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

Commit

Permalink
Fixes incorrect behavior for includedViews and quickActions #992 #1046
Browse files Browse the repository at this point in the history
  • Loading branch information
wiadev committed Jul 26, 2017
1 parent fb1605c commit a3bea18
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 81 deletions.
61 changes: 34 additions & 27 deletions src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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':
Expand Down Expand Up @@ -688,6 +693,8 @@ export function handleProcessResponse(response, type, id, successCallback) {
dispatch(addNotification('Process', summary, 5000, 'primary'))
}

dispatch(setProcessSaved());

successCallback && successCallback();
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,21 @@ class Container extends Component {
inModal={modal.visible}
>
</DocumentList>
{includedView.windowType &&
includedView.viewId &&
{includedView.windowType && includedView.viewId && (
<DocumentList
type="includedView"
selected={selected}
selectedWindowType={selectedWindowType}
windowType={includedView.windowType}
defaultViewId={includedView.viewId}
fetchQuickActionsOnInit={true}
isModal={true}
isIncluded={true}
processStatus={processStatus}
inBackground={false}
inModal={modal.visible}
/>
}
)}
</div>
</RawModal>
}
Expand Down
58 changes: 43 additions & 15 deletions src/components/app/DocumentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class DocumentList extends Component {
isShowIncluded: false,
hasShowIncluded: false
}

this.fetchLayoutAndData();
}

Expand Down Expand Up @@ -186,7 +187,9 @@ class DocumentList extends Component {
this.setState({
cachedSelection: null
}, () => {
dispatch(setListIncludedView());
if (includedView.windowType === 'pickingSlot') {
dispatch(setListIncludedView());
}
})
}
}
Expand Down Expand Up @@ -216,8 +219,13 @@ class DocumentList extends Component {
})
});
}

if(fullyChanged == true){
this.browseView(true);

if (this.quickActionsComponent) {
this.quickActionsComponent.updateActions();
}
}
});
}
Expand Down Expand Up @@ -370,25 +378,39 @@ 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);
}

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'));
});
}

Expand Down Expand Up @@ -539,9 +561,15 @@ class DocumentList extends Component {
/>}
</div>
<QuickActions
{...{windowType, selectedWindowType, viewId,
refresh, processStatus}}
selected={selectionValid ? selected : undefined}
{...{
selectedWindowType,
refresh,
processStatus
}}
ref={ (c) => this.quickActionsComponent = (c && c.getWrappedInstance()) }
selected={selected}
viewId={viewId}
windowType={windowType}
fetchOnInit={fetchQuickActionsOnInit}
disabled={hasIncluded}
shouldNotUpdate={inBackground && !hasIncluded}
Expand Down
89 changes: 53 additions & 36 deletions src/components/app/QuickActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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)) {
Expand All @@ -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 = () => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -250,6 +267,6 @@ QuickActions.propTypes = {
dispatch: PropTypes.func.isRequired
};

QuickActions = connect()(QuickActions)
QuickActions = connect(false, false, false, { withRef: true })(QuickActions)

export default QuickActions;

0 comments on commit a3bea18

Please sign in to comment.