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