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