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