Merge branch '20085-Sharing-Dialog-Form-Validation-Error-fix' into main
[arvados.git] / src / store / workbench / workbench-actions.ts
index b2da727b6615820d63639a67be27dcada870dc68..524337796efe37a6cfc472c9174eb3a7bd6012bd 100644 (file)
@@ -87,6 +87,7 @@ import {
     loadCollectionPanel,
 } from 'store/collection-panel/collection-panel-action';
 import { CollectionResource } from 'models/collection';
+import { WorkflowResource } from 'models/workflow';
 import {
     loadSearchResultsPanel,
     searchResultsPanelActions,
@@ -452,41 +453,34 @@ export const loadCollection = (uuid: string) =>
                     userUuid,
                     services,
                 });
+                let collection: CollectionResource | undefined;
+                let breadcrumbfunc: ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>) | undefined;
+                let sidepanel: string | undefined;
                 match({
-                    OWNED: (collection) => {
-                        dispatch(
-                            collectionPanelActions.SET_COLLECTION(
-                                collection as CollectionResource
-                            )
-                        );
-                        dispatch(updateResources([collection]));
-                        dispatch(activateSidePanelTreeItem(collection.ownerUuid));
-                        dispatch(setSidePanelBreadcrumbs(collection.ownerUuid));
-                        dispatch(loadCollectionPanel(collection.uuid));
+                    OWNED: (thecollection) => {
+                        collection = thecollection as CollectionResource;
+                        sidepanel = collection.ownerUuid;
+                        breadcrumbfunc = setSidePanelBreadcrumbs;
                     },
-                    SHARED: (collection) => {
-                        dispatch(
-                            collectionPanelActions.SET_COLLECTION(
-                                collection as CollectionResource
-                            )
-                        );
-                        dispatch(updateResources([collection]));
-                        dispatch<any>(setSharedWithMeBreadcrumbs(collection.ownerUuid));
-                        dispatch(activateSidePanelTreeItem(collection.ownerUuid));
-                        dispatch(loadCollectionPanel(collection.uuid));
+                    SHARED: (thecollection) => {
+                        collection = thecollection as CollectionResource;
+                        sidepanel = collection.ownerUuid;
+                        breadcrumbfunc = setSharedWithMeBreadcrumbs;
                     },
-                    TRASHED: (collection) => {
-                        dispatch(
-                            collectionPanelActions.SET_COLLECTION(
-                                collection as CollectionResource
-                            )
-                        );
-                        dispatch(updateResources([collection]));
-                        dispatch(setTrashBreadcrumbs(''));
-                        dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
-                        dispatch(loadCollectionPanel(collection.uuid));
+                    TRASHED: (thecollection) => {
+                        collection = thecollection as CollectionResource;
+                        sidepanel = SidePanelTreeCategory.TRASH;
+                        breadcrumbfunc = () => setTrashBreadcrumbs('');
                     },
                 });
+                if (collection && breadcrumbfunc && sidepanel) {
+                    dispatch(updateResources([collection]));
+                    await dispatch<any>(finishLoadingProject(collection.ownerUuid));
+                    dispatch(collectionPanelActions.SET_COLLECTION(collection));
+                    await dispatch(activateSidePanelTreeItem(sidepanel));
+                    dispatch(breadcrumbfunc(collection.ownerUuid));
+                    dispatch(loadCollectionPanel(collection.uuid));
+                }
             }
         }
     );
@@ -579,11 +573,48 @@ export const loadProcess = (uuid: string) =>
     handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
         dispatch<any>(loadProcessPanel(uuid));
         const process = await dispatch<any>(processesActions.loadProcess(uuid));
-        await dispatch<any>(
-            activateSidePanelTreeItem(process.containerRequest.ownerUuid)
-        );
-        dispatch<any>(setProcessBreadcrumbs(uuid));
-        dispatch<any>(loadDetailsPanel(uuid));
+        if (process) {
+            await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
+            await dispatch<any>(
+                activateSidePanelTreeItem(process.containerRequest.ownerUuid)
+            );
+            dispatch<any>(setProcessBreadcrumbs(uuid));
+            dispatch<any>(loadDetailsPanel(uuid));
+        }
+    });
+
+export const loadRegisteredWorkflow = (uuid: string) =>
+    handleFirstTimeLoad(async (dispatch: Dispatch,
+        getState: () => RootState,
+        services: ServiceRepository) => {
+
+        const userUuid = getUserUuid(getState());
+        if (userUuid) {
+            const match = await loadGroupContentsResource({
+                uuid,
+                userUuid,
+                services,
+            });
+            let workflow: WorkflowResource | undefined;
+            let breadcrumbfunc: ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>) | undefined;
+            match({
+                OWNED: async (theworkflow) => {
+                    workflow = theworkflow as WorkflowResource;
+                    breadcrumbfunc = setSidePanelBreadcrumbs;
+                },
+                SHARED: async (theworkflow) => {
+                    workflow = theworkflow as WorkflowResource;
+                    breadcrumbfunc = setSharedWithMeBreadcrumbs;
+                },
+                TRASHED: () => { }
+            });
+            if (workflow && breadcrumbfunc) {
+                dispatch(updateResources([workflow]));
+                await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
+                await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
+                dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
+            }
+        }
     });
 
 export const updateProcess =
@@ -662,6 +693,7 @@ export const copyProcess =
                         kind: SnackbarKind.SUCCESS,
                     })
                 );
+                dispatch<any>(navigateTo(process.uuid));
             } catch (e) {
                 dispatch(
                     snackbarActions.OPEN_SNACKBAR({
@@ -873,8 +905,12 @@ const loadGroupContentsResource = async (params: {
             resource = await params.services.collectionService.get(params.uuid);
         } else if (kind === ResourceKind.PROJECT) {
             resource = await params.services.projectService.get(params.uuid);
-        } else {
+        } else if (kind === ResourceKind.WORKFLOW) {
+            resource = await params.services.workflowService.get(params.uuid);
+        } else if (kind === ResourceKind.CONTAINER_REQUEST) {
             resource = await params.services.containerRequestService.get(params.uuid);
+        } else {
+            throw new Error("loadGroupContentsResource unsupported kind " + kind)
         }
         handler = groupContentsHandlers.SHARED(resource);
     }