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 #1083 from metasfresh/revert-1069-dev-1046-fix
Browse files Browse the repository at this point in the history
Revert "Fixes incorrect behaviour for included views and quickActions #992 #1046"
  • Loading branch information
metas-mk authored Jul 26, 2017
2 parents b05b361 + 6fde744 commit f665102
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 89 deletions.
8 changes: 3 additions & 5 deletions src/components/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,19 @@ 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
52 changes: 15 additions & 37 deletions src/components/app/DocumentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class DocumentList extends Component {
isShowIncluded: false,
hasShowIncluded: false
}

this.fetchLayoutAndData();
}

Expand Down Expand Up @@ -187,9 +186,7 @@ class DocumentList extends Component {
this.setState({
cachedSelection: null
}, () => {
if (includedView.windowType === 'pickingSlot') {
dispatch(setListIncludedView());
}
dispatch(setListIncludedView());
})
}
}
Expand Down Expand Up @@ -373,39 +370,25 @@ 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) => {
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
}, selectionState),
() => {
if (forceSelection) {
dispatch(selectTableItems([ response.data.result[0].id ], windowType))
}
this.connectWS(response.data.viewId);
}
);

).then(response => {
dispatch(indicatorState('saved'));

this.mounted && this.setState(Object.assign({}, {
data: response.data,
filters: response.data.filters
}, refresh && {
refresh: Date.now()
}), () => {
this.connectWS(response.data.viewId);
})
});
}

Expand Down Expand Up @@ -556,14 +539,9 @@ class DocumentList extends Component {
/>}
</div>
<QuickActions
{...{
selectedWindowType,
refresh,
processStatus
}}
selected={selected}
viewId={viewId}
windowType={windowType}
{...{windowType, selectedWindowType, viewId,
refresh, processStatus}}
selected={selectionValid ? selected : undefined}
fetchOnInit={fetchQuickActionsOnInit}
disabled={hasIncluded}
shouldNotUpdate={inBackground && !hasIncluded}
Expand Down
82 changes: 35 additions & 47 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(props.windowType, props.viewId, props.selected);
if(fetchOnInit){
this.fetchActions();
}
}

Expand All @@ -47,31 +47,10 @@ 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);
}

componentDidUpdate = (prevProps) => {
const {
inBackground, inModal
selected, refresh, shouldNotUpdate, viewId, selectedWindowType,
windowType, inBackground, inModal
} = this.props;

if (inModal === false && (prevProps.inModal === true)) {
Expand All @@ -87,6 +66,22 @@ 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 @@ -118,32 +113,25 @@ class QuickActions extends Component {
this.toggleDropdown();
}

fetchActions = (windowType, viewId, selected) => {
/*
this.setState({
fetchActions = () => {
const {windowType, viewId, selected} = this.props;

this.mounted && this.setState({
loading: true
});
*/

if (windowType && viewId && selected) {
quickActionsRequest(windowType, viewId, selected)
.then(response => {
this.setState({
actions: response.data.actions,
loading: false
})

quickActionsRequest(windowType, viewId, selected)
.then(response => {
this.mounted && this.setState({
actions: response.data.actions,
loading: false
})
})
.catch(() => {
this.mounted && this.setState({
loading: false
})
.catch(() => {
this.setState({
loading: false
})
});
}
else {
this.setState({
loading: false
});
}
}

toggleDropdown = (option) => {
Expand Down

0 comments on commit f665102

Please sign in to comment.