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

Fixes incorrect behaviour for included views and quickActions #992 #1046 #1069

Merged
merged 1 commit into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
52 changes: 37 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 @@ -370,25 +373,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 +556,14 @@ class DocumentList extends Component {
/>}
</div>
<QuickActions
{...{windowType, selectedWindowType, viewId,
refresh, processStatus}}
selected={selectionValid ? selected : undefined}
{...{
selectedWindowType,
refresh,
processStatus
}}
selected={selected}
viewId={viewId}
windowType={windowType}
fetchOnInit={fetchQuickActionsOnInit}
disabled={hasIncluded}
shouldNotUpdate={inBackground && !hasIncluded}
Expand Down
82 changes: 47 additions & 35 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,31 @@ 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 {
selected, refresh, shouldNotUpdate, viewId, selectedWindowType,
windowType, inBackground, inModal
inBackground, inModal
} = this.props;

if (inModal === false && (prevProps.inModal === true)) {
Expand All @@ -66,22 +87,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 +118,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