18787: Avoids re-rendering by only dispatching SET_COLLECTIONS when needed.
[arvados-workbench2.git] / src / store / collection-panel / collection-panel-action.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;
     };