15768: project multimove works Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox...
[arvados.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, 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 } from "components/multiselectToolbar/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 = (data: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
282     const projectsToMove: string[] = selectedToArray(getState().multiselect.checkedList);
283     //if no items in checkedlist, default to normal context menu behavior
284     if (!projectsToMove.length) projectsToMove.push(data.uuid);
285     const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
286     const destinationUuid = data.ownerUuid;
287
288     for (const projectUuid of projectsToMove) {
289         await moveSingleProject(projectUuid);
290     }
291
292     async function moveSingleProject(projectUuid) {
293         try {
294             const originalProject = getResource(projectUuid)(getState().resources);
295             const oldProject = { ...originalProject, ownerUuid: data.ownerUuid } as any;
296             const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
297             const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
298             if (movedProject) {
299                 dispatch(
300                     snackbarActions.OPEN_SNACKBAR({
301                         message: "Project has been moved",
302                         hideDuration: 2000,
303                         kind: SnackbarKind.SUCCESS,
304                     })
305                 );
306                 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
307             }
308         } catch (e) {
309             dispatch(
310                 snackbarActions.OPEN_SNACKBAR({
311                     message: e.message,
312                     hideDuration: 2000,
313                     kind: SnackbarKind.ERROR,
314                 })
315             );
316         }
317     }
318     if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
319     await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
320 };
321
322 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
323     const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
324     if (updatedProject) {
325         dispatch(
326             snackbarActions.OPEN_SNACKBAR({
327                 message: "Project has been successfully updated.",
328                 hideDuration: 2000,
329                 kind: SnackbarKind.SUCCESS,
330             })
331         );
332         await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
333         dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
334     }
335 };
336
337 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
338     const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
339     if (updatedGroup) {
340         dispatch(
341             snackbarActions.OPEN_SNACKBAR({
342                 message: "Group has been successfully updated.",
343                 hideDuration: 2000,
344                 kind: SnackbarKind.SUCCESS,
345             })
346         );
347         await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
348         dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
349     }
350 };
351
352 export const loadCollection = (uuid: string) =>
353     handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
354         const userUuid = getUserUuid(getState());
355         if (userUuid) {
356             const match = await loadGroupContentsResource({
357                 uuid,
358                 userUuid,
359                 services,
360             });
361             let collection: CollectionResource | undefined;
362             let breadcrumbfunc:
363                 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
364                 | undefined;
365             let sidepanel: string | undefined;
366             match({
367                 OWNED: thecollection => {
368                     collection = thecollection as CollectionResource;
369                     sidepanel = collection.ownerUuid;
370                     breadcrumbfunc = setSidePanelBreadcrumbs;
371                 },
372                 SHARED: thecollection => {
373                     collection = thecollection as CollectionResource;
374                     sidepanel = collection.ownerUuid;
375                     breadcrumbfunc = setSharedWithMeBreadcrumbs;
376                 },
377                 TRASHED: thecollection => {
378                     collection = thecollection as CollectionResource;
379                     sidepanel = SidePanelTreeCategory.TRASH;
380                     breadcrumbfunc = () => setTrashBreadcrumbs("");
381                 },
382             });
383             if (collection && breadcrumbfunc && sidepanel) {
384                 dispatch(updateResources([collection]));
385                 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
386                 dispatch(collectionPanelActions.SET_COLLECTION(collection));
387                 await dispatch(activateSidePanelTreeItem(sidepanel));
388                 dispatch(breadcrumbfunc(collection.ownerUuid));
389                 dispatch(loadCollectionPanel(collection.uuid));
390             }
391         }
392     });
393
394 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
395     const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
396     if (collection) {
397         dispatch(
398             snackbarActions.OPEN_SNACKBAR({
399                 message: "Collection has been successfully created.",
400                 hideDuration: 2000,
401                 kind: SnackbarKind.SUCCESS,
402             })
403         );
404         dispatch<any>(updateResources([collection]));
405         dispatch<any>(navigateTo(collection.uuid));
406     }
407 };
408
409 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
410     try {
411         const copyToProject = getResource(data.ownerUuid)(getState().resources);
412         const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
413         if (copyToProject && collection) {
414             dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
415             dispatch(
416                 snackbarActions.OPEN_SNACKBAR({
417                     message: "Collection has been copied.",
418                     hideDuration: 3000,
419                     kind: SnackbarKind.SUCCESS,
420                     link: collection.ownerUuid,
421                 })
422             );
423         }
424     } catch (e) {
425         dispatch(
426             snackbarActions.OPEN_SNACKBAR({
427                 message: e.message,
428                 hideDuration: 2000,
429                 kind: SnackbarKind.ERROR,
430             })
431         );
432     }
433 };
434
435 export const moveCollection = (data: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
436     try {
437         const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
438         dispatch<any>(updateResources([collection]));
439         dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
440         dispatch(
441             snackbarActions.OPEN_SNACKBAR({
442                 message: "Collection has been moved.",
443                 hideDuration: 2000,
444                 kind: SnackbarKind.SUCCESS,
445             })
446         );
447     } catch (e) {
448         dispatch(
449             snackbarActions.OPEN_SNACKBAR({
450                 message: e.message,
451                 hideDuration: 2000,
452                 kind: SnackbarKind.ERROR,
453             })
454         );
455     }
456 };
457
458 export const loadProcess = (uuid: string) =>
459     handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
460         dispatch<any>(loadProcessPanel(uuid));
461         const process = await dispatch<any>(processesActions.loadProcess(uuid));
462         if (process) {
463             await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
464             await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
465             dispatch<any>(setProcessBreadcrumbs(uuid));
466             dispatch<any>(loadDetailsPanel(uuid));
467         }
468     });
469
470 export const loadRegisteredWorkflow = (uuid: string) =>
471     handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
472         const userUuid = getUserUuid(getState());
473         if (userUuid) {
474             const match = await loadGroupContentsResource({
475                 uuid,
476                 userUuid,
477                 services,
478             });
479             let workflow: WorkflowResource | undefined;
480             let breadcrumbfunc:
481                 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
482                 | undefined;
483             match({
484                 OWNED: async theworkflow => {
485                     workflow = theworkflow as WorkflowResource;
486                     breadcrumbfunc = setSidePanelBreadcrumbs;
487                 },
488                 SHARED: async theworkflow => {
489                     workflow = theworkflow as WorkflowResource;
490                     breadcrumbfunc = setSharedWithMeBreadcrumbs;
491                 },
492                 TRASHED: () => {},
493             });
494             if (workflow && breadcrumbfunc) {
495                 dispatch(updateResources([workflow]));
496                 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
497                 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
498                 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
499             }
500         }
501     });
502
503 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
504     try {
505         const process = await dispatch<any>(processUpdateActions.updateProcess(data));
506         if (process) {
507             dispatch(
508                 snackbarActions.OPEN_SNACKBAR({
509                     message: "Process has been successfully updated.",
510                     hideDuration: 2000,
511                     kind: SnackbarKind.SUCCESS,
512                 })
513             );
514             dispatch<any>(updateResources([process]));
515             dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
516         }
517     } catch (e) {
518         dispatch(
519             snackbarActions.OPEN_SNACKBAR({
520                 message: e.message,
521                 hideDuration: 2000,
522                 kind: SnackbarKind.ERROR,
523             })
524         );
525     }
526 };
527
528 export const moveProcess = (data: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
529     try {
530         const process = await dispatch<any>(processMoveActions.moveProcess(data));
531         dispatch<any>(updateResources([process]));
532         dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
533         dispatch(
534             snackbarActions.OPEN_SNACKBAR({
535                 message: "Process has been moved.",
536                 hideDuration: 2000,
537                 kind: SnackbarKind.SUCCESS,
538             })
539         );
540     } catch (e) {
541         dispatch(
542             snackbarActions.OPEN_SNACKBAR({
543                 message: e.message,
544                 hideDuration: 2000,
545                 kind: SnackbarKind.ERROR,
546             })
547         );
548     }
549 };
550
551 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
552     try {
553         const process = await dispatch<any>(processCopyActions.copyProcess(data));
554         dispatch<any>(updateResources([process]));
555         dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
556         dispatch(
557             snackbarActions.OPEN_SNACKBAR({
558                 message: "Process has been copied.",
559                 hideDuration: 2000,
560                 kind: SnackbarKind.SUCCESS,
561             })
562         );
563         dispatch<any>(navigateTo(process.uuid));
564     } catch (e) {
565         dispatch(
566             snackbarActions.OPEN_SNACKBAR({
567                 message: e.message,
568                 hideDuration: 2000,
569                 kind: SnackbarKind.ERROR,
570             })
571         );
572     }
573 };
574
575 export const resourceIsNotLoaded = (uuid: string) =>
576     snackbarActions.OPEN_SNACKBAR({
577         message: `Resource identified by ${uuid} is not loaded.`,
578         kind: SnackbarKind.ERROR,
579     });
580
581 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
582     message: "User is not authenticated",
583     kind: SnackbarKind.ERROR,
584 });
585
586 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
587     message: "Could not load user",
588     kind: SnackbarKind.ERROR,
589 });
590
591 export const reloadProjectMatchingUuid =
592     (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
593         const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
594         if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
595             dispatch<any>(loadProject(currentProjectPanelUuid));
596         }
597     };
598
599 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
600     dispatch<any>(loadSharedWithMePanel());
601     await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
602     await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
603 });
604
605 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
606     await dispatch<any>(loadRunProcessPanel());
607 });
608
609 export const loadPublicFavorites = () =>
610     handleFirstTimeLoad((dispatch: Dispatch) => {
611         dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
612         dispatch<any>(loadPublicFavoritePanel());
613         dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
614     });
615
616 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
617     await dispatch(loadSearchResultsPanel());
618 });
619
620 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
621     await dispatch(loadLinkPanel());
622 });
623
624 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
625     await dispatch(loadVirtualMachinesPanel());
626     dispatch(setBreadcrumbs([{ label: "Virtual Machines" }]));
627 });
628
629 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
630     await dispatch(loadVirtualMachinesPanel());
631     dispatch(setBreadcrumbs([{ label: "Virtual Machines Admin", icon: AdminMenuIcon }]));
632 });
633
634 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
635     await dispatch(loadRepositoriesPanel());
636     dispatch(setBreadcrumbs([{ label: "Repositories" }]));
637 });
638
639 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
640     await dispatch(loadSshKeysPanel());
641 });
642
643 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
644     await dispatch(loadSiteManagerPanel());
645 });
646
647 export const loadUserProfile = (userUuid?: string) =>
648     handleFirstTimeLoad((dispatch: Dispatch<any>) => {
649         if (userUuid) {
650             dispatch(setUserProfileBreadcrumbs(userUuid));
651             dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
652         } else {
653             dispatch(setMyAccountBreadcrumbs());
654             dispatch(userProfilePanelActions.loadUserProfilePanel());
655         }
656     });
657
658 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
659     dispatch(loadLinkAccountPanel());
660 });
661
662 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
663     await dispatch(loadKeepServicesPanel());
664 });
665
666 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
667     await dispatch(loadUsersPanel());
668     dispatch(setUsersBreadcrumbs());
669 });
670
671 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
672     await dispatch(loadApiClientAuthorizationsPanel());
673 });
674
675 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
676     dispatch(setGroupsBreadcrumbs());
677     dispatch(groupPanelActions.loadGroupsPanel());
678 });
679
680 export const loadGroupDetailsPanel = (groupUuid: string) =>
681     handleFirstTimeLoad((dispatch: Dispatch<any>) => {
682         dispatch(setGroupDetailsBreadcrumbs(groupUuid));
683         dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
684     });
685
686 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
687     const uuid = typeof project === "string" ? project : project.uuid;
688     dispatch(openProjectPanel(uuid));
689     dispatch(loadDetailsPanel(uuid));
690     if (typeof project !== "string") {
691         dispatch(updateResources([project]));
692     }
693 };
694
695 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
696     const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
697     const { items } = await params.services.groupsService.contents(params.userUuid, {
698         filters,
699         recursive: true,
700         includeTrash: true,
701     });
702     const resource = items.shift();
703     let handler: GroupContentsHandler;
704     if (resource) {
705         handler =
706             (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
707                 ? groupContentsHandlers.TRASHED(resource)
708                 : groupContentsHandlers.OWNED(resource);
709     } else {
710         const kind = extractUuidKind(params.uuid);
711         let resource: GroupContentsResource;
712         if (kind === ResourceKind.COLLECTION) {
713             resource = await params.services.collectionService.get(params.uuid);
714         } else if (kind === ResourceKind.PROJECT) {
715             resource = await params.services.projectService.get(params.uuid);
716         } else if (kind === ResourceKind.WORKFLOW) {
717             resource = await params.services.workflowService.get(params.uuid);
718         } else if (kind === ResourceKind.CONTAINER_REQUEST) {
719             resource = await params.services.containerRequestService.get(params.uuid);
720         } else {
721             throw new Error("loadGroupContentsResource unsupported kind " + kind);
722         }
723         handler = groupContentsHandlers.SHARED(resource);
724     }
725     return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
726 };
727
728 const groupContentsHandlersRecord = {
729     TRASHED: ofType<GroupContentsResource>(),
730     SHARED: ofType<GroupContentsResource>(),
731     OWNED: ofType<GroupContentsResource>(),
732 };
733
734 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
735
736 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;