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