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

Commit

Permalink
Update parent QuickActions with current child selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ottosichert committed Dec 21, 2017
1 parent d30b45a commit 0bb7fbd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/components/app/DocumentList.js
Expand Up @@ -267,9 +267,9 @@ class DocumentList extends Component {
});
};

updateQuickActions = () => {
updateQuickActions = childSelection => {
if (this.quickActionsComponent) {
this.quickActionsComponent.updateActions();
this.quickActionsComponent.updateActions(childSelection);
}
};

Expand Down
10 changes: 8 additions & 2 deletions src/components/app/QuickActions.js
Expand Up @@ -77,9 +77,15 @@ class QuickActions extends Component {
return nextProps.shouldNotUpdate !== true;
}

updateActions = () => {
updateActions = (childSelection = this.props.childView.viewSelectedIds) => {
const { windowType, viewId, selected, childView, parentView } = this.props;
this.fetchActions(windowType, viewId, selected, childView, parentView);
this.fetchActions(
windowType,
viewId,
selected,
{ ...childView, viewSelectedIds: childSelection },
parentView
);
};

componentDidUpdate = prevProps => {
Expand Down
74 changes: 40 additions & 34 deletions src/components/table/Table.js
Expand Up @@ -295,37 +295,37 @@ class Table extends Component {

selectProduct = (id, idFocused, idFocusedDown) => {
const { dispatch, type, disconnectFromState, tabInfo, viewId } = this.props;
const { selected } = this.state;

this.setState(
prevState => ({
selected: prevState.selected.concat([id])
}),
() => {
const { selected } = this.state;
const newSelected = selected.concat([id]);

if (tabInfo) {
dispatch(
selectTableItems({
windowType: type,
viewId,
ids: selected
})
);
}
this.setState({ selected: newSelected }, () => {
const { selected } = this.state;

if (!disconnectFromState) {
dispatch(
selectTableItems({
windowType: type,
viewId,
ids: selected
})
);
}
if (tabInfo) {
dispatch(
selectTableItems({
windowType: type,
viewId,
ids: selected
})
);
}

this.triggerFocus(idFocused, idFocusedDown);
if (!disconnectFromState) {
dispatch(
selectTableItems({
windowType: type,
viewId,
ids: selected
})
);
}
);

this.triggerFocus(idFocused, idFocusedDown);
});

return newSelected;
};

selectRangeProduct = ids => {
Expand Down Expand Up @@ -613,28 +613,34 @@ class Table extends Component {
const isSelected = selected.indexOf(id) > -1;
const isAnySelected = selected.length > 0;

if (onSelectionChanged) {
onSelectionChanged();
}
let newSelection;

if (selectMore) {
if (isSelected) {
const newSelected = this.deselectProduct(id);
return newSelected.length > 0;
newSelection = this.deselectProduct(id);
} else {
this.selectProduct(id);
newSelection = this.selectProduct(id);
}
} else if (selectRange) {
if (isAnySelected) {
const idsToSelect = this.getProductRange(id);
this.selectRangeProduct(idsToSelect);
newSelection = this.getProductRange(id);
this.selectRangeProduct(newSelection);
} else {
newSelection = [id];
this.selectOneProduct(id);
}
} else {
newSelection = [id];
this.selectOneProduct(id);
}

if (onSelectionChanged) {
onSelectionChanged(newSelection);
}

return newSelection.length > 0;
}

return true;
};

Expand Down
4 changes: 2 additions & 2 deletions src/containers/DocList.js
Expand Up @@ -84,8 +84,8 @@ class DocList extends Component {
this.setState({ notfound: isNotFound });
};

handleUpdateParentSelectedIds = () => {
this.masterDocumentList.updateQuickActions();
handleUpdateParentSelectedIds = childSelection => {
this.masterDocumentList.updateQuickActions(childSelection);
};

render() {
Expand Down

1 comment on commit 0bb7fbd

@ottosichert
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #1465

Please sign in to comment.