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