UI Improvements
[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 { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
8 import { snackbarActions } from '~/store/snackbar/snackbar-actions';
9 import { loadFavoritePanel } from '~/store/favorite-panel/favorite-panel-action';
10 import { openProjectPanel, projectPanelActions, setIsProjectPanelTrashed } from '~/store/project-panel/project-panel-action';
11 import { activateSidePanelTreeItem, initSidePanelTree, SidePanelTreeCategory, loadSidePanelTreeProjects } from '~/store/side-panel-tree/side-panel-tree-actions';
12 import { loadResource, updateResources } from '~/store/resources/resources-actions';
13 import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-action';
14 import { projectPanelColumns } from '~/views/project-panel/project-panel';
15 import { favoritePanelColumns } from '~/views/favorite-panel/favorite-panel';
16 import { matchRootRoute } from '~/routes/routes';
17 import { setSidePanelBreadcrumbs, setProcessBreadcrumbs, setSharedWithMeBreadcrumbs, setTrashBreadcrumbs, setBreadcrumbs, setGroupDetailsBreadcrumbs, setGroupsBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
18 import { navigateToProject } from '~/store/navigation/navigation-action';
19 import { MoveToFormDialogData } from '~/store/move-to-dialog/move-to-dialog';
20 import { ServiceRepository } from '~/services/services';
21 import { getResource } from '~/store/resources/resources';
22 import { getProjectPanelCurrentUuid } from '~/store/project-panel/project-panel-action';
23 import * as projectCreateActions from '~/store/projects/project-create-actions';
24 import * as projectMoveActions from '~/store/projects/project-move-actions';
25 import * as projectUpdateActions from '~/store/projects/project-update-actions';
26 import * as collectionCreateActions from '~/store/collections/collection-create-actions';
27 import * as collectionCopyActions from '~/store/collections/collection-copy-actions';
28 import * as collectionUpdateActions from '~/store/collections/collection-update-actions';
29 import * as collectionMoveActions from '~/store/collections/collection-move-actions';
30 import * as processesActions from '~/store/processes/processes-actions';
31 import * as processMoveActions from '~/store/processes/process-move-actions';
32 import * as processUpdateActions from '~/store/processes/process-update-actions';
33 import * as processCopyActions from '~/store/processes/process-copy-actions';
34 import { trashPanelColumns } from "~/views/trash-panel/trash-panel";
35 import { loadTrashPanel, trashPanelActions } from "~/store/trash-panel/trash-panel-action";
36 import { initProcessLogsPanel } from '~/store/process-logs-panel/process-logs-panel-actions';
37 import { loadProcessPanel } from '~/store/process-panel/process-panel-actions';
38 import { sharedWithMePanelActions } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
39 import { loadSharedWithMePanel } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
40 import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
41 import { loadWorkflowPanel, workflowPanelActions } from '~/store/workflow-panel/workflow-panel-actions';
42 import { loadSshKeysPanel } from '~/store/auth/auth-action-ssh';
43 import { loadMyAccountPanel } from '~/store/my-account/my-account-panel-actions';
44 import { loadSiteManagerPanel } from '~/store/auth/auth-action-session';
45 import { workflowPanelColumns } from '~/views/workflow-panel/workflow-panel-view';
46 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
47 import { getProgressIndicator } from '~/store/progress-indicator/progress-indicator-reducer';
48 import { ResourceKind, extractUuidKind } from '~/models/resource';
49 import { FilterBuilder } from '~/services/api/filter-builder';
50 import { GroupContentsResource } from '~/services/groups-service/groups-service';
51 import { unionize, ofType, UnionOf, MatchCases } from '~/common/unionize';
52 import { loadRunProcessPanel } from '~/store/run-process-panel/run-process-panel-actions';
53 import { loadCollectionFiles } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
54 import { SnackbarKind } from '~/store/snackbar/snackbar-actions';
55 import { collectionPanelActions } from "~/store/collection-panel/collection-panel-action";
56 import { CollectionResource } from "~/models/collection";
57 import { searchResultsPanelActions, loadSearchResultsPanel } from '~/store/search-results-panel/search-results-panel-actions';
58 import { searchResultsPanelColumns } from '~/views/search-results-panel/search-results-panel-view';
59 import { loadVirtualMachinesPanel } from '~/store/virtual-machines/virtual-machines-actions';
60 import { loadRepositoriesPanel } from '~/store/repositories/repositories-actions';
61 import { loadKeepServicesPanel } from '~/store/keep-services/keep-services-actions';
62 import { loadUsersPanel, userBindedActions } from '~/store/users/users-actions';
63 import { loadLinkPanel, linkPanelActions } from '~/store/link-panel/link-panel-actions';
64 import { loadComputeNodesPanel, computeNodesActions } from '~/store/compute-nodes/compute-nodes-actions';
65 import { linkPanelColumns } from '~/views/link-panel/link-panel-root';
66 import { userPanelColumns } from '~/views/user-panel/user-panel';
67 import { computeNodePanelColumns } from '~/views/compute-node-panel/compute-node-panel-root';
68 import { loadApiClientAuthorizationsPanel } from '~/store/api-client-authorizations/api-client-authorizations-actions';
69 import * as groupPanelActions from '~/store/groups-panel/groups-panel-actions';
70 import { groupsPanelColumns } from '~/views/groups-panel/groups-panel';
71 import * as groupDetailsPanelActions from '~/store/group-details-panel/group-details-panel-actions';
72 import { groupDetailsPanelColumns } from '~/views/group-details-panel/group-details-panel';
73
74 export const WORKBENCH_LOADING_SCREEN = 'workbenchLoadingScreen';
75
76 export const isWorkbenchLoading = (state: RootState) => {
77     const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
78     return progress ? progress.working : false;
79 };
80
81 const handleFirstTimeLoad = (action: any) =>
82     async (dispatch: Dispatch<any>, getState: () => RootState) => {
83         try {
84             await dispatch(action);
85         } finally {
86             if (isWorkbenchLoading(getState())) {
87                 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
88             }
89         }
90     };
91
92 export const loadWorkbench = () =>
93     async (dispatch: Dispatch, getState: () => RootState) => {
94         dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
95         const { auth, router } = getState();
96         const { user } = auth;
97         if (user) {
98             const userResource = await dispatch<any>(loadResource(user.uuid));
99             if (userResource) {
100                 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
101                 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
102                 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
103                 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
104                 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
105                 dispatch(searchResultsPanelActions.SET_COLUMNS({ columns: searchResultsPanelColumns }));
106                 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
107                 dispatch(groupPanelActions.GroupsPanelActions.SET_COLUMNS({ columns: groupsPanelColumns }));
108                 dispatch(groupDetailsPanelActions.GroupDetailsPanelActions.SET_COLUMNS({columns: groupDetailsPanelColumns}));
109                 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
110                 dispatch(computeNodesActions.SET_COLUMNS({ columns: computeNodePanelColumns }));
111                 dispatch<any>(initSidePanelTree());
112                 if (router.location) {
113                     const match = matchRootRoute(router.location.pathname);
114                     if (match) {
115                         dispatch(navigateToProject(userResource.uuid));
116                     }
117                 }
118             } else {
119                 dispatch(userIsNotAuthenticated);
120             }
121         } else {
122             dispatch(userIsNotAuthenticated);
123         }
124     };
125
126 export const loadFavorites = () =>
127     handleFirstTimeLoad(
128         (dispatch: Dispatch) => {
129             dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
130             dispatch<any>(loadFavoritePanel());
131             dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
132         });
133
134 export const loadTrash = () =>
135     handleFirstTimeLoad(
136         (dispatch: Dispatch) => {
137             dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
138             dispatch<any>(loadTrashPanel());
139             dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
140         });
141
142 export const loadProject = (uuid: string) =>
143     handleFirstTimeLoad(
144         async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
145             const userUuid = services.authService.getUuid();
146             dispatch(setIsProjectPanelTrashed(false));
147             if (userUuid) {
148                 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
149                     // Load another users home projects
150                     dispatch(finishLoadingProject(uuid));
151                 } else if (userUuid !== uuid) {
152                     const match = await loadGroupContentsResource({ uuid, userUuid, services });
153                     match({
154                         OWNED: async project => {
155                             await dispatch(activateSidePanelTreeItem(uuid));
156                             dispatch<any>(setSidePanelBreadcrumbs(uuid));
157                             dispatch(finishLoadingProject(project));
158                         },
159                         SHARED: project => {
160                             dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
161                             dispatch(activateSidePanelTreeItem(uuid));
162                             dispatch(finishLoadingProject(project));
163                         },
164                         TRASHED: project => {
165                             dispatch<any>(setTrashBreadcrumbs(uuid));
166                             dispatch(setIsProjectPanelTrashed(true));
167                             dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
168                             dispatch(finishLoadingProject(project));
169                         }
170                     });
171                 } else {
172                     await dispatch(activateSidePanelTreeItem(userUuid));
173                     dispatch<any>(setSidePanelBreadcrumbs(userUuid));
174                     dispatch(finishLoadingProject(userUuid));
175                 }
176             }
177         });
178
179 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) =>
180     async (dispatch: Dispatch) => {
181         const newProject = await dispatch<any>(projectCreateActions.createProject(data));
182         if (newProject) {
183             dispatch(snackbarActions.OPEN_SNACKBAR({
184                 message: "Project has been successfully created.",
185                 hideDuration: 2000,
186                 kind: SnackbarKind.SUCCESS
187             }));
188             await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
189             dispatch<any>(reloadProjectMatchingUuid([newProject.ownerUuid]));
190         }
191     };
192
193 export const moveProject = (data: MoveToFormDialogData) =>
194     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
195         try {
196             const oldProject = getResource(data.uuid)(getState().resources);
197             const oldOwnerUuid = oldProject ? oldProject.ownerUuid : '';
198             const movedProject = await dispatch<any>(projectMoveActions.moveProject(data));
199             if (movedProject) {
200                 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Project has been moved', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
201                 if (oldProject) {
202                     await dispatch<any>(loadSidePanelTreeProjects(oldProject.ownerUuid));
203                 }
204                 dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
205             }
206         } catch (e) {
207             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
208         }
209     };
210
211 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) =>
212     async (dispatch: Dispatch) => {
213         const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
214         if (updatedProject) {
215             dispatch(snackbarActions.OPEN_SNACKBAR({
216                 message: "Project has been successfully updated.",
217                 hideDuration: 2000,
218                 kind: SnackbarKind.SUCCESS
219             }));
220             await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
221             dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
222         }
223     };
224
225 export const loadCollection = (uuid: string) =>
226     handleFirstTimeLoad(
227         async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
228             const userUuid = services.authService.getUuid();
229             if (userUuid) {
230                 const match = await loadGroupContentsResource({ uuid, userUuid, services });
231                 match({
232                     OWNED: async collection => {
233                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
234                         dispatch(updateResources([collection]));
235                         await dispatch(activateSidePanelTreeItem(collection.ownerUuid));
236                         dispatch(setSidePanelBreadcrumbs(collection.ownerUuid));
237                         dispatch(loadCollectionFiles(collection.uuid));
238                     },
239                     SHARED: collection => {
240                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
241                         dispatch(updateResources([collection]));
242                         dispatch<any>(setSharedWithMeBreadcrumbs(collection.ownerUuid));
243                         dispatch(activateSidePanelTreeItem(collection.ownerUuid));
244                         dispatch(loadCollectionFiles(collection.uuid));
245                     },
246                     TRASHED: collection => {
247                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
248                         dispatch(updateResources([collection]));
249                         dispatch(setTrashBreadcrumbs(''));
250                         dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
251                         dispatch(loadCollectionFiles(collection.uuid));
252                     },
253
254                 });
255             }
256         });
257
258 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) =>
259     async (dispatch: Dispatch) => {
260         const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
261         if (collection) {
262             dispatch(snackbarActions.OPEN_SNACKBAR({
263                 message: "Collection has been successfully created.",
264                 hideDuration: 2000,
265                 kind: SnackbarKind.SUCCESS
266             }));
267             dispatch<any>(updateResources([collection]));
268             dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
269         }
270     };
271
272 export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
273     async (dispatch: Dispatch) => {
274         const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
275         if (collection) {
276             dispatch(snackbarActions.OPEN_SNACKBAR({
277                 message: "Collection has been successfully updated.",
278                 hideDuration: 2000,
279                 kind: SnackbarKind.SUCCESS
280             }));
281             dispatch<any>(updateResources([collection]));
282             dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
283         }
284     };
285
286 export const copyCollection = (data: CopyFormDialogData) =>
287     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
288         try {
289             const copyToProject = getResource(data.ownerUuid)(getState().resources);
290             const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
291             if (copyToProject && collection) {
292                 dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
293                 dispatch(snackbarActions.OPEN_SNACKBAR({
294                     message: 'Collection has been copied.',
295                     hideDuration: 3000,
296                     kind: SnackbarKind.SUCCESS,
297                     link: collection.ownerUuid
298                 }));
299             }
300         } catch (e) {
301             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
302         }
303     };
304
305 export const moveCollection = (data: MoveToFormDialogData) =>
306     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
307         try {
308             const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
309             dispatch<any>(updateResources([collection]));
310             dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
311             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been moved.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
312         } catch (e) {
313             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
314         }
315     };
316
317 export const loadProcess = (uuid: string) =>
318     handleFirstTimeLoad(
319         async (dispatch: Dispatch, getState: () => RootState) => {
320             dispatch<any>(loadProcessPanel(uuid));
321             const process = await dispatch<any>(processesActions.loadProcess(uuid));
322             await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
323             dispatch<any>(setProcessBreadcrumbs(uuid));
324             dispatch(loadDetailsPanel(uuid));
325         });
326
327 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) =>
328     async (dispatch: Dispatch) => {
329         try {
330             const process = await dispatch<any>(processUpdateActions.updateProcess(data));
331             if (process) {
332                 dispatch(snackbarActions.OPEN_SNACKBAR({
333                     message: "Process has been successfully updated.",
334                     hideDuration: 2000,
335                     kind: SnackbarKind.SUCCESS
336                 }));
337                 dispatch<any>(updateResources([process]));
338                 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
339             }
340         } catch (e) {
341             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
342         }
343     };
344
345 export const moveProcess = (data: MoveToFormDialogData) =>
346     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
347         try {
348             const process = await dispatch<any>(processMoveActions.moveProcess(data));
349             dispatch<any>(updateResources([process]));
350             dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
351             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been moved.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
352         } catch (e) {
353             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
354         }
355     };
356
357 export const copyProcess = (data: CopyFormDialogData) =>
358     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
359         try {
360             const process = await dispatch<any>(processCopyActions.copyProcess(data));
361             dispatch<any>(updateResources([process]));
362             dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
363             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been copied.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
364         } catch (e) {
365             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
366         }
367     };
368
369 export const loadProcessLog = (uuid: string) =>
370     handleFirstTimeLoad(
371         async (dispatch: Dispatch) => {
372             const process = await dispatch<any>(processesActions.loadProcess(uuid));
373             dispatch<any>(setProcessBreadcrumbs(uuid));
374             dispatch<any>(initProcessLogsPanel(uuid));
375             await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
376         });
377
378 export const resourceIsNotLoaded = (uuid: string) =>
379     snackbarActions.OPEN_SNACKBAR({
380         message: `Resource identified by ${uuid} is not loaded.`,
381         kind: SnackbarKind.ERROR
382     });
383
384 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
385     message: 'User is not authenticated',
386     kind: SnackbarKind.ERROR
387 });
388
389 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
390     message: 'Could not load user',
391     kind: SnackbarKind.ERROR
392 });
393
394 export const reloadProjectMatchingUuid = (matchingUuids: string[]) =>
395     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
396         const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
397         if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
398             dispatch<any>(loadProject(currentProjectPanelUuid));
399         }
400     };
401
402 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
403     dispatch<any>(loadSharedWithMePanel());
404     await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
405     await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
406 });
407
408 export const loadRunProcess = handleFirstTimeLoad(
409     async (dispatch: Dispatch) => {
410         await dispatch<any>(loadRunProcessPanel());
411     }
412 );
413
414 export const loadWorkflow = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
415     dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.WORKFLOWS));
416     await dispatch(loadWorkflowPanel());
417     dispatch(setSidePanelBreadcrumbs(SidePanelTreeCategory.WORKFLOWS));
418 });
419
420 export const loadSearchResults = handleFirstTimeLoad(
421     async (dispatch: Dispatch<any>) => {
422         await dispatch(loadSearchResultsPanel());
423     });
424
425 export const loadLinks = handleFirstTimeLoad(
426     async (dispatch: Dispatch<any>) => {
427         await dispatch(loadLinkPanel());
428     });
429
430 export const loadVirtualMachines = handleFirstTimeLoad(
431     async (dispatch: Dispatch<any>) => {
432         await dispatch(loadVirtualMachinesPanel());
433         dispatch(setBreadcrumbs([{ label: 'Virtual Machines' }]));
434     });
435
436 export const loadRepositories = handleFirstTimeLoad(
437     async (dispatch: Dispatch<any>) => {
438         await dispatch(loadRepositoriesPanel());
439         dispatch(setBreadcrumbs([{ label: 'Repositories' }]));
440     });
441
442 export const loadSshKeys = handleFirstTimeLoad(
443     async (dispatch: Dispatch<any>) => {
444         await dispatch(loadSshKeysPanel());
445     });
446
447 export const loadSiteManager = handleFirstTimeLoad(
448 async (dispatch: Dispatch<any>) => {
449     await dispatch(loadSiteManagerPanel());
450 });
451
452 export const loadMyAccount = handleFirstTimeLoad(
453     (dispatch: Dispatch<any>) => {
454         dispatch(loadMyAccountPanel());
455     });
456
457 export const loadKeepServices = handleFirstTimeLoad(
458     async (dispatch: Dispatch<any>) => {
459         await dispatch(loadKeepServicesPanel());
460     });
461
462 export const loadUsers = handleFirstTimeLoad(
463     async (dispatch: Dispatch<any>) => {
464         await dispatch(loadUsersPanel());
465         dispatch(setBreadcrumbs([{ label: 'Users' }]));
466     });
467
468 export const loadComputeNodes = handleFirstTimeLoad(
469     async (dispatch: Dispatch<any>) => {
470         await dispatch(loadComputeNodesPanel());
471     });
472
473 export const loadApiClientAuthorizations = handleFirstTimeLoad(
474     async (dispatch: Dispatch<any>) => {
475         await dispatch(loadApiClientAuthorizationsPanel());
476     });
477
478 export const loadGroupsPanel = handleFirstTimeLoad(
479     (dispatch: Dispatch<any>) => {
480         dispatch(setGroupsBreadcrumbs());
481         dispatch(groupPanelActions.loadGroupsPanel());
482     });
483
484
485 export const loadGroupDetailsPanel = (groupUuid: string) =>
486     handleFirstTimeLoad(
487         (dispatch: Dispatch<any>) => {
488             dispatch(setGroupDetailsBreadcrumbs(groupUuid));
489             dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
490         });
491
492 const finishLoadingProject = (project: GroupContentsResource | string) =>
493     async (dispatch: Dispatch<any>) => {
494         const uuid = typeof project === 'string' ? project : project.uuid;
495         dispatch(openProjectPanel(uuid));
496         dispatch(loadDetailsPanel(uuid));
497         if (typeof project !== 'string') {
498             dispatch(updateResources([project]));
499         }
500     };
501
502 const loadGroupContentsResource = async (params: {
503     uuid: string,
504     userUuid: string,
505     services: ServiceRepository
506 }) => {
507     const filters = new FilterBuilder()
508         .addEqual('uuid', params.uuid)
509         .getFilters();
510     const { items } = await params.services.groupsService.contents(params.userUuid, {
511         filters,
512         recursive: true,
513         includeTrash: true,
514     });
515     const resource = items.shift();
516     let handler: GroupContentsHandler;
517     if (resource) {
518         handler = (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
519             ? groupContentsHandlers.TRASHED(resource)
520             : groupContentsHandlers.OWNED(resource);
521     } else {
522         const kind = extractUuidKind(params.uuid);
523         let resource: GroupContentsResource;
524         if (kind === ResourceKind.COLLECTION) {
525             resource = await params.services.collectionService.get(params.uuid);
526         } else if (kind === ResourceKind.PROJECT) {
527             resource = await params.services.projectService.get(params.uuid);
528         } else {
529             resource = await params.services.containerRequestService.get(params.uuid);
530         }
531         handler = groupContentsHandlers.SHARED(resource);
532     }
533     return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) =>
534         groupContentsHandlers.match(handler, cases);
535
536 };
537
538 const groupContentsHandlersRecord = {
539     TRASHED: ofType<GroupContentsResource>(),
540     SHARED: ofType<GroupContentsResource>(),
541     OWNED: ofType<GroupContentsResource>(),
542 };
543
544 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
545
546 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;