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