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