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