Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / collection-panel / collection-panel-action.ts
index 55eb5949dd70d61f805a923d36f91607d1c9cb98..49573215af9224d55942d2dc2e33c8c177d017e5 100644 (file)
@@ -12,10 +12,10 @@ import { unionize, ofType, UnionOf } from 'common/unionize';
 import { SnackbarKind } from 'store/snackbar/snackbar-actions';
 import { navigateTo } from 'store/navigation/navigation-action';
 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
+import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
 
 export const collectionPanelActions = unionize({
     SET_COLLECTION: ofType<CollectionResource>(),
-    LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>(),
 });
 
 export type CollectionPanelAction = UnionOf<typeof collectionPanelActions>;
@@ -23,12 +23,20 @@ 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) {
+            try {
+                dispatch(progressIndicatorActions.START_WORKING(uuid + "-panel"));
+                collection = await services.collectionService.get(uuid);
+                dispatch(collectionPanelActions.SET_COLLECTION(collection));
+                dispatch(resourcesActions.SET_RESOURCES([collection]));
+            } finally {
+                dispatch(progressIndicatorActions.STOP_WORKING(uuid + "-panel"));
+            }
+        } else {
+            collection = item;
+        }
         dispatch<any>(loadDetailsPanel(collection.uuid));
-        dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection }));
-        dispatch(resourcesActions.SET_RESOURCES([collection]));
         return collection;
     };