Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-4994 ENG-4995 enable user to perform actions in search mode #1508

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/state/pages/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ export const sendDeletePage = (page, successRedirect = true) => async (dispatch)
const response = await deletePage(page);
const json = await response.json();
if (response) {
dispatch(addToast({
id: 'app.deleted',
values: {
type: 'page',
code: page.code,
},
}, TOAST_SUCCESS));
dispatch(removePage(page));
if (page.tourProgress === APP_TOUR_CANCELLED) return;
if ((page.tourProgress !== APP_TOUR_STARTED && successRedirect) || page.redirectToPageTree) {
Expand Down
2 changes: 1 addition & 1 deletion src/state/pages/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const childrenMap = (state = {}, action = {}) => {
case REMOVE_PAGE: {
const { parentCode, code } = action.payload.page;
const newState = { ...state };
if (parentCode) {
if (parentCode && newState[parentCode]) {
newState[parentCode] = newState[parentCode].filter(f => f !== code);
}
delete newState[code];
Expand Down
6 changes: 3 additions & 3 deletions src/state/pages/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export const getDashboardPages = state => state.pages.dashboard;
export const getIsVirtualRootOn = state => state.pages.virtualRoot;

export const getSearchPages = createSelector(
[getSearchPagesRaw, getChildrenMap],
(pages, pageChildren) => {
[getSearchPagesRaw],
(pages) => {
if (!pages) return pages;
return pages.map(page => ({
...page,
isEmpty: pageChildren[page.code] && page.children.length === 0,
isEmpty: page.children.length === 0,
}));
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/common/DeletePageModalContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getPagesMap } from 'state/pages/selectors';

export const mapStateToProps = state => ({
info: getInfo(state),
page: getPagesMap(state)[getInfo(state).code],
page: getInfo(state).page || getPagesMap(state)[getInfo(state).code],
});

export const mapDispatchToProps = dispatch => ({
Expand Down
6 changes: 3 additions & 3 deletions src/ui/pages/common/PageTreeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ export const mapDispatchToProps = (dispatch, ownProps) => ({
},
onClickDelete: (page) => {
dispatch(setVisibleModal(MODAL_ID));
dispatch(setInfo({ type: 'page', code: page.code }));
dispatch(setInfo({ type: 'page', code: page.code, page }));
},
onClickPublish: (page) => {
dispatch(setVisibleModal(PUBLISH_MODAL_ID));
dispatch(setInfo({ type: 'page', code: page.code }));
dispatch(setInfo({ type: 'page', code: page.code, page }));
},
onClickUnPublish: (page) => {
dispatch(setVisibleModal(UNPUBLISH_MODAL_ID));
dispatch(setInfo({ type: 'page', code: page.code }));
dispatch(setInfo({ type: 'page', code: page.code, page }));
},
onClickDetails: (page) => {
dispatch(setSelectedPage(page));
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/common/PublishPageModalContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getPagesMap } from 'state/pages/selectors';

export const mapStateToProps = state => ({
info: getInfo(state),
page: getPagesMap(state)[getInfo(state).code],
page: getInfo(state).page || getPagesMap(state)[getInfo(state).code],
});

export const mapDispatchToProps = dispatch => ({
Expand Down
2 changes: 1 addition & 1 deletion src/ui/pages/common/UnpublishPageModalContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getPagesMap } from 'state/pages/selectors';

export const mapStateToProps = state => ({
info: getInfo(state),
page: getPagesMap(state)[getInfo(state).code],
page: getInfo(state).page || getPagesMap(state)[getInfo(state).code],
});

export const mapDispatchToProps = dispatch => ({
Expand Down
4 changes: 4 additions & 0 deletions src/ui/pages/list/PageListSearchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Paginator, Spinner, Alert } from 'patternfly-react';
import { FormattedMessage, injectIntl, intlShape } from 'react-intl';
import { DataTable } from '@entando/datatable';
import DeletePageModalContainer from 'ui/pages/common/DeletePageModalContainer';
import PublishPageModalContainer from 'ui/pages/common/PublishPageModalContainer';
import UnpublishPageModalContainer from 'ui/pages/common/UnpublishPageModalContainer';
import paginatorMessages from 'ui/paginatorMessages';

class PageListSearchTable extends Component {
Expand Down Expand Up @@ -125,6 +127,8 @@ class PageListSearchTable extends Component {
{this.renderTable()}
</Spinner>
<DeletePageModalContainer />
<PublishPageModalContainer />
<UnpublishPageModalContainer />
</div>
);
}
Expand Down
5 changes: 3 additions & 2 deletions test/state/pages/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,9 @@ describe('state/pages/actions', () => {
store.dispatch(sendDeletePage(DASHBOARD_PAYLOAD)).then(() => {
expect(deletePage).toHaveBeenCalled();
const actions = store.getActions();
expect(actions).toHaveLength(1);
expect(actions[0]).toHaveProperty('type', REMOVE_PAGE);
expect(actions).toHaveLength(2);
expect(actions[0]).toHaveProperty('type', ADD_TOAST);
expect(actions[1]).toHaveProperty('type', REMOVE_PAGE);
expect(history.push).toHaveBeenCalledWith(ROUTE_PAGE_TREE);
done();
}).catch(done.fail);
Expand Down
6 changes: 3 additions & 3 deletions test/ui/pages/common/PageTreeContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('PageTreeContainer', () => {
it('should dispatch an action if onClickDelete is called', () => {
props.onClickDelete({ code: 'pagecode' });
expect(setVisibleModal).toHaveBeenCalledWith(MODAL_ID);
expect(setInfo).toHaveBeenCalledWith({ type: 'page', code: 'pagecode' });
expect(setInfo).toHaveBeenCalledWith({ type: 'page', code: 'pagecode', page: { code: 'pagecode' } });
});

it('should dispatch an action if onClickClone is called', () => {
Expand All @@ -130,13 +130,13 @@ describe('PageTreeContainer', () => {
it('should dispatch an action if onClickPublish is called', () => {
props.onClickPublish({ code: 'pagecode', status: 'publish' });
expect(setVisibleModal).toHaveBeenCalledWith(PUBLISH_MODAL_ID);
expect(setInfo).toHaveBeenCalledWith({ type: 'page', code: 'pagecode' });
expect(setInfo).toHaveBeenCalledWith({ type: 'page', code: 'pagecode', page: { code: 'pagecode', status: 'publish' } });
});

it('should dispatch an action if onClickUnPublish is called', () => {
props.onClickUnPublish({ code: 'pagecode', status: 'unpublish' });
expect(setVisibleModal).toHaveBeenCalledWith(UNPUBLISH_MODAL_ID);
expect(setInfo).toHaveBeenCalledWith({ type: 'page', code: 'pagecode' });
expect(setInfo).toHaveBeenCalledWith({ type: 'page', code: 'pagecode', page: { code: 'pagecode', status: 'unpublish' } });
});

it('should dispatch an action if "onClickDetails" is called', () => {
Expand Down