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