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