19231: Add smaller page sizes (10 and 20 items) to load faster
[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     setUsersBreadcrumbs,
36     setMyAccountBreadcrumbs,
37     setUserProfileBreadcrumbs,
38 } from 'store/breadcrumbs/breadcrumbs-actions';
39 import { navigateTo, navigateToRootProject } from 'store/navigation/navigation-action';
40 import { MoveToFormDialogData } from 'store/move-to-dialog/move-to-dialog';
41 import { ServiceRepository } from 'services/services';
42 import { getResource } from 'store/resources/resources';
43 import * as projectCreateActions from 'store/projects/project-create-actions';
44 import * as projectMoveActions from 'store/projects/project-move-actions';
45 import * as projectUpdateActions from 'store/projects/project-update-actions';
46 import * as collectionCreateActions from 'store/collections/collection-create-actions';
47 import * as collectionCopyActions from 'store/collections/collection-copy-actions';
48 import * as collectionMoveActions from 'store/collections/collection-move-actions';
49 import * as processesActions from 'store/processes/processes-actions';
50 import * as processMoveActions from 'store/processes/process-move-actions';
51 import * as processUpdateActions from 'store/processes/process-update-actions';
52 import * as processCopyActions from 'store/processes/process-copy-actions';
53 import { trashPanelColumns } from "views/trash-panel/trash-panel";
54 import { loadTrashPanel, trashPanelActions } from "store/trash-panel/trash-panel-action";
55 import { loadProcessPanel } from 'store/process-panel/process-panel-actions';
56 import {
57     loadSharedWithMePanel,
58     sharedWithMePanelActions
59 } from 'store/shared-with-me-panel/shared-with-me-panel-actions';
60 import { CopyFormDialogData } from 'store/copy-dialog/copy-dialog';
61 import { workflowPanelActions } from 'store/workflow-panel/workflow-panel-actions';
62 import { loadSshKeysPanel } from 'store/auth/auth-action-ssh';
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 * as userProfilePanelActions from 'store/user-profile/user-profile-actions';
85 import { linkPanelActions, loadLinkPanel } from 'store/link-panel/link-panel-actions';
86 import { linkPanelColumns } from 'views/link-panel/link-panel-root';
87 import { userPanelColumns } from 'views/user-panel/user-panel';
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 { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from 'views/group-details-panel/group-details-panel';
94 import { DataTableFetchMode } from "components/data-table/data-table";
95 import { loadPublicFavoritePanel, publicFavoritePanelActions } from 'store/public-favorites-panel/public-favorites-action';
96 import { publicFavoritePanelColumns } from 'views/public-favorites-panel/public-favorites-panel';
97 import { loadCollectionsContentAddressPanel, collectionsContentAddressActions } from 'store/collections-content-address-panel/collections-content-address-panel-actions';
98 import { collectionContentAddressPanelColumns } from 'views/collection-content-address-panel/collection-content-address-panel';
99 import { subprocessPanelActions } from 'store/subprocess-panel/subprocess-panel-actions';
100 import { subprocessPanelColumns } from 'views/subprocess-panel/subprocess-panel-root';
101 import { loadAllProcessesPanel, allProcessesPanelActions } from '../all-processes-panel/all-processes-panel-action';
102 import { allProcessesPanelColumns } from 'views/all-processes-panel/all-processes-panel';
103 import { AdminMenuIcon } from 'components/icon/icon';
104 import { userProfileGroupsColumns } from 'views/user-profile-panel/user-profile-panel-root';
105
106 export const WORKBENCH_LOADING_SCREEN = 'workbenchLoadingScreen';
107
108 export const isWorkbenchLoading = (state: RootState) => {
109     const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
110     return progress ? progress.working : false;
111 };
112
113 export const handleFirstTimeLoad = (action: any) =>
114     async (dispatch: Dispatch<any>, getState: () => RootState) => {
115         try {
116             await dispatch(action);
117         } finally {
118             if (isWorkbenchLoading(getState())) {
119                 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
120             }
121         }
122     };
123
124 export const loadWorkbench = () =>
125     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
126         dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
127         const { auth, router } = getState();
128         const { user } = auth;
129         if (user) {
130             dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
131             dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
132             dispatch(allProcessesPanelActions.SET_COLUMNS({ columns: allProcessesPanelColumns }));
133             dispatch(publicFavoritePanelActions.SET_COLUMNS({ columns: publicFavoritePanelColumns }));
134             dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
135             dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
136             dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
137             dispatch(searchResultsPanelActions.SET_FETCH_MODE({ fetchMode: DataTableFetchMode.INFINITE }));
138             dispatch(searchResultsPanelActions.SET_COLUMNS({ columns: searchResultsPanelColumns }));
139             dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
140             dispatch(groupPanelActions.GroupsPanelActions.SET_COLUMNS({ columns: groupsPanelColumns }));
141             dispatch(groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({ columns: groupDetailsMembersPanelColumns }));
142             dispatch(groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({ columns: groupDetailsPermissionsPanelColumns }));
143             dispatch(userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({ columns: userProfileGroupsColumns }));
144             dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
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>(navigateToRootProject);
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                 return;
202             }
203             if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
204                 // Load another users home projects
205                 dispatch(finishLoadingProject(uuid));
206             } else if (userUuid !== uuid) {
207                 await dispatch(finishLoadingProject(uuid));
208                 const match = await loadGroupContentsResource({ uuid, userUuid, services });
209                 match({
210                     OWNED: async () => {
211                         await dispatch(activateSidePanelTreeItem(uuid));
212                         dispatch<any>(setSidePanelBreadcrumbs(uuid));
213                     },
214                     SHARED: async () => {
215                         await dispatch(activateSidePanelTreeItem(uuid));
216                         dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
217                     },
218                     TRASHED: async () => {
219                         await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
220                         dispatch<any>(setTrashBreadcrumbs(uuid));
221                         dispatch(setIsProjectPanelTrashed(true));
222                     }
223                 });
224             } else {
225                 await dispatch(finishLoadingProject(userUuid));
226                 await dispatch(activateSidePanelTreeItem(userUuid));
227                 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
228             }
229         });
230
231 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) =>
232     async (dispatch: Dispatch) => {
233         const newProject = await dispatch<any>(projectCreateActions.createProject(data));
234         if (newProject) {
235             dispatch(snackbarActions.OPEN_SNACKBAR({
236                 message: "Project has been successfully created.",
237                 hideDuration: 2000,
238                 kind: SnackbarKind.SUCCESS
239             }));
240             await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
241             dispatch<any>(navigateTo(newProject.uuid));
242         }
243     };
244
245 export const moveProject = (data: MoveToFormDialogData) =>
246     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
247         try {
248             const oldProject = getResource(data.uuid)(getState().resources);
249             const oldOwnerUuid = oldProject ? oldProject.ownerUuid : '';
250             const movedProject = await dispatch<any>(projectMoveActions.moveProject(data));
251             if (movedProject) {
252                 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Project has been moved', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
253                 if (oldProject) {
254                     await dispatch<any>(loadSidePanelTreeProjects(oldProject.ownerUuid));
255                 }
256                 dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
257             }
258         } catch (e) {
259             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
260         }
261     };
262
263 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) =>
264     async (dispatch: Dispatch) => {
265         const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
266         if (updatedProject) {
267             dispatch(snackbarActions.OPEN_SNACKBAR({
268                 message: "Project has been successfully updated.",
269                 hideDuration: 2000,
270                 kind: SnackbarKind.SUCCESS
271             }));
272             await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
273             dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
274         }
275     };
276
277 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) =>
278     async (dispatch: Dispatch) => {
279         const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
280         if (updatedGroup) {
281             dispatch(snackbarActions.OPEN_SNACKBAR({
282                 message: "Group has been successfully updated.",
283                 hideDuration: 2000,
284                 kind: SnackbarKind.SUCCESS
285             }));
286             await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
287             dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
288         }
289     };
290
291 export const loadCollection = (uuid: string) =>
292     handleFirstTimeLoad(
293         async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
294             const userUuid = getUserUuid(getState());
295             if (userUuid) {
296                 const match = await loadGroupContentsResource({ uuid, userUuid, services });
297                 match({
298                     OWNED: collection => {
299                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
300                         dispatch(updateResources([collection]));
301                         dispatch(activateSidePanelTreeItem(collection.ownerUuid));
302                         dispatch(setSidePanelBreadcrumbs(collection.ownerUuid));
303                         dispatch(loadCollectionPanel(collection.uuid));
304                     },
305                     SHARED: collection => {
306                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
307                         dispatch(updateResources([collection]));
308                         dispatch<any>(setSharedWithMeBreadcrumbs(collection.ownerUuid));
309                         dispatch(activateSidePanelTreeItem(collection.ownerUuid));
310                         dispatch(loadCollectionPanel(collection.uuid));
311                     },
312                     TRASHED: collection => {
313                         dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
314                         dispatch(updateResources([collection]));
315                         dispatch(setTrashBreadcrumbs(''));
316                         dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
317                         dispatch(loadCollectionPanel(collection.uuid));
318                     },
319                 });
320             }
321         });
322
323 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) =>
324     async (dispatch: Dispatch) => {
325         const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
326         if (collection) {
327             dispatch(snackbarActions.OPEN_SNACKBAR({
328                 message: "Collection has been successfully created.",
329                 hideDuration: 2000,
330                 kind: SnackbarKind.SUCCESS
331             }));
332             dispatch<any>(updateResources([collection]));
333             dispatch<any>(navigateTo(collection.uuid));
334         }
335     };
336
337 export const copyCollection = (data: CopyFormDialogData) =>
338     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
339         try {
340             const copyToProject = getResource(data.ownerUuid)(getState().resources);
341             const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
342             if (copyToProject && collection) {
343                 dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
344                 dispatch(snackbarActions.OPEN_SNACKBAR({
345                     message: 'Collection has been copied.',
346                     hideDuration: 3000,
347                     kind: SnackbarKind.SUCCESS,
348                     link: collection.ownerUuid
349                 }));
350             }
351         } catch (e) {
352             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
353         }
354     };
355
356 export const moveCollection = (data: MoveToFormDialogData) =>
357     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
358         try {
359             const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
360             dispatch<any>(updateResources([collection]));
361             dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
362             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been moved.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
363         } catch (e) {
364             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
365         }
366     };
367
368 export const loadProcess = (uuid: string) =>
369     handleFirstTimeLoad(
370         async (dispatch: Dispatch, getState: () => RootState) => {
371             dispatch<any>(loadProcessPanel(uuid));
372             const process = await dispatch<any>(processesActions.loadProcess(uuid));
373             await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
374             dispatch<any>(setProcessBreadcrumbs(uuid));
375             dispatch<any>(loadDetailsPanel(uuid));
376         });
377
378 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) =>
379     async (dispatch: Dispatch) => {
380         try {
381             const process = await dispatch<any>(processUpdateActions.updateProcess(data));
382             if (process) {
383                 dispatch(snackbarActions.OPEN_SNACKBAR({
384                     message: "Process has been successfully updated.",
385                     hideDuration: 2000,
386                     kind: SnackbarKind.SUCCESS
387                 }));
388                 dispatch<any>(updateResources([process]));
389                 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
390             }
391         } catch (e) {
392             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
393         }
394     };
395
396 export const moveProcess = (data: MoveToFormDialogData) =>
397     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
398         try {
399             const process = await dispatch<any>(processMoveActions.moveProcess(data));
400             dispatch<any>(updateResources([process]));
401             dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
402             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been moved.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
403         } catch (e) {
404             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
405         }
406     };
407
408 export const copyProcess = (data: CopyFormDialogData) =>
409     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
410         try {
411             const process = await dispatch<any>(processCopyActions.copyProcess(data));
412             dispatch<any>(updateResources([process]));
413             dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
414             dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been copied.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
415         } catch (e) {
416             dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
417         }
418     };
419
420 export const resourceIsNotLoaded = (uuid: string) =>
421     snackbarActions.OPEN_SNACKBAR({
422         message: `Resource identified by ${uuid} is not loaded.`,
423         kind: SnackbarKind.ERROR
424     });
425
426 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
427     message: 'User is not authenticated',
428     kind: SnackbarKind.ERROR
429 });
430
431 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
432     message: 'Could not load user',
433     kind: SnackbarKind.ERROR
434 });
435
436 export const reloadProjectMatchingUuid = (matchingUuids: string[]) =>
437     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
438         const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
439         if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
440             dispatch<any>(loadProject(currentProjectPanelUuid));
441         }
442     };
443
444 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
445     dispatch<any>(loadSharedWithMePanel());
446     await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
447     await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
448 });
449
450 export const loadRunProcess = handleFirstTimeLoad(
451     async (dispatch: Dispatch) => {
452         await dispatch<any>(loadRunProcessPanel());
453     }
454 );
455
456 export const loadPublicFavorites = () =>
457     handleFirstTimeLoad(
458         (dispatch: Dispatch) => {
459             dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
460             dispatch<any>(loadPublicFavoritePanel());
461             dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
462         });
463
464 export const loadSearchResults = handleFirstTimeLoad(
465     async (dispatch: Dispatch<any>) => {
466         await dispatch(loadSearchResultsPanel());
467     });
468
469 export const loadLinks = handleFirstTimeLoad(
470     async (dispatch: Dispatch<any>) => {
471         await dispatch(loadLinkPanel());
472     });
473
474 export const loadVirtualMachines = handleFirstTimeLoad(
475     async (dispatch: Dispatch<any>) => {
476         await dispatch(loadVirtualMachinesPanel());
477         dispatch(setBreadcrumbs([{ label: 'Virtual Machines' }]));
478     });
479
480 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(
481     async (dispatch: Dispatch<any>) => {
482         await dispatch(loadVirtualMachinesPanel());
483         dispatch(setBreadcrumbs([{ label: 'Virtual Machines Admin', icon: AdminMenuIcon }]));
484     });
485
486 export const loadRepositories = handleFirstTimeLoad(
487     async (dispatch: Dispatch<any>) => {
488         await dispatch(loadRepositoriesPanel());
489         dispatch(setBreadcrumbs([{ label: 'Repositories' }]));
490     });
491
492 export const loadSshKeys = handleFirstTimeLoad(
493     async (dispatch: Dispatch<any>) => {
494         await dispatch(loadSshKeysPanel());
495     });
496
497 export const loadSiteManager = handleFirstTimeLoad(
498     async (dispatch: Dispatch<any>) => {
499         await dispatch(loadSiteManagerPanel());
500     });
501
502 export const loadUserProfile = (userUuid?: string) =>
503     handleFirstTimeLoad(
504         (dispatch: Dispatch<any>) => {
505             if (userUuid) {
506                 dispatch(setUserProfileBreadcrumbs(userUuid));
507                 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
508             } else {
509                 dispatch(setMyAccountBreadcrumbs());
510                 dispatch(userProfilePanelActions.loadUserProfilePanel());
511             }
512         }
513     );
514
515 export const loadLinkAccount = handleFirstTimeLoad(
516     (dispatch: Dispatch<any>) => {
517         dispatch(loadLinkAccountPanel());
518     });
519
520 export const loadKeepServices = handleFirstTimeLoad(
521     async (dispatch: Dispatch<any>) => {
522         await dispatch(loadKeepServicesPanel());
523     });
524
525 export const loadUsers = handleFirstTimeLoad(
526     async (dispatch: Dispatch<any>) => {
527         await dispatch(loadUsersPanel());
528         dispatch(setUsersBreadcrumbs());
529     });
530
531 export const loadApiClientAuthorizations = handleFirstTimeLoad(
532     async (dispatch: Dispatch<any>) => {
533         await dispatch(loadApiClientAuthorizationsPanel());
534     });
535
536 export const loadGroupsPanel = handleFirstTimeLoad(
537     (dispatch: Dispatch<any>) => {
538         dispatch(setGroupsBreadcrumbs());
539         dispatch(groupPanelActions.loadGroupsPanel());
540     });
541
542
543 export const loadGroupDetailsPanel = (groupUuid: string) =>
544     handleFirstTimeLoad(
545         (dispatch: Dispatch<any>) => {
546             dispatch(setGroupDetailsBreadcrumbs(groupUuid));
547             dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
548         });
549
550 const finishLoadingProject = (project: GroupContentsResource | string) =>
551     async (dispatch: Dispatch<any>) => {
552         const uuid = typeof project === 'string' ? project : project.uuid;
553         dispatch(openProjectPanel(uuid));
554         dispatch(loadDetailsPanel(uuid));
555         if (typeof project !== 'string') {
556             dispatch(updateResources([project]));
557         }
558     };
559
560 const loadGroupContentsResource = async (params: {
561     uuid: string,
562     userUuid: string,
563     services: ServiceRepository
564 }) => {
565     const filters = new FilterBuilder()
566         .addEqual('uuid', params.uuid)
567         .getFilters();
568     const { items } = await params.services.groupsService.contents(params.userUuid, {
569         filters,
570         recursive: true,
571         includeTrash: true,
572     });
573     const resource = items.shift();
574     let handler: GroupContentsHandler;
575     if (resource) {
576         handler = (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
577             ? groupContentsHandlers.TRASHED(resource)
578             : groupContentsHandlers.OWNED(resource);
579     } else {
580         const kind = extractUuidKind(params.uuid);
581         let resource: GroupContentsResource;
582         if (kind === ResourceKind.COLLECTION) {
583             resource = await params.services.collectionService.get(params.uuid);
584         } else if (kind === ResourceKind.PROJECT) {
585             resource = await params.services.projectService.get(params.uuid);
586         } else {
587             resource = await params.services.containerRequestService.get(params.uuid);
588         }
589         handler = groupContentsHandlers.SHARED(resource);
590     }
591     return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) =>
592         groupContentsHandlers.match(handler, cases);
593
594 };
595
596 const groupContentsHandlersRecord = {
597     TRASHED: ofType<GroupContentsResource>(),
598     SHARED: ofType<GroupContentsResource>(),
599     OWNED: ofType<GroupContentsResource>(),
600 };
601
602 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
603
604 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;