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