15768: fixed project multimove filtering Arvados-DCO-1.1-Signed-off-by: Lisa Knox...
[arvados-workbench2.git] / src / store / workbench / workbench-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from "redux";
6 import { RootState } from "store/store";
7 import { getUserUuid } from "common/getuser";
8 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
9 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
10 import { favoritePanelActions, loadFavoritePanel } from "store/favorite-panel/favorite-panel-action";
11 import {
12     getProjectPanelCurrentUuid,
13     openProjectPanel,
14     projectPanelActions,
15     setIsProjectPanelTrashed,
16 } from "store/project-panel/project-panel-action";
17 import {
18     activateSidePanelTreeItem,
19     initSidePanelTree,
20     loadSidePanelTreeProjects,
21     SidePanelTreeCategory,
22 } from "store/side-panel-tree/side-panel-tree-actions";
23 import { updateResources } from "store/resources/resources-actions";
24 import { projectPanelColumns } from "views/project-panel/project-panel";
25 import { favoritePanelColumns } from "views/favorite-panel/favorite-panel";
26 import { matchRootRoute } from "routes/routes";
27 import {
28     setBreadcrumbs,
29     setGroupDetailsBreadcrumbs,
30     setGroupsBreadcrumbs,
31     setProcessBreadcrumbs,
32     setSharedWithMeBreadcrumbs,
33     setSidePanelBreadcrumbs,
34     setTrashBreadcrumbs,
35     setUsersBreadcrumbs,
36     setMyAccountBreadcrumbs,
37     setUserProfileBreadcrumbs,
38 } from "store/breadcrumbs/breadcrumbs-actions";
39 import { navigateTo, navigateToRootProject } from "store/navigation/navigation-action";
40 import { MoveToFormDialogData } from "store/move-to-dialog/move-to-dialog";
41 import { ServiceRepository } from "services/services";
42 import { getResource } from "store/resources/resources";
43 import * as projectCreateActions from "store/projects/project-create-actions";
44 import * as projectMoveActions from "store/projects/project-move-actions";
45 import * as projectUpdateActions from "store/projects/project-update-actions";
46 import * as collectionCreateActions from "store/collections/collection-create-actions";
47 import * as collectionCopyActions from "store/collections/collection-copy-actions";
48 import * as collectionMoveActions from "store/collections/collection-move-actions";
49 import * as processesActions from "store/processes/processes-actions";
50 import * as processMoveActions from "store/processes/process-move-actions";
51 import * as processUpdateActions from "store/processes/process-update-actions";
52 import * as processCopyActions from "store/processes/process-copy-actions";
53 import { trashPanelColumns } from "views/trash-panel/trash-panel";
54 import { loadTrashPanel, trashPanelActions } from "store/trash-panel/trash-panel-action";
55 import { loadProcessPanel } from "store/process-panel/process-panel-actions";
56 import { loadSharedWithMePanel, sharedWithMePanelActions } from "store/shared-with-me-panel/shared-with-me-panel-actions";
57 import { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
58 import { workflowPanelActions } from "store/workflow-panel/workflow-panel-actions";
59 import { loadSshKeysPanel } from "store/auth/auth-action-ssh";
60 import { loadLinkAccountPanel, linkAccountPanelActions } from "store/link-account-panel/link-account-panel-actions";
61 import { loadSiteManagerPanel } from "store/auth/auth-action-session";
62 import { workflowPanelColumns } from "views/workflow-panel/workflow-panel-view";
63 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
64 import { getProgressIndicator } from "store/progress-indicator/progress-indicator-reducer";
65 import { extractUuidKind, Resource, ResourceKind } from "models/resource";
66 import { FilterBuilder } from "services/api/filter-builder";
67 import { GroupContentsResource } from "services/groups-service/groups-service";
68 import { MatchCases, ofType, unionize, UnionOf } from "common/unionize";
69 import { loadRunProcessPanel } from "store/run-process-panel/run-process-panel-actions";
70 import { collectionPanelActions, loadCollectionPanel } from "store/collection-panel/collection-panel-action";
71 import { CollectionResource } from "models/collection";
72 import { WorkflowResource } from "models/workflow";
73 import { loadSearchResultsPanel, searchResultsPanelActions } from "store/search-results-panel/search-results-panel-actions";
74 import { searchResultsPanelColumns } from "views/search-results-panel/search-results-panel-view";
75 import { loadVirtualMachinesPanel } from "store/virtual-machines/virtual-machines-actions";
76 import { loadRepositoriesPanel } from "store/repositories/repositories-actions";
77 import { loadKeepServicesPanel } from "store/keep-services/keep-services-actions";
78 import { loadUsersPanel, userBindedActions } from "store/users/users-actions";
79 import * as userProfilePanelActions from "store/user-profile/user-profile-actions";
80 import { linkPanelActions, loadLinkPanel } from "store/link-panel/link-panel-actions";
81 import { linkPanelColumns } from "views/link-panel/link-panel-root";
82 import { userPanelColumns } from "views/user-panel/user-panel";
83 import { loadApiClientAuthorizationsPanel, apiClientAuthorizationsActions } from "store/api-client-authorizations/api-client-authorizations-actions";
84 import { apiClientAuthorizationPanelColumns } from "views/api-client-authorization-panel/api-client-authorization-panel-root";
85 import * as groupPanelActions from "store/groups-panel/groups-panel-actions";
86 import { groupsPanelColumns } from "views/groups-panel/groups-panel";
87 import * as groupDetailsPanelActions from "store/group-details-panel/group-details-panel-actions";
88 import { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from "views/group-details-panel/group-details-panel";
89 import { DataTableFetchMode } from "components/data-table/data-table";
90 import { loadPublicFavoritePanel, publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
91 import { publicFavoritePanelColumns } from "views/public-favorites-panel/public-favorites-panel";
92 import {
93     loadCollectionsContentAddressPanel,
94     collectionsContentAddressActions,
95 } from "store/collections-content-address-panel/collections-content-address-panel-actions";
96 import { collectionContentAddressPanelColumns } from "views/collection-content-address-panel/collection-content-address-panel";
97 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
98 import { subprocessPanelColumns } from "views/subprocess-panel/subprocess-panel-root";
99 import { loadAllProcessesPanel, allProcessesPanelActions } from "../all-processes-panel/all-processes-panel-action";
100 import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
101 import { AdminMenuIcon } from "components/icon/icon";
102 import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
103 import { selectedToArray } 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         const originalProject = getResource(projectUuid)(getState().resources) as Resource & { name: string };
294         if (originalProject.kind === ResourceKind.PROJECT) {
295             try {
296                 const oldProject: MoveToFormDialogData = { name: originalProject.name, uuid: originalProject.uuid, ownerUuid: data.ownerUuid };
297                 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
298                 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
299                 if (movedProject) {
300                     dispatch(
301                         snackbarActions.OPEN_SNACKBAR({
302                             message: "Project has been moved",
303                             hideDuration: 2000,
304                             kind: SnackbarKind.SUCCESS,
305                         })
306                     );
307                     await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
308                 }
309             } catch (e) {
310                 dispatch(
311                     snackbarActions.OPEN_SNACKBAR({
312                         message: e.message,
313                         hideDuration: 2000,
314                         kind: SnackbarKind.ERROR,
315                     })
316                 );
317             }
318         }
319     }
320     if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
321     await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
322 };
323
324 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
325     const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
326     if (updatedProject) {
327         dispatch(
328             snackbarActions.OPEN_SNACKBAR({
329                 message: "Project has been successfully updated.",
330                 hideDuration: 2000,
331                 kind: SnackbarKind.SUCCESS,
332             })
333         );
334         await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
335         dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
336     }
337 };
338
339 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
340     const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
341     if (updatedGroup) {
342         dispatch(
343             snackbarActions.OPEN_SNACKBAR({
344                 message: "Group has been successfully updated.",
345                 hideDuration: 2000,
346                 kind: SnackbarKind.SUCCESS,
347             })
348         );
349         await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
350         dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
351     }
352 };
353
354 export const loadCollection = (uuid: string) =>
355     handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
356         const userUuid = getUserUuid(getState());
357         if (userUuid) {
358             const match = await loadGroupContentsResource({
359                 uuid,
360                 userUuid,
361                 services,
362             });
363             let collection: CollectionResource | undefined;
364             let breadcrumbfunc:
365                 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
366                 | undefined;
367             let sidepanel: string | undefined;
368             match({
369                 OWNED: thecollection => {
370                     collection = thecollection as CollectionResource;
371                     sidepanel = collection.ownerUuid;
372                     breadcrumbfunc = setSidePanelBreadcrumbs;
373                 },
374                 SHARED: thecollection => {
375                     collection = thecollection as CollectionResource;
376                     sidepanel = collection.ownerUuid;
377                     breadcrumbfunc = setSharedWithMeBreadcrumbs;
378                 },
379                 TRASHED: thecollection => {
380                     collection = thecollection as CollectionResource;
381                     sidepanel = SidePanelTreeCategory.TRASH;
382                     breadcrumbfunc = () => setTrashBreadcrumbs("");
383                 },
384             });
385             if (collection && breadcrumbfunc && sidepanel) {
386                 dispatch(updateResources([collection]));
387                 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
388                 dispatch(collectionPanelActions.SET_COLLECTION(collection));
389                 await dispatch(activateSidePanelTreeItem(sidepanel));
390                 dispatch(breadcrumbfunc(collection.ownerUuid));
391                 dispatch(loadCollectionPanel(collection.uuid));
392             }
393         }
394     });
395
396 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
397     const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
398     if (collection) {
399         dispatch(
400             snackbarActions.OPEN_SNACKBAR({
401                 message: "Collection has been successfully created.",
402                 hideDuration: 2000,
403                 kind: SnackbarKind.SUCCESS,
404             })
405         );
406         dispatch<any>(updateResources([collection]));
407         dispatch<any>(navigateTo(collection.uuid));
408     }
409 };
410
411 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
412     try {
413         const copyToProject = getResource(data.ownerUuid)(getState().resources);
414         const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
415         if (copyToProject && collection) {
416             dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
417             dispatch(
418                 snackbarActions.OPEN_SNACKBAR({
419                     message: "Collection has been copied.",
420                     hideDuration: 3000,
421                     kind: SnackbarKind.SUCCESS,
422                     link: collection.ownerUuid,
423                 })
424             );
425         }
426     } catch (e) {
427         dispatch(
428             snackbarActions.OPEN_SNACKBAR({
429                 message: e.message,
430                 hideDuration: 2000,
431                 kind: SnackbarKind.ERROR,
432             })
433         );
434     }
435 };
436
437 export const moveCollection = (data: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
438     try {
439         const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
440         dispatch<any>(updateResources([collection]));
441         dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
442         dispatch(
443             snackbarActions.OPEN_SNACKBAR({
444                 message: "Collection has been moved.",
445                 hideDuration: 2000,
446                 kind: SnackbarKind.SUCCESS,
447             })
448         );
449     } catch (e) {
450         dispatch(
451             snackbarActions.OPEN_SNACKBAR({
452                 message: e.message,
453                 hideDuration: 2000,
454                 kind: SnackbarKind.ERROR,
455             })
456         );
457     }
458 };
459
460 export const loadProcess = (uuid: string) =>
461     handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
462         dispatch<any>(loadProcessPanel(uuid));
463         const process = await dispatch<any>(processesActions.loadProcess(uuid));
464         if (process) {
465             await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
466             await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
467             dispatch<any>(setProcessBreadcrumbs(uuid));
468             dispatch<any>(loadDetailsPanel(uuid));
469         }
470     });
471
472 export const loadRegisteredWorkflow = (uuid: string) =>
473     handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
474         const userUuid = getUserUuid(getState());
475         if (userUuid) {
476             const match = await loadGroupContentsResource({
477                 uuid,
478                 userUuid,
479                 services,
480             });
481             let workflow: WorkflowResource | undefined;
482             let breadcrumbfunc:
483                 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
484                 | undefined;
485             match({
486                 OWNED: async theworkflow => {
487                     workflow = theworkflow as WorkflowResource;
488                     breadcrumbfunc = setSidePanelBreadcrumbs;
489                 },
490                 SHARED: async theworkflow => {
491                     workflow = theworkflow as WorkflowResource;
492                     breadcrumbfunc = setSharedWithMeBreadcrumbs;
493                 },
494                 TRASHED: () => {},
495             });
496             if (workflow && breadcrumbfunc) {
497                 dispatch(updateResources([workflow]));
498                 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
499                 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
500                 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
501             }
502         }
503     });
504
505 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
506     try {
507         const process = await dispatch<any>(processUpdateActions.updateProcess(data));
508         if (process) {
509             dispatch(
510                 snackbarActions.OPEN_SNACKBAR({
511                     message: "Process has been successfully updated.",
512                     hideDuration: 2000,
513                     kind: SnackbarKind.SUCCESS,
514                 })
515             );
516             dispatch<any>(updateResources([process]));
517             dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
518         }
519     } catch (e) {
520         dispatch(
521             snackbarActions.OPEN_SNACKBAR({
522                 message: e.message,
523                 hideDuration: 2000,
524                 kind: SnackbarKind.ERROR,
525             })
526         );
527     }
528 };
529
530 export const moveProcess = (data: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
531     console.log("PROCESSS_DATA: ", data);
532     try {
533         const process = await dispatch<any>(processMoveActions.moveProcess(data));
534         dispatch<any>(updateResources([process]));
535         dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
536         dispatch(
537             snackbarActions.OPEN_SNACKBAR({
538                 message: "Process has been moved.",
539                 hideDuration: 2000,
540                 kind: SnackbarKind.SUCCESS,
541             })
542         );
543     } catch (e) {
544         dispatch(
545             snackbarActions.OPEN_SNACKBAR({
546                 message: e.message,
547                 hideDuration: 2000,
548                 kind: SnackbarKind.ERROR,
549             })
550         );
551     }
552 };
553
554 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
555     try {
556         const process = await dispatch<any>(processCopyActions.copyProcess(data));
557         dispatch<any>(updateResources([process]));
558         dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
559         dispatch(
560             snackbarActions.OPEN_SNACKBAR({
561                 message: "Process has been copied.",
562                 hideDuration: 2000,
563                 kind: SnackbarKind.SUCCESS,
564             })
565         );
566         dispatch<any>(navigateTo(process.uuid));
567     } catch (e) {
568         dispatch(
569             snackbarActions.OPEN_SNACKBAR({
570                 message: e.message,
571                 hideDuration: 2000,
572                 kind: SnackbarKind.ERROR,
573             })
574         );
575     }
576 };
577
578 export const resourceIsNotLoaded = (uuid: string) =>
579     snackbarActions.OPEN_SNACKBAR({
580         message: `Resource identified by ${uuid} is not loaded.`,
581         kind: SnackbarKind.ERROR,
582     });
583
584 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
585     message: "User is not authenticated",
586     kind: SnackbarKind.ERROR,
587 });
588
589 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
590     message: "Could not load user",
591     kind: SnackbarKind.ERROR,
592 });
593
594 export const reloadProjectMatchingUuid =
595     (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
596         const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
597         if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
598             dispatch<any>(loadProject(currentProjectPanelUuid));
599         }
600     };
601
602 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
603     dispatch<any>(loadSharedWithMePanel());
604     await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
605     await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
606 });
607
608 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
609     await dispatch<any>(loadRunProcessPanel());
610 });
611
612 export const loadPublicFavorites = () =>
613     handleFirstTimeLoad((dispatch: Dispatch) => {
614         dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
615         dispatch<any>(loadPublicFavoritePanel());
616         dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
617     });
618
619 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
620     await dispatch(loadSearchResultsPanel());
621 });
622
623 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
624     await dispatch(loadLinkPanel());
625 });
626
627 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
628     await dispatch(loadVirtualMachinesPanel());
629     dispatch(setBreadcrumbs([{ label: "Virtual Machines" }]));
630 });
631
632 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
633     await dispatch(loadVirtualMachinesPanel());
634     dispatch(setBreadcrumbs([{ label: "Virtual Machines Admin", icon: AdminMenuIcon }]));
635 });
636
637 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
638     await dispatch(loadRepositoriesPanel());
639     dispatch(setBreadcrumbs([{ label: "Repositories" }]));
640 });
641
642 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
643     await dispatch(loadSshKeysPanel());
644 });
645
646 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
647     await dispatch(loadSiteManagerPanel());
648 });
649
650 export const loadUserProfile = (userUuid?: string) =>
651     handleFirstTimeLoad((dispatch: Dispatch<any>) => {
652         if (userUuid) {
653             dispatch(setUserProfileBreadcrumbs(userUuid));
654             dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
655         } else {
656             dispatch(setMyAccountBreadcrumbs());
657             dispatch(userProfilePanelActions.loadUserProfilePanel());
658         }
659     });
660
661 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
662     dispatch(loadLinkAccountPanel());
663 });
664
665 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
666     await dispatch(loadKeepServicesPanel());
667 });
668
669 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
670     await dispatch(loadUsersPanel());
671     dispatch(setUsersBreadcrumbs());
672 });
673
674 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
675     await dispatch(loadApiClientAuthorizationsPanel());
676 });
677
678 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
679     dispatch(setGroupsBreadcrumbs());
680     dispatch(groupPanelActions.loadGroupsPanel());
681 });
682
683 export const loadGroupDetailsPanel = (groupUuid: string) =>
684     handleFirstTimeLoad((dispatch: Dispatch<any>) => {
685         dispatch(setGroupDetailsBreadcrumbs(groupUuid));
686         dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
687     });
688
689 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
690     const uuid = typeof project === "string" ? project : project.uuid;
691     dispatch(openProjectPanel(uuid));
692     dispatch(loadDetailsPanel(uuid));
693     if (typeof project !== "string") {
694         dispatch(updateResources([project]));
695     }
696 };
697
698 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
699     const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
700     const { items } = await params.services.groupsService.contents(params.userUuid, {
701         filters,
702         recursive: true,
703         includeTrash: true,
704     });
705     const resource = items.shift();
706     let handler: GroupContentsHandler;
707     if (resource) {
708         handler =
709             (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
710                 ? groupContentsHandlers.TRASHED(resource)
711                 : groupContentsHandlers.OWNED(resource);
712     } else {
713         const kind = extractUuidKind(params.uuid);
714         let resource: GroupContentsResource;
715         if (kind === ResourceKind.COLLECTION) {
716             resource = await params.services.collectionService.get(params.uuid);
717         } else if (kind === ResourceKind.PROJECT) {
718             resource = await params.services.projectService.get(params.uuid);
719         } else if (kind === ResourceKind.WORKFLOW) {
720             resource = await params.services.workflowService.get(params.uuid);
721         } else if (kind === ResourceKind.CONTAINER_REQUEST) {
722             resource = await params.services.containerRequestService.get(params.uuid);
723         } else {
724             throw new Error("loadGroupContentsResource unsupported kind " + kind);
725         }
726         handler = groupContentsHandlers.SHARED(resource);
727     }
728     return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
729 };
730
731 const groupContentsHandlersRecord = {
732     TRASHED: ofType<GroupContentsResource>(),
733     SHARED: ofType<GroupContentsResource>(),
734     OWNED: ofType<GroupContentsResource>(),
735 };
736
737 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
738
739 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;