Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1256 from metasfresh/dev-1239
Browse files Browse the repository at this point in the history
Close includedView when navigating with opened includedView
  • Loading branch information
teosarca authored Oct 12, 2017
2 parents 253ef3d + f4633d3 commit 68d43d5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 46 deletions.
14 changes: 7 additions & 7 deletions src/actions/ListActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ export function setPagination(page, windowType){
}
}

export function setListIncludedView(windowType, viewId) {
export function setListIncludedView({ windowType, viewId } = {}) {
return {
type: types.SET_LIST_INCLUDED_VIEW,
windowType,
viewId
}
payload: { windowType, viewId },
};
}

export function closeListIncludedView(windowType, viewId) {
export function closeListIncludedView({
windowType, viewId, forceClose = false,
} = {}) {
return {
type: types.CLOSE_LIST_INCLUDED_VIEW,
windowType,
viewId,
payload: { windowType, viewId, forceClose },
};
}
15 changes: 10 additions & 5 deletions src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
} from './AppActions';

import {
setListIncludedView
closeListIncludedView,
setListIncludedView,
} from './ListActions';

export function setLatestNewDocument(id) {
Expand Down Expand Up @@ -764,12 +765,16 @@ export function handleProcessResponse(response, type, id, successCallback) {
}
break;
case 'openIncludedView':
dispatch(setListIncludedView(
action.windowId, action.viewId
));
dispatch(setListIncludedView({
windowType: action.windowId,
viewId: action.viewId,
}));
break;
case 'closeIncludedView':
dispatch(setListIncludedView());
dispatch(closeListIncludedView({
windowType: action.windowId,
viewId: action.viewId,
}));
break;
case 'selectViewRows':
dispatch(selectTableItems(
Expand Down
19 changes: 7 additions & 12 deletions src/components/app/DocumentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class DocumentList extends Component {
(layout && layout.supportIncludedView) &&
!_.isEqual(this.props.selected, selected)
) {
dispatch(setListIncludedView());
dispatch(closeListIncludedView({ windowType, viewId }));
}
}

Expand Down Expand Up @@ -499,29 +499,24 @@ class DocumentList extends Component {
}
}

showIncludedViewOnSelect = (showIncludedView, data) => {
showIncludedViewOnSelect = ({
showIncludedView, windowType, viewId, forceClose,
} = {}) => {
const { dispatch } = this.props;

this.setState({
isShowIncluded: !!showIncludedView,
hasShowIncluded: !!showIncludedView,
}, () => {
if (showIncludedView) {
dispatch(setListIncludedView(
// some events pass windowId, some pass windowType
data.windowId || data.windowType,
data.viewId,
));
dispatch(setListIncludedView({ windowType, viewId }));
}
});

// can't use setState callback because component might be unmounted and
// callback is never called
if (!showIncludedView && data) {
dispatch(closeListIncludedView(
data.windowId || data.windowType,
data.viewId,
));
if (!showIncludedView) {
dispatch(closeListIncludedView({ windowType, viewId, forceClose }));
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/app/RawModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ class RawModal extends Component {

dispatch(closeRawModal());
dispatch(closeModal());
dispatch(closeListIncludedView(windowType, viewId));
dispatch(closeListIncludedView({
windowType,
viewId,
forceClose: true,
}));

if (!modalVisible){
document.body.style.overflow = 'auto';
Expand Down
39 changes: 27 additions & 12 deletions src/components/table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ class Table extends Component {
});

this.deselectAllProducts();
showIncludedViewOnSelect && showIncludedViewOnSelect(false, {
showIncludedViewOnSelect && showIncludedViewOnSelect({
showIncludedView: false,
windowType: prevProps.windowType,
viewId: prevProps.viewid,
forceClose: true,
});
}
}
Expand All @@ -142,7 +144,11 @@ class Table extends Component {

this.deselectAllProducts();
if (showIncludedViewOnSelect) {
showIncludedViewOnSelect(false, { windowType, viewId });
showIncludedViewOnSelect({
showIncludedView: false,
windowType,
viewId,
});
}
}

Expand All @@ -153,10 +159,12 @@ class Table extends Component {
if (selected.length === 1) {
rows.forEach((item) => {
if (item.id === selected[0]) {
showIncludedViewOnSelect(
item.supportIncludedViews,
item.includedView,
);
showIncludedViewOnSelect({
showIncludedView: item.supportIncludedViews,
windowType: item.includedView.windowType ||
item.includedView.windowId,
viewId: item.includedView.viewId,
});
}
});
}
Expand Down Expand Up @@ -376,7 +384,11 @@ class Table extends Component {

this.deselectAllProducts();
if (showIncludedViewOnSelect) {
showIncludedViewOnSelect(false, { windowType, viewId });
showIncludedViewOnSelect({
showIncludedView: false,
windowType,
viewId,
});
}
}
}
Expand Down Expand Up @@ -882,11 +894,14 @@ class Table extends Component {
}
onMouseDown={(e) => {
this.handleClick(e, item[keyProperty]);
supportIncludedViewOnSelect &&
showIncludedViewOnSelect(
item.supportIncludedViews,
item.includedView
)
if (supportIncludedViewOnSelect) {
showIncludedViewOnSelect({
showIncludedView: item.supportIncludedViews,
windowType: item.includedView.windowType ||
item.includedView.windowId,
viewId: item.includedView.viewId,
});
}
}}
handleRightClick={(e, fieldName, supportZoomInto,
supportFieldEdit) =>
Expand Down
29 changes: 20 additions & 9 deletions src/reducers/listHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,39 @@ export default function listHandler(state = initialState, action) {
})
});

case types.SET_LIST_INCLUDED_VIEW:
case types.SET_LIST_INCLUDED_VIEW: {
const { windowType, viewId } = action.payload;

return Object.assign({}, state, {
includedView: Object.assign({}, state.includedView, {
viewId: action.viewId,
windowType: action.windowType
})
viewId,
windowType,
}),
});
}

case types.CLOSE_LIST_INCLUDED_VIEW: {
const { windowType, viewId } = state.includedView;
const {
windowType: newWindowType,
viewId: newViewId,
forceClose,
} = action.payload;

case types.CLOSE_LIST_INCLUDED_VIEW:
if ((state.includedView.windowType === action.windowType) &&
(state.includedView.viewId === action.viewId)
) {
if (forceClose || (
windowType === newWindowType && viewId === newViewId
)) {
// only close includedView if it hasn't changed since
return Object.assign({}, state, {
includedView: Object.assign({}, state.includedView, {
viewId: '',
windowType: null
})
}),
});
} else {
return state;
}
}

default:
return state;
Expand Down

0 comments on commit 68d43d5

Please sign in to comment.