16439: Merge branch 'master' into 16439-objects-creation-placement-fix
[arvados-workbench2.git] / src / store / workbench / workbench-actions.ts
index 9917782ab45baa8b98c34db97efe91256ddd35d2..e2ff01f7afa71c6df8e6434ce03d08a830f5c0fb 100644 (file)
@@ -4,6 +4,7 @@
 
 import { Dispatch } from 'redux';
 import { RootState } from "~/store/store";
+import { getUserUuid } from "~/common/getuser";
 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
 import { favoritePanelActions, loadFavoritePanel } from '~/store/favorite-panel/favorite-panel-action';
@@ -19,7 +20,7 @@ import {
     loadSidePanelTreeProjects,
     SidePanelTreeCategory
 } from '~/store/side-panel-tree/side-panel-tree-actions';
-import { loadResource, updateResources } from '~/store/resources/resources-actions';
+import { updateResources } from '~/store/resources/resources-actions';
 import { projectPanelColumns } from '~/views/project-panel/project-panel';
 import { favoritePanelColumns } from '~/views/favorite-panel/favorite-panel';
 import { matchRootRoute } from '~/routes/routes';
@@ -32,7 +33,7 @@ import {
     setSidePanelBreadcrumbs,
     setTrashBreadcrumbs
 } from '~/store/breadcrumbs/breadcrumbs-actions';
-import { navigateToProject } from '~/store/navigation/navigation-action';
+import { navigateTo } from '~/store/navigation/navigation-action';
 import { MoveToFormDialogData } from '~/store/move-to-dialog/move-to-dialog';
 import { ServiceRepository } from '~/services/services';
 import { getResource } from '~/store/resources/resources';
@@ -96,6 +97,10 @@ import { loadPublicFavoritePanel, publicFavoritePanelActions } from '~/store/pub
 import { publicFavoritePanelColumns } from '~/views/public-favorites-panel/public-favorites-panel';
 import { loadCollectionsContentAddressPanel, collectionsContentAddressActions } from '~/store/collections-content-address-panel/collections-content-address-panel-actions';
 import { collectionContentAddressPanelColumns } from '~/views/collection-content-address-panel/collection-content-address-panel';
+import { subprocessPanelActions } from '~/store/subprocess-panel/subprocess-panel-actions';
+import { subprocessPanelColumns } from '~/views/subprocess-panel/subprocess-panel-root';
+import { loadAllProcessesPanel, allProcessesPanelActions } from '../all-processes-panel/all-processes-panel-action';
+import { allProcessesPanelColumns } from '~/views/all-processes-panel/all-processes-panel';
 
 export const WORKBENCH_LOADING_SCREEN = 'workbenchLoadingScreen';
 
@@ -123,6 +128,7 @@ export const loadWorkbench = () =>
         if (user) {
             dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
             dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
+            dispatch(allProcessesPanelActions.SET_COLUMNS({ columns: allProcessesPanelColumns }));
             dispatch(publicFavoritePanelActions.SET_COLUMNS({ columns: publicFavoritePanelColumns }));
             dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
             dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
@@ -136,6 +142,7 @@ export const loadWorkbench = () =>
             dispatch(computeNodesActions.SET_COLUMNS({ columns: computeNodePanelColumns }));
             dispatch(apiClientAuthorizationsActions.SET_COLUMNS({ columns: apiClientAuthorizationPanelColumns }));
             dispatch(collectionsContentAddressActions.SET_COLUMNS({ columns: collectionContentAddressPanelColumns }));
+            dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
 
             if (services.linkAccountService.getAccountToLink()) {
                 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
@@ -145,7 +152,7 @@ export const loadWorkbench = () =>
             if (router.location) {
                 const match = matchRootRoute(router.location.pathname);
                 if (match) {
-                    dispatch(navigateToProject(user.uuid));
+                    dispatch<any>(navigateTo(user.uuid));
                 }
             }
         } else {
@@ -174,10 +181,19 @@ export const loadTrash = () =>
             dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
         });
 
+export const loadAllProcesses = () =>
+    handleFirstTimeLoad(
+        (dispatch: Dispatch) => {
+            dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
+            dispatch<any>(loadAllProcessesPanel());
+            dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
+        }
+    );
+
 export const loadProject = (uuid: string) =>
     handleFirstTimeLoad(
         async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
-            const userUuid = services.authService.getUuid();
+            const userUuid = getUserUuid(getState());
             dispatch(setIsProjectPanelTrashed(false));
             if (userUuid) {
                 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
@@ -221,7 +237,7 @@ export const createProject = (data: projectCreateActions.ProjectCreateFormDialog
                 kind: SnackbarKind.SUCCESS
             }));
             await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
-            dispatch<any>(reloadProjectMatchingUuid([newProject.ownerUuid]));
+            dispatch<any>(navigateTo(newProject.uuid));
         }
     };
 
@@ -260,14 +276,14 @@ export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialog
 export const loadCollection = (uuid: string) =>
     handleFirstTimeLoad(
         async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
-            const userUuid = services.authService.getUuid();
+            const userUuid = getUserUuid(getState());
             if (userUuid) {
                 const match = await loadGroupContentsResource({ uuid, userUuid, services });
                 match({
                     OWNED: async collection => {
                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
                         dispatch(updateResources([collection]));
-                        await dispatch(activateSidePanelTreeItem(collection.ownerUuid));
+                        dispatch(activateSidePanelTreeItem(collection.ownerUuid));
                         dispatch(setSidePanelBreadcrumbs(collection.ownerUuid));
                         dispatch(loadCollectionPanel(collection.uuid));
                     },
@@ -285,7 +301,6 @@ export const loadCollection = (uuid: string) =>
                         dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
                         dispatch(loadCollectionPanel(collection.uuid));
                     },
-
                 });
             }
         });
@@ -300,21 +315,25 @@ export const createCollection = (data: collectionCreateActions.CollectionCreateF
                 kind: SnackbarKind.SUCCESS
             }));
             dispatch<any>(updateResources([collection]));
-            dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
+            dispatch<any>(navigateTo(collection.uuid));
         }
     };
 
 export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
     async (dispatch: Dispatch) => {
-        const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
-        if (collection) {
-            dispatch(snackbarActions.OPEN_SNACKBAR({
-                message: "Collection has been successfully updated.",
-                hideDuration: 2000,
-                kind: SnackbarKind.SUCCESS
-            }));
-            dispatch<any>(updateResources([collection]));
-            dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
+        try {
+            const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
+            if (collection) {
+                dispatch(snackbarActions.OPEN_SNACKBAR({
+                    message: "Collection has been successfully updated.",
+                    hideDuration: 2000,
+                    kind: SnackbarKind.SUCCESS
+                }));
+                dispatch<any>(updateResources([collection]));
+                dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
+            }
+        } catch (e) {
+            dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors.join(''), hideDuration: 2000, kind: SnackbarKind.ERROR }));
         }
     };