18787: Avoids re-rendering by only dispatching SET_COLLECTIONS when needed.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 31 May 2022 12:19:10 +0000 (09:19 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 31 May 2022 12:19:10 +0000 (09:19 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/store/collection-panel/collection-panel-action.ts
src/store/workbench/workbench-actions.ts

index 890a7441aa6ee14971f15517996f0b6e676a7363..7bab86320da1e00c2a3f2a1706b824722c87e14c 100644 (file)
@@ -22,12 +22,15 @@ export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
 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<any>(loadDetailsPanel(collection.uuid));
-        dispatch(collectionPanelActions.SET_COLLECTION(collection));
-        dispatch(resourcesActions.SET_RESOURCES([collection]));
         return collection;
     };
 
index 3142b63339f61ed461ea73a7d59b81239b2d16b8..0a3484310ee74a5d6e5182f3e47fb27290520ef3 100644 (file)
@@ -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));