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