Skip to content

Commit

Permalink
Cleanup selections logic (#2695)
Browse files Browse the repository at this point in the history
* #2693 fix selections

* #2693 create a quickactions selector

* #2693 cleanup

* #2693 simplify and fix fetching quickactions

* #2693 remove some unused code for quickactions
  • Loading branch information
siemiatj committed Apr 24, 2020
1 parent 101950a commit 391b2bc
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 110 deletions.
32 changes: 15 additions & 17 deletions src/api/view.js
Expand Up @@ -205,48 +205,46 @@ export async function quickActionsRequest(
parentView
) {
const requests = [];

const query = getQueryString({
viewProfileId,
selectedIds,
childViewId: childView.viewId,
childViewSelectedIds: childView.viewSelectedIds,
parentViewId: parentView.viewId,
parentViewSelectedIds: parentView.viewSelectedIds,
});

const mainRequest = get(`
${config.API_URL}/documentView/${windowId}/${viewId}/quickActions${
query ? `?${query}` : ''
}`);

requests.push(mainRequest);

if (parentView.viewId) {
const parentQuery = getQueryString({
viewProfileId,
selectedIds: parentView.viewSelectedIds,
childViewId: viewId,
childViewSelectedIds: selectedIds,
});

const r1 = get(`
const childRequest = get(`
${config.API_URL}/documentView/${parentView.windowType}/${
parentView.viewId
}/quickActions${parentQuery ? `?${parentQuery}` : ''}`);
requests.push(r1);
} else if (childView.viewId) {
requests.push(childRequest);
}

if (childView.viewId) {
const childQuery = getQueryString({
viewProfileId,
selectedIds: childView.selectedIds,
parentViewId: viewId,
parentViewSelectedIds: selectedIds,
});

const r2 = get(`
const parentRequest = get(`
${config.API_URL}/documentView/${childView.windowType}/${
childView.viewId
}/quickActions${childQuery ? `?${childQuery}` : ''}`);
requests.push(r2);
requests.push(parentRequest);
}

const r3 = get(`
${config.API_URL}/documentView/${windowId}/${viewId}/quickActions${
query ? `?${query}` : ''
}`);
requests.push(r3);

return await Promise.all(requests);
}
18 changes: 1 addition & 17 deletions src/components/app/DocumentList/DocumentList.js
Expand Up @@ -62,27 +62,12 @@ export default class DocumentList extends Component {
onToggleState(GEO_PANEL_STATES[newStateIdx]);
};

/**
* @method updateQuickActions
* @summary ToDo: Describe the method.
*/
updateQuickActions = (childSelection) => {
if (this.quickActionsComponent) {
this.quickActionsComponent.updateActions(childSelection);
}
};

/**
* @method setTableRowEdited
* @summary ToDo: Describe the method.
*/
setTableRowEdited = (val) => {
this.setState(
{
rowEdited: val,
},
() => this.updateQuickActions()
);
this.setState({ rowEdited: val });
};

/**
Expand Down Expand Up @@ -344,7 +329,6 @@ export default class DocumentList extends Component {
readonly={true}
supportOpenRecord={layout.supportOpenRecord}
onRowEdited={this.setTableRowEdited}
updateQuickActions={this.updateQuickActions}
keyProperty="id"
onDoubleClick={onRedirectToDocument}
handleChangePage={onChangePage}
Expand Down
17 changes: 2 additions & 15 deletions src/components/app/DocumentList/index.js
Expand Up @@ -216,9 +216,6 @@ class DocumentListContainer extends Component {
if (filtersActive.size) {
this.filterCurrentView();
}

// force updating actions
this.updateQuickActions();
}

updateViewData(windowType, rows);
Expand All @@ -239,21 +236,10 @@ class DocumentListContainer extends Component {
});

this.browseView();
this.updateQuickActions();
}
});
};

/**
* @method updateQuickActions
* @summary Trigger the QuickActions component to fetch quick actions for the new selection
*/
updateQuickActions = (childSelection) => {
if (this.quickActionsComponent) {
this.quickActionsComponent.updateActions(childSelection);
}
};

/**
* @method loadSupportAttributeFlag
* @summary Load supportAttribute of the selected row from the table.
Expand Down Expand Up @@ -470,6 +456,7 @@ class DocumentListContainer extends Component {
updateUri,
type,
isIncluded,
includedView,
fetchDocument,
indicatorState,
selectTableItems,
Expand Down Expand Up @@ -507,7 +494,7 @@ class DocumentListContainer extends Component {
const resultById = {};
const selection = getSelectionDirect(selections, windowType, viewId);
const forceSelection =
(type === 'includedView' || isIncluded) &&
(type === 'includedView' || isIncluded || includedView) &&
response &&
result.length > 0 &&
(selection.length === 0 ||
Expand Down
35 changes: 14 additions & 21 deletions src/components/app/QuickActions.js
Expand Up @@ -6,6 +6,7 @@ import Queue from 'simple-promise-queue';
import cx from 'classnames';

import { quickActionsRequest } from '../../api';
import { getQuickactions } from '../../reducers/windowHandler';
import {
openModal,
fetchedQuickActions,
Expand Down Expand Up @@ -241,22 +242,19 @@ export class QuickActions extends Component {
parentView
)
.then((result) => {
const [respRel, resp] = result;
const [resp, respRel] = result;

if (this.mounted) {
const currentActions =
resp && resp.data ? resp.data.actions : respRel.data.actions;
const currentActions = resp && resp.data ? resp.data.actions : [];
const relatedActions =
resp && resp.data ? respRel.data.actions : null;

if ((parentView.viewId || childView.viewId) && relatedActions) {
const windowType = parentView.windowType
? parentView.windowType
: childView.windowType;
const id = parentView.viewId
? parentView.viewId
: childView.viewId;
fetchedQuickActions(windowType, id, relatedActions);
respRel && respRel.data ? respRel.data.actions : [];

if (childView.viewId && relatedActions) {
fetchedQuickActions(
childView.windowType,
childView.viewId,
relatedActions
);
}

fetchedQuickActions(windowId, viewId, currentActions);
Expand Down Expand Up @@ -460,14 +458,9 @@ QuickActions.propTypes = {
onInvalidViewId: PropTypes.func,
};

const mapStateToProps = (state, ownProps) => {
const { viewId, windowType } = ownProps;
const key = `${windowType}${viewId ? `-${viewId}` : ''}`;

return {
actions: state.windowHandler.quickActions[key] || [],
};
};
const mapStateToProps = (state, { viewId, windowType }) => ({
actions: getQuickactions(state, { viewId, windowType }),
});

export default connect(
mapStateToProps,
Expand Down

0 comments on commit 391b2bc

Please sign in to comment.