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