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