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