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