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