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