From: Lucas Di Pentima Date: Tue, 31 May 2022 12:19:10 +0000 (-0300) Subject: 18787: Avoids re-rendering by only dispatching SET_COLLECTIONS when needed. X-Git-Tag: 2.5.0~54^2~1 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/05010c44073b52c0e414d180cfc21bae215c4d33 18787: Avoids re-rendering by only dispatching SET_COLLECTIONS when needed. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/store/collection-panel/collection-panel-action.ts b/src/store/collection-panel/collection-panel-action.ts index 890a7441..7bab8632 100644 --- a/src/store/collection-panel/collection-panel-action.ts +++ b/src/store/collection-panel/collection-panel-action.ts @@ -22,12 +22,15 @@ export type CollectionPanelAction = UnionOf; export const loadCollectionPanel = (uuid: string, forceReload = false) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const { collectionPanel: { item } } = getState(); - const collection = (item && item.uuid === uuid && !forceReload) - ? item - : await services.collectionService.get(uuid); + let collection: CollectionResource | null = null; + if (!item || item.uuid !== uuid || forceReload) { + collection = await services.collectionService.get(uuid); + dispatch(collectionPanelActions.SET_COLLECTION(collection)); + dispatch(resourcesActions.SET_RESOURCES([collection])); + } else { + collection = item; + } dispatch(loadDetailsPanel(collection.uuid)); - dispatch(collectionPanelActions.SET_COLLECTION(collection)); - dispatch(resourcesActions.SET_RESOURCES([collection])); return collection; }; diff --git a/src/store/workbench/workbench-actions.ts b/src/store/workbench/workbench-actions.ts index 3142b633..0a348431 100644 --- a/src/store/workbench/workbench-actions.ts +++ b/src/store/workbench/workbench-actions.ts @@ -295,7 +295,7 @@ export const loadCollection = (uuid: string) => if (userUuid) { const match = await loadGroupContentsResource({ uuid, userUuid, services }); match({ - OWNED: async collection => { + OWNED: collection => { dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource)); dispatch(updateResources([collection])); dispatch(activateSidePanelTreeItem(collection.ownerUuid));