Merge 'main' into 20382-process-action-menu-cancel
[arvados-workbench2.git] / src / store / workbench / workbench-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from "redux";
6 import { RootState } from "store/store";
7 import { getUserUuid } from "common/getuser";
8 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
9 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
10 import { favoritePanelActions, loadFavoritePanel } from "store/favorite-panel/favorite-panel-action";
11 import { getProjectPanelCurrentUuid, setIsProjectPanelTrashed } from "store/project-panel/project-panel-action";
12 import { projectPanelActions } from "store/project-panel/project-panel-action-bind";
13 import {
14     activateSidePanelTreeItem,
15     initSidePanelTree,
16     loadSidePanelTreeProjects,
17     SidePanelTreeCategory,
18 } from "store/side-panel-tree/side-panel-tree-actions";
19 import { updateResources } from "store/resources/resources-actions";
20 import { projectPanelColumns } from "views/project-panel/project-panel";
21 import { favoritePanelColumns } from "views/favorite-panel/favorite-panel";
22 import { matchRootRoute } from "routes/routes";
23 import {
24     setBreadcrumbs,
25     setGroupDetailsBreadcrumbs,
26     setGroupsBreadcrumbs,
27     setProcessBreadcrumbs,
28     setSharedWithMeBreadcrumbs,
29     setSidePanelBreadcrumbs,
30     setTrashBreadcrumbs,
31     setUsersBreadcrumbs,
32     setMyAccountBreadcrumbs,
33     setUserProfileBreadcrumbs,
34 } from "store/breadcrumbs/breadcrumbs-actions";
35 import { navigateTo, navigateToRootProject } from "store/navigation/navigation-action";
36 import { MoveToFormDialogData } from "store/move-to-dialog/move-to-dialog";
37 import { ServiceRepository } from "services/services";
38 import { getResource } from "store/resources/resources";
39 import * as projectCreateActions from "store/projects/project-create-actions";
40 import * as projectMoveActions from "store/projects/project-move-actions";
41 import * as projectUpdateActions from "store/projects/project-update-actions";
42 import * as collectionCreateActions from "store/collections/collection-create-actions";
43 import * as collectionCopyActions from "store/collections/collection-copy-actions";
44 import * as collectionMoveActions from "store/collections/collection-move-actions";
45 import * as processesActions from "store/processes/processes-actions";
46 import * as processMoveActions from "store/processes/process-move-actions";
47 import * as processUpdateActions from "store/processes/process-update-actions";
48 import * as processCopyActions from "store/processes/process-copy-actions";
49 import { trashPanelColumns } from "views/trash-panel/trash-panel";
50 import { loadTrashPanel, trashPanelActions } from "store/trash-panel/trash-panel-action";
51 import { loadProcessPanel } from "store/process-panel/process-panel-actions";
52 import { loadSharedWithMePanel, sharedWithMePanelActions } from "store/shared-with-me-panel/shared-with-me-panel-actions";
53 import { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
54 import { workflowPanelActions } from "store/workflow-panel/workflow-panel-actions";
55 import { loadSshKeysPanel } from "store/auth/auth-action-ssh";
56 import { loadLinkAccountPanel, linkAccountPanelActions } from "store/link-account-panel/link-account-panel-actions";
57 import { loadSiteManagerPanel } from "store/auth/auth-action-session";
58 import { workflowPanelColumns } from "views/workflow-panel/workflow-panel-view";
59 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
60 import { getProgressIndicator } from "store/progress-indicator/progress-indicator-reducer";
61 import { extractUuidKind, Resource, ResourceKind } from "models/resource";
62 import { FilterBuilder } from "services/api/filter-builder";
63 import { GroupContentsResource } from "services/groups-service/groups-service";
64 import { MatchCases, ofType, unionize, UnionOf } from "common/unionize";
65 import { loadRunProcessPanel } from "store/run-process-panel/run-process-panel-actions";
66 import { collectionPanelActions, loadCollectionPanel } from "store/collection-panel/collection-panel-action";
67 import { CollectionResource } from "models/collection";
68 import { WorkflowResource } from "models/workflow";
69 import { loadSearchResultsPanel, searchResultsPanelActions } from "store/search-results-panel/search-results-panel-actions";
70 import { searchResultsPanelColumns } from "views/search-results-panel/search-results-panel-view";
71 import { loadVirtualMachinesPanel } from "store/virtual-machines/virtual-machines-actions";
72 import { loadRepositoriesPanel } from "store/repositories/repositories-actions";
73 import { loadKeepServicesPanel } from "store/keep-services/keep-services-actions";
74 import { loadUsersPanel, userBindedActions } from "store/users/users-actions";
75 import * as userProfilePanelActions from "store/user-profile/user-profile-actions";
76 import { linkPanelActions, loadLinkPanel } from "store/link-panel/link-panel-actions";
77 import { linkPanelColumns } from "views/link-panel/link-panel-root";
78 import { userPanelColumns } from "views/user-panel/user-panel";
79 import { loadApiClientAuthorizationsPanel, apiClientAuthorizationsActions } from "store/api-client-authorizations/api-client-authorizations-actions";
80 import { apiClientAuthorizationPanelColumns } from "views/api-client-authorization-panel/api-client-authorization-panel-root";
81 import * as groupPanelActions from "store/groups-panel/groups-panel-actions";
82 import { groupsPanelColumns } from "views/groups-panel/groups-panel";
83 import * as groupDetailsPanelActions from "store/group-details-panel/group-details-panel-actions";
84 import { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from "views/group-details-panel/group-details-panel";
85 import { DataTableFetchMode } from "components/data-table/data-table";
86 import { loadPublicFavoritePanel, publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
87 import { publicFavoritePanelColumns } from "views/public-favorites-panel/public-favorites-panel";
88 import {
89     loadCollectionsContentAddressPanel,
90     collectionsContentAddressActions,
91 } from "store/collections-content-address-panel/collections-content-address-panel-actions";
92 import { collectionContentAddressPanelColumns } from "views/collection-content-address-panel/collection-content-address-panel";
93 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
94 import { subprocessPanelColumns } from "views/subprocess-panel/subprocess-panel-root";
95 import { loadAllProcessesPanel, allProcessesPanelActions } from "../all-processes-panel/all-processes-panel-action";
96 import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
97 import { AdminMenuIcon } from "components/icon/icon";
98 import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
99 import { selectedToArray, selectedToKindSet } from "components/multiselect-toolbar/MultiselectToolbar";
100 import { multiselectActions } from "store/multiselect/multiselect-actions";
101
102 export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
103
104 export const isWorkbenchLoading = (state: RootState) => {
105     const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
106     return progress ? progress.working : false;
107 };
108
109 export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
110     try {
111         await dispatch(action);
112     } finally {
113         if (isWorkbenchLoading(getState())) {
114             dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
115         }
116     }
117 };
118
119 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
120     dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
121     const { auth, router } = getState();
122     const { user } = auth;
123     if (user) {
124         dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
125         dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
126         dispatch(
127             allProcessesPanelActions.SET_COLUMNS({
128                 columns: allProcessesPanelColumns,
129             })
130         );
131         dispatch(
132             publicFavoritePanelActions.SET_COLUMNS({
133                 columns: publicFavoritePanelColumns,
134             })
135         );
136         dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
137         dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
138         dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
139         dispatch(
140             searchResultsPanelActions.SET_FETCH_MODE({
141                 fetchMode: DataTableFetchMode.INFINITE,
142             })
143         );
144         dispatch(
145             searchResultsPanelActions.SET_COLUMNS({
146                 columns: searchResultsPanelColumns,
147             })
148         );
149         dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
150         dispatch(
151             groupPanelActions.GroupsPanelActions.SET_COLUMNS({
152                 columns: groupsPanelColumns,
153             })
154         );
155         dispatch(
156             groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
157                 columns: groupDetailsMembersPanelColumns,
158             })
159         );
160         dispatch(
161             groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
162                 columns: groupDetailsPermissionsPanelColumns,
163             })
164         );
165         dispatch(
166             userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
167                 columns: userProfileGroupsColumns,
168             })
169         );
170         dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
171         dispatch(
172             apiClientAuthorizationsActions.SET_COLUMNS({
173                 columns: apiClientAuthorizationPanelColumns,
174             })
175         );
176         dispatch(
177             collectionsContentAddressActions.SET_COLUMNS({
178                 columns: collectionContentAddressPanelColumns,
179             })
180         );
181         dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
182
183         if (services.linkAccountService.getAccountToLink()) {
184             dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
185         }
186
187         dispatch<any>(initSidePanelTree());
188         if (router.location) {
189             const match = matchRootRoute(router.location.pathname);
190             if (match) {
191                 dispatch<any>(navigateToRootProject);
192             }
193         }
194     } else {
195         dispatch(userIsNotAuthenticated);
196     }
197 };
198
199 export const loadFavorites = () =>
200     handleFirstTimeLoad((dispatch: Dispatch) => {
201         dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
202         dispatch<any>(loadFavoritePanel());
203         dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
204     });
205
206 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
207     await dispatch(loadCollectionsContentAddressPanel());
208 });
209
210 export const loadTrash = () =>
211     handleFirstTimeLoad((dispatch: Dispatch) => {
212         dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
213         dispatch<any>(loadTrashPanel());
214         dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
215     });
216
217 export const loadAllProcesses = () =>
218     handleFirstTimeLoad((dispatch: Dispatch) => {
219         dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
220         dispatch<any>(loadAllProcessesPanel());
221         dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
222     });
223
224 export const loadProject = (uuid: string) =>
225     handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
226         const userUuid = getUserUuid(getState());
227         dispatch(setIsProjectPanelTrashed(false));
228         if (!userUuid) {
229             return;
230         }
231         if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
232             // Load another users home projects
233             dispatch(finishLoadingProject(uuid));
234         } else if (userUuid !== uuid) {
235             await dispatch(finishLoadingProject(uuid));
236             const match = await loadGroupContentsResource({
237                 uuid,
238                 userUuid,
239                 services,
240             });
241             match({
242                 OWNED: async () => {
243                     await dispatch(activateSidePanelTreeItem(uuid));
244                     dispatch<any>(setSidePanelBreadcrumbs(uuid));
245                 },
246                 SHARED: async () => {
247                     await dispatch(activateSidePanelTreeItem(uuid));
248                     dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
249                 },
250                 TRASHED: async () => {
251                     await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
252                     dispatch<any>(setTrashBreadcrumbs(uuid));
253                     dispatch(setIsProjectPanelTrashed(true));
254                 },
255             });
256         } else {
257             await dispatch(finishLoadingProject(userUuid));
258             await dispatch(activateSidePanelTreeItem(userUuid));
259             dispatch<any>(setSidePanelBreadcrumbs(userUuid));
260         }
261     });
262
263 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
264     const newProject = await dispatch<any>(projectCreateActions.createProject(data));
265     if (newProject) {
266         dispatch(
267             snackbarActions.OPEN_SNACKBAR({
268                 message: "Project has been successfully created.",
269                 hideDuration: 2000,
270                 kind: SnackbarKind.SUCCESS,
271             })
272         );
273         await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
274         dispatch<any>(navigateTo(newProject.uuid));
275     }
276 };
277
278 export const moveProject =
279     (data: MoveToFormDialogData, isSecondaryMove = false) =>
280     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
281         const checkedList = getState().multiselect.checkedList;
282         const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
283
284         //if no items in checkedlist default to normal context menu behavior
285         if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
286
287         const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
288         const destinationUuid = data.ownerUuid;
289
290         const projectsToMove: MoveableResource[] = uuidsToMove
291             .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
292             .filter(resource => resource.kind === ResourceKind.PROJECT);
293
294         for (const project of projectsToMove) {
295             await moveSingleProject(project);
296         }
297
298         //omly propagate if this call is the original
299         if (!isSecondaryMove) {
300             const kindsToMove: Set<string> = selectedToKindSet(checkedList);
301             kindsToMove.delete(ResourceKind.PROJECT);
302
303             kindsToMove.forEach(kind => {
304                 secondaryMove[kind](data, true)(dispatch, getState, services);
305             });
306         }
307
308         async function moveSingleProject(project: MoveableResource) {
309             try {
310                 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
311                 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
312                 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
313                 if (movedProject) {
314                     dispatch(
315                         snackbarActions.OPEN_SNACKBAR({
316                             message: "Project has been moved",
317                             hideDuration: 2000,
318                             kind: SnackbarKind.SUCCESS,
319                         })
320                     );
321                     await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
322                 }
323             } catch (e) {
324                 dispatch(
325                     snackbarActions.OPEN_SNACKBAR({
326                         message: e.message,
327                         hideDuration: 2000,
328                         kind: SnackbarKind.ERROR,
329                     })
330                 );
331             }
332         }
333         if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
334         await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
335     };
336
337 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
338     const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
339     if (updatedProject) {
340         dispatch(
341             snackbarActions.OPEN_SNACKBAR({
342                 message: "Project has been successfully updated.",
343                 hideDuration: 2000,
344                 kind: SnackbarKind.SUCCESS,
345             })
346         );
347         await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
348         dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
349     }
350 };
351
352 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
353     const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
354     if (updatedGroup) {
355         dispatch(
356             snackbarActions.OPEN_SNACKBAR({
357                 message: "Group has been successfully updated.",
358                 hideDuration: 2000,
359                 kind: SnackbarKind.SUCCESS,
360             })
361         );
362         await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
363         dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
364     }
365 };
366
367 export const loadCollection = (uuid: string) =>
368     handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
369         const userUuid = getUserUuid(getState());
370         if (userUuid) {
371             const match = await loadGroupContentsResource({
372                 uuid,
373                 userUuid,
374                 services,
375             });
376             let collection: CollectionResource | undefined;
377             let breadcrumbfunc:
378                 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
379                 | undefined;
380             let sidepanel: string | undefined;
381             match({
382                 OWNED: thecollection => {
383                     collection = thecollection as CollectionResource;
384                     sidepanel = collection.ownerUuid;
385                     breadcrumbfunc = setSidePanelBreadcrumbs;
386                 },
387                 SHARED: thecollection => {
388                     collection = thecollection as CollectionResource;
389                     sidepanel = collection.ownerUuid;
390                     breadcrumbfunc = setSharedWithMeBreadcrumbs;
391                 },
392                 TRASHED: thecollection => {
393                     collection = thecollection as CollectionResource;
394                     sidepanel = SidePanelTreeCategory.TRASH;
395                     breadcrumbfunc = () => setTrashBreadcrumbs("");
396                 },
397             });
398             if (collection && breadcrumbfunc && sidepanel) {
399                 dispatch(updateResources([collection]));
400                 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
401                 dispatch(collectionPanelActions.SET_COLLECTION(collection));
402                 await dispatch(activateSidePanelTreeItem(sidepanel));
403                 dispatch(breadcrumbfunc(collection.ownerUuid));
404                 dispatch(loadCollectionPanel(collection.uuid));
405             }
406         }
407     });
408
409 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
410     const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
411     if (collection) {
412         dispatch(
413             snackbarActions.OPEN_SNACKBAR({
414                 message: "Collection has been successfully created.",
415                 hideDuration: 2000,
416                 kind: SnackbarKind.SUCCESS,
417             })
418         );
419         dispatch<any>(updateResources([collection]));
420         dispatch<any>(navigateTo(collection.uuid));
421     }
422 };
423
424 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
425     const checkedList = getState().multiselect.checkedList;
426     const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
427
428     //if no items in checkedlist && no items passed in, default to normal context menu behavior
429     if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
430
431     const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
432         .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
433         .filter(resource => resource.kind === ResourceKind.COLLECTION);
434
435     for (const collection of collectionsToCopy) {
436         await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
437     }
438
439     async function copySingleCollection(copyToProject: CollectionCopyResource) {
440         const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
441         try {
442             const collection = await dispatch<any>(
443                 collectionCopyActions.copyCollection({
444                     ...copyToProject,
445                     name: newName,
446                     fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
447                 })
448             );
449             if (copyToProject && collection) {
450                 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
451                 dispatch(
452                     snackbarActions.OPEN_SNACKBAR({
453                         message: "Collection has been copied.",
454                         hideDuration: 3000,
455                         kind: SnackbarKind.SUCCESS,
456                         link: collection.ownerUuid,
457                     })
458                 );
459                 dispatch<any>(multiselectActions.deselectOne(copyToProject.uuid));
460             }
461         } catch (e) {
462             dispatch(
463                 snackbarActions.OPEN_SNACKBAR({
464                     message: e.message,
465                     hideDuration: 2000,
466                     kind: SnackbarKind.ERROR,
467                 })
468             );
469         }
470     }
471     dispatch(projectPanelActions.REQUEST_ITEMS());
472 };
473
474 export const moveCollection =
475     (data: MoveToFormDialogData, isSecondaryMove = false) =>
476     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
477         const checkedList = getState().multiselect.checkedList;
478         const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
479
480         //if no items in checkedlist && no items passed in, default to normal context menu behavior
481         if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
482
483         const collectionsToMove: MoveableResource[] = uuidsToMove
484             .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
485             .filter(resource => resource.kind === ResourceKind.COLLECTION);
486
487         for (const collection of collectionsToMove) {
488             await moveSingleCollection(collection);
489         }
490
491         //omly propagate if this call is the original
492         if (!isSecondaryMove) {
493             const kindsToMove: Set<string> = selectedToKindSet(checkedList);
494             kindsToMove.delete(ResourceKind.COLLECTION);
495
496             kindsToMove.forEach(kind => {
497                 secondaryMove[kind](data, true)(dispatch, getState, services);
498             });
499         }
500
501         async function moveSingleCollection(collection: MoveableResource) {
502             try {
503                 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
504                 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
505                 dispatch<any>(updateResources([movedCollection]));
506                 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
507                 dispatch(
508                     snackbarActions.OPEN_SNACKBAR({
509                         message: "Collection has been moved.",
510                         hideDuration: 2000,
511                         kind: SnackbarKind.SUCCESS,
512                     })
513                 );
514             } catch (e) {
515                 dispatch(
516                     snackbarActions.OPEN_SNACKBAR({
517                         message: e.message,
518                         hideDuration: 2000,
519                         kind: SnackbarKind.ERROR,
520                     })
521                 );
522             }
523         }
524     };
525
526 export const loadProcess = (uuid: string) =>
527     handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
528         dispatch<any>(loadProcessPanel(uuid));
529         const process = await dispatch<any>(processesActions.loadProcess(uuid));
530         if (process) {
531             await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
532             await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
533             dispatch<any>(setProcessBreadcrumbs(uuid));
534             dispatch<any>(loadDetailsPanel(uuid));
535         }
536     });
537
538 export const loadRegisteredWorkflow = (uuid: string) =>
539     handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
540         const userUuid = getUserUuid(getState());
541         if (userUuid) {
542             const match = await loadGroupContentsResource({
543                 uuid,
544                 userUuid,
545                 services,
546             });
547             let workflow: WorkflowResource | undefined;
548             let breadcrumbfunc:
549                 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
550                 | undefined;
551             match({
552                 OWNED: async theworkflow => {
553                     workflow = theworkflow as WorkflowResource;
554                     breadcrumbfunc = setSidePanelBreadcrumbs;
555                 },
556                 SHARED: async theworkflow => {
557                     workflow = theworkflow as WorkflowResource;
558                     breadcrumbfunc = setSharedWithMeBreadcrumbs;
559                 },
560                 TRASHED: () => {},
561             });
562             if (workflow && breadcrumbfunc) {
563                 dispatch(updateResources([workflow]));
564                 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
565                 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
566                 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
567             }
568         }
569     });
570
571 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
572     try {
573         const process = await dispatch<any>(processUpdateActions.updateProcess(data));
574         if (process) {
575             dispatch(
576                 snackbarActions.OPEN_SNACKBAR({
577                     message: "Process has been successfully updated.",
578                     hideDuration: 2000,
579                     kind: SnackbarKind.SUCCESS,
580                 })
581             );
582             dispatch<any>(updateResources([process]));
583             dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
584         }
585     } catch (e) {
586         dispatch(
587             snackbarActions.OPEN_SNACKBAR({
588                 message: e.message,
589                 hideDuration: 2000,
590                 kind: SnackbarKind.ERROR,
591             })
592         );
593     }
594 };
595
596 export const moveProcess =
597     (data: MoveToFormDialogData, isSecondaryMove = false) =>
598     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
599         const checkedList = getState().multiselect.checkedList;
600         const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
601
602         //if no items in checkedlist && no items passed in, default to normal context menu behavior
603         if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
604
605         const processesToMove: MoveableResource[] = uuidsToMove
606             .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
607             .filter(resource => resource.kind === ResourceKind.PROCESS);
608
609         for (const process of processesToMove) {
610             await moveSingleProcess(process);
611         }
612
613         //omly propagate if this call is the original
614         if (!isSecondaryMove) {
615             const kindsToMove: Set<string> = selectedToKindSet(checkedList);
616             kindsToMove.delete(ResourceKind.PROCESS);
617
618             kindsToMove.forEach(kind => {
619                 secondaryMove[kind](data, true)(dispatch, getState, services);
620             });
621         }
622
623         async function moveSingleProcess(process: MoveableResource) {
624             try {
625                 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
626                 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
627                 dispatch<any>(updateResources([movedProcess]));
628                 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
629                 dispatch(
630                     snackbarActions.OPEN_SNACKBAR({
631                         message: "Process has been moved.",
632                         hideDuration: 2000,
633                         kind: SnackbarKind.SUCCESS,
634                     })
635                 );
636             } catch (e) {
637                 dispatch(
638                     snackbarActions.OPEN_SNACKBAR({
639                         message: e.message,
640                         hideDuration: 2000,
641                         kind: SnackbarKind.ERROR,
642                     })
643                 );
644             }
645         }
646     };
647
648 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
649     try {
650         const process = await dispatch<any>(processCopyActions.copyProcess(data));
651         dispatch<any>(updateResources([process]));
652         dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
653         dispatch(
654             snackbarActions.OPEN_SNACKBAR({
655                 message: "Process has been copied.",
656                 hideDuration: 2000,
657                 kind: SnackbarKind.SUCCESS,
658             })
659         );
660         dispatch<any>(navigateTo(process.uuid));
661     } catch (e) {
662         dispatch(
663             snackbarActions.OPEN_SNACKBAR({
664                 message: e.message,
665                 hideDuration: 2000,
666                 kind: SnackbarKind.ERROR,
667             })
668         );
669     }
670 };
671
672 export const resourceIsNotLoaded = (uuid: string) =>
673     snackbarActions.OPEN_SNACKBAR({
674         message: `Resource identified by ${uuid} is not loaded.`,
675         kind: SnackbarKind.ERROR,
676     });
677
678 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
679     message: "User is not authenticated",
680     kind: SnackbarKind.ERROR,
681 });
682
683 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
684     message: "Could not load user",
685     kind: SnackbarKind.ERROR,
686 });
687
688 export const reloadProjectMatchingUuid =
689     (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
690         const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
691         if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
692             dispatch<any>(loadProject(currentProjectPanelUuid));
693         }
694     };
695
696 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
697     dispatch<any>(loadSharedWithMePanel());
698     await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
699     await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
700 });
701
702 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
703     await dispatch<any>(loadRunProcessPanel());
704 });
705
706 export const loadPublicFavorites = () =>
707     handleFirstTimeLoad((dispatch: Dispatch) => {
708         dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
709         dispatch<any>(loadPublicFavoritePanel());
710         dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
711     });
712
713 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
714     await dispatch(loadSearchResultsPanel());
715 });
716
717 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
718     await dispatch(loadLinkPanel());
719 });
720
721 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
722     await dispatch(loadVirtualMachinesPanel());
723     dispatch(setBreadcrumbs([{ label: "Virtual Machines" }]));
724 });
725
726 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
727     await dispatch(loadVirtualMachinesPanel());
728     dispatch(setBreadcrumbs([{ label: "Virtual Machines Admin", icon: AdminMenuIcon }]));
729 });
730
731 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
732     await dispatch(loadRepositoriesPanel());
733     dispatch(setBreadcrumbs([{ label: "Repositories" }]));
734 });
735
736 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
737     await dispatch(loadSshKeysPanel());
738 });
739
740 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
741     await dispatch(loadSiteManagerPanel());
742 });
743
744 export const loadUserProfile = (userUuid?: string) =>
745     handleFirstTimeLoad((dispatch: Dispatch<any>) => {
746         if (userUuid) {
747             dispatch(setUserProfileBreadcrumbs(userUuid));
748             dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
749         } else {
750             dispatch(setMyAccountBreadcrumbs());
751             dispatch(userProfilePanelActions.loadUserProfilePanel());
752         }
753     });
754
755 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
756     dispatch(loadLinkAccountPanel());
757 });
758
759 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
760     await dispatch(loadKeepServicesPanel());
761 });
762
763 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
764     await dispatch(loadUsersPanel());
765     dispatch(setUsersBreadcrumbs());
766 });
767
768 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
769     await dispatch(loadApiClientAuthorizationsPanel());
770 });
771
772 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
773     dispatch(setGroupsBreadcrumbs());
774     dispatch(groupPanelActions.loadGroupsPanel());
775 });
776
777 export const loadGroupDetailsPanel = (groupUuid: string) =>
778     handleFirstTimeLoad((dispatch: Dispatch<any>) => {
779         dispatch(setGroupDetailsBreadcrumbs(groupUuid));
780         dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
781     });
782
783 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
784     const uuid = typeof project === "string" ? project : project.uuid;
785     dispatch(loadDetailsPanel(uuid));
786     if (typeof project !== "string") {
787         dispatch(updateResources([project]));
788     }
789 };
790
791 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
792     const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
793     const { items } = await params.services.groupsService.contents(params.userUuid, {
794         filters,
795         recursive: true,
796         includeTrash: true,
797     });
798     const resource = items.shift();
799     let handler: GroupContentsHandler;
800     if (resource) {
801         handler =
802             (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
803                 ? groupContentsHandlers.TRASHED(resource)
804                 : groupContentsHandlers.OWNED(resource);
805     } else {
806         const kind = extractUuidKind(params.uuid);
807         let resource: GroupContentsResource;
808         if (kind === ResourceKind.COLLECTION) {
809             resource = await params.services.collectionService.get(params.uuid);
810         } else if (kind === ResourceKind.PROJECT) {
811             resource = await params.services.projectService.get(params.uuid);
812         } else if (kind === ResourceKind.WORKFLOW) {
813             resource = await params.services.workflowService.get(params.uuid);
814         } else if (kind === ResourceKind.CONTAINER_REQUEST) {
815             resource = await params.services.containerRequestService.get(params.uuid);
816         } else {
817             throw new Error("loadGroupContentsResource unsupported kind " + kind);
818         }
819         handler = groupContentsHandlers.SHARED(resource);
820     }
821     return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
822 };
823
824 const groupContentsHandlersRecord = {
825     TRASHED: ofType<GroupContentsResource>(),
826     SHARED: ofType<GroupContentsResource>(),
827     OWNED: ofType<GroupContentsResource>(),
828 };
829
830 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
831
832 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
833
834 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
835
836 type MoveableResource = Resource & { name: string };
837
838 type MoveFunc = (
839     data: MoveToFormDialogData,
840     isSecondaryMove?: boolean
841 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
842
843 const secondaryMove: Record<string, MoveFunc> = {
844     [ResourceKind.PROJECT]: moveProject,
845     [ResourceKind.PROCESS]: moveProcess,
846     [ResourceKind.COLLECTION]: moveCollection,
847 };