diff --git a/src/actions/WindowActions.js b/src/actions/WindowActions.js index 88da7b8d3..da3df9e39 100644 --- a/src/actions/WindowActions.js +++ b/src/actions/WindowActions.js @@ -599,32 +599,35 @@ export function createProcess(processType, viewId, type, ids, tabId, rowId) { return getProcessData( processType, viewId, type, ids, tabId, rowId - ).then(response => { - const preparedData = parseToDisplay(response.data.fieldsByName); - - pid = response.data.pinstanceId; - - if (Object.keys(preparedData).length === 0) { - startProcess(processType, pid).then(response => { - dispatch(setProcessSaved()); - dispatch(handleProcessResponse(response, processType, pid)); - }).catch(err => { - dispatch(setProcessSaved()); - throw err; - }); - throw new Error('close_modal'); - }else{ - dispatch(initDataSuccess(preparedData, 'modal')); - initLayout('process', processType).then(response => { - const preparedLayout = Object.assign({}, response.data, { - pinstanceId: pid - }) - dispatch(setProcessSaved()); - return dispatch(initLayoutSuccess(preparedLayout, 'modal')) - }).catch(err => { - dispatch(setProcessSaved()); - throw err; - }); + ).then( (response) => { + if (response.data) { + const preparedData = parseToDisplay(response.data.fieldsByName); + + pid = response.data.pinstanceId; + + if (Object.keys(preparedData).length === 0) { + startProcess(processType, pid).then(response => { + dispatch(handleProcessResponse(response, processType, pid)); + }).catch(err => { + dispatch(setProcessSaved()); + throw err; + }); + } + else { + dispatch(initDataSuccess(preparedData, 'modal')); + initLayout('process', processType).then(response => { + dispatch(setProcessSaved()); + + const preparedLayout = Object.assign({}, response.data, { + pinstanceId: pid + }); + + return dispatch(initLayoutSuccess(preparedLayout, 'modal')) + }).catch(err => { + dispatch(setProcessSaved()); + throw err; + }); + } } }).catch(err => { dispatch(setProcessSaved()); @@ -641,7 +644,9 @@ export function handleProcessResponse(response, type, id, successCallback) { if(error){ dispatch(addNotification('Process error', summary, 5000, 'error')); - }else{ + dispatch(setProcessSaved()); + } + else { if(action){ switch(action.type){ case 'openView': @@ -688,6 +693,8 @@ export function handleProcessResponse(response, type, id, successCallback) { dispatch(addNotification('Process', summary, 5000, 'primary')) } + dispatch(setProcessSaved()); + successCallback && successCallback(); } } diff --git a/src/components/Container.js b/src/components/Container.js index fe58c4ad2..0ea4f0120 100644 --- a/src/components/Container.js +++ b/src/components/Container.js @@ -112,19 +112,21 @@ class Container extends Component { inModal={modal.visible} > - {includedView.windowType && - includedView.viewId && + {includedView.windowType && includedView.viewId && ( - } + )} } diff --git a/src/components/app/DocumentList.js b/src/components/app/DocumentList.js index 51b77984e..b6a17689c 100644 --- a/src/components/app/DocumentList.js +++ b/src/components/app/DocumentList.js @@ -65,6 +65,7 @@ class DocumentList extends Component { isShowIncluded: false, hasShowIncluded: false } + this.fetchLayoutAndData(); } @@ -186,7 +187,9 @@ class DocumentList extends Component { this.setState({ cachedSelection: null }, () => { - dispatch(setListIncludedView()); + if (includedView.windowType === 'pickingSlot') { + dispatch(setListIncludedView()); + } }) } } @@ -216,8 +219,13 @@ class DocumentList extends Component { }) }); } + if(fullyChanged == true){ this.browseView(true); + + if (this.quickActionsComponent) { + this.quickActionsComponent.updateActions(); + } } }); } @@ -370,7 +378,7 @@ class DocumentList extends Component { setNotFound && setNotFound(false); dispatch(indicatorState('pending')); - if(updateUri){ + if (updateUri) { id && updateUri('viewId', id); page && updateUri('page', page); sortingQuery && updateUri('sort', sortingQuery); @@ -378,17 +386,31 @@ class DocumentList extends Component { return browseViewRequest( id, page, this.pageLength, sortingQuery, windowType - ).then(response => { - dispatch(indicatorState('saved')); + ).then( (response) => { + let selectionState = {}; + let forceSelection = false; + if ( + ((this.props.type === 'includedView') || this.props.isIncluded) && + response.data && response.data.result && (response.data.result.length > 0) + ) { + selectionState.cachedSelection = null; + forceSelection = true; + } - this.mounted && this.setState(Object.assign({}, { - data: response.data, - filters: response.data.filters - }, refresh && { - refresh: Date.now() - }), () => { - this.connectWS(response.data.viewId); - }) + this.mounted && this.setState( + Object.assign({}, { + data: response.data, + filters: response.data.filters + }, selectionState), + () => { + if (forceSelection) { + dispatch(selectTableItems([ response.data.result[0].id ], windowType)) + } + this.connectWS(response.data.viewId); + } + ); + + dispatch(indicatorState('saved')); }); } @@ -539,9 +561,15 @@ class DocumentList extends Component { />} this.quickActionsComponent = (c && c.getWrappedInstance()) } + selected={selected} + viewId={viewId} + windowType={windowType} fetchOnInit={fetchQuickActionsOnInit} disabled={hasIncluded} shouldNotUpdate={inBackground && !hasIncluded} diff --git a/src/components/app/QuickActions.js b/src/components/app/QuickActions.js index f29dd516d..cd4d715de 100644 --- a/src/components/app/QuickActions.js +++ b/src/components/app/QuickActions.js @@ -34,8 +34,8 @@ class QuickActions extends Component { const {fetchOnInit} = this.props; - if(fetchOnInit){ - this.fetchActions(); + if (fetchOnInit) { + this.fetchActions(props.windowType, props.viewId, props.selected); } } @@ -47,10 +47,36 @@ class QuickActions extends Component { this.mounted = false; } + componentWillReceiveProps = (nextProps) => { + const { + selected, viewId, windowType + } = this.props; + + if (nextProps.selectedWindowType && (nextProps.selectedWindowType !== nextProps.windowType)) { + return; + } + + if ( + (nextProps.selected && (JSON.stringify(nextProps.selected) !== JSON.stringify(selected))) || + (nextProps.viewId && (nextProps.viewId !== viewId)) || + (nextProps.windowType && (nextProps.windowType !== windowType)) + ) { + this.fetchActions(nextProps.windowType, nextProps.viewId, nextProps.selected); + } + } + + shouldComponentUpdate(nextProps) { + return (nextProps.shouldNotUpdate !== true); + } + + updateActions = () => { + const { windowType, viewId, selected } = this.props; + this.fetchActions(windowType, viewId, selected); + } + componentDidUpdate = (prevProps) => { const { - selected, refresh, shouldNotUpdate, viewId, selectedWindowType, - windowType, inBackground, inModal + inBackground, inModal } = this.props; if (inModal === false && (prevProps.inModal === true)) { @@ -66,22 +92,6 @@ class QuickActions extends Component { loading: false }); } - - if(shouldNotUpdate){ - return; - } - - if(selectedWindowType && (selectedWindowType !== windowType)){ - return; - } - - if( - (JSON.stringify(prevProps.selected) !== JSON.stringify(selected)) || - (JSON.stringify(prevProps.refresh) !== JSON.stringify(refresh)) || - (JSON.stringify(prevProps.viewId) !== JSON.stringify(viewId)) - ){ - this.fetchActions(); - } } getChildContext = () => { @@ -113,25 +123,32 @@ class QuickActions extends Component { this.toggleDropdown(); } - fetchActions = () => { - const {windowType, viewId, selected} = this.props; - - this.mounted && this.setState({ + fetchActions = (windowType, viewId, selected) => { +/* + this.setState({ loading: true }); - - quickActionsRequest(windowType, viewId, selected) - .then(response => { - this.mounted && this.setState({ - actions: response.data.actions, - loading: false - }) - }) - .catch(() => { - this.mounted && this.setState({ - loading: false +*/ + + if (windowType && viewId && selected) { + quickActionsRequest(windowType, viewId, selected) + .then(response => { + this.setState({ + actions: response.data.actions, + loading: false + }) }) + .catch(() => { + this.setState({ + loading: false + }) + }); + } + else { + this.setState({ + loading: false }); + } } toggleDropdown = (option) => { @@ -250,6 +267,6 @@ QuickActions.propTypes = { dispatch: PropTypes.func.isRequired }; -QuickActions = connect()(QuickActions) +QuickActions = connect(false, false, false, { withRef: true })(QuickActions) export default QuickActions;