1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from 'redux';
6 import { RootState } from "~/store/store";
7 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
8 import { snackbarActions } from '~/store/snackbar/snackbar-actions';
9 import { loadFavoritePanel } from '~/store/favorite-panel/favorite-panel-action';
10 import { openProjectPanel, projectPanelActions, setIsProjectPanelTrashed } from '~/store/project-panel/project-panel-action';
11 import { activateSidePanelTreeItem, initSidePanelTree, SidePanelTreeCategory, loadSidePanelTreeProjects } from '~/store/side-panel-tree/side-panel-tree-actions';
12 import { loadResource, updateResources } from '~/store/resources/resources-actions';
13 import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-action';
14 import { projectPanelColumns } from '~/views/project-panel/project-panel';
15 import { favoritePanelColumns } from '~/views/favorite-panel/favorite-panel';
16 import { matchRootRoute } from '~/routes/routes';
17 import { setSidePanelBreadcrumbs, setProcessBreadcrumbs, setSharedWithMeBreadcrumbs, setTrashBreadcrumbs, setBreadcrumbs, setGroupDetailsBreadcrumbs, setGroupsBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
18 import { navigateToProject } from '~/store/navigation/navigation-action';
19 import { MoveToFormDialogData } from '~/store/move-to-dialog/move-to-dialog';
20 import { ServiceRepository } from '~/services/services';
21 import { getResource } from '~/store/resources/resources';
22 import { getProjectPanelCurrentUuid } from '~/store/project-panel/project-panel-action';
23 import * as projectCreateActions from '~/store/projects/project-create-actions';
24 import * as projectMoveActions from '~/store/projects/project-move-actions';
25 import * as projectUpdateActions from '~/store/projects/project-update-actions';
26 import * as collectionCreateActions from '~/store/collections/collection-create-actions';
27 import * as collectionCopyActions from '~/store/collections/collection-copy-actions';
28 import * as collectionUpdateActions from '~/store/collections/collection-update-actions';
29 import * as collectionMoveActions from '~/store/collections/collection-move-actions';
30 import * as processesActions from '~/store/processes/processes-actions';
31 import * as processMoveActions from '~/store/processes/process-move-actions';
32 import * as processUpdateActions from '~/store/processes/process-update-actions';
33 import * as processCopyActions from '~/store/processes/process-copy-actions';
34 import { trashPanelColumns } from "~/views/trash-panel/trash-panel";
35 import { loadTrashPanel, trashPanelActions } from "~/store/trash-panel/trash-panel-action";
36 import { initProcessLogsPanel } from '~/store/process-logs-panel/process-logs-panel-actions';
37 import { loadProcessPanel } from '~/store/process-panel/process-panel-actions';
38 import { sharedWithMePanelActions } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
39 import { loadSharedWithMePanel } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
40 import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
41 import { loadWorkflowPanel, workflowPanelActions } from '~/store/workflow-panel/workflow-panel-actions';
42 import { loadSshKeysPanel } from '~/store/auth/auth-action';
43 import { loadMyAccountPanel } from '~/store/my-account/my-account-panel-actions';
44 import { workflowPanelColumns } from '~/views/workflow-panel/workflow-panel-view';
45 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
46 import { getProgressIndicator } from '~/store/progress-indicator/progress-indicator-reducer';
47 import { ResourceKind, extractUuidKind } from '~/models/resource';
48 import { FilterBuilder } from '~/services/api/filter-builder';
49 import { GroupContentsResource } from '~/services/groups-service/groups-service';
50 import { unionize, ofType, UnionOf, MatchCases } from '~/common/unionize';
51 import { loadRunProcessPanel } from '~/store/run-process-panel/run-process-panel-actions';
52 import { loadCollectionFiles } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions';
53 import { SnackbarKind } from '~/store/snackbar/snackbar-actions';
54 import { collectionPanelActions } from "~/store/collection-panel/collection-panel-action";
55 import { CollectionResource } from "~/models/collection";
56 import { searchResultsPanelActions, loadSearchResultsPanel } from '~/store/search-results-panel/search-results-panel-actions';
57 import { searchResultsPanelColumns } from '~/views/search-results-panel/search-results-panel-view';
58 import { loadVirtualMachinesPanel } from '~/store/virtual-machines/virtual-machines-actions';
59 import { loadRepositoriesPanel } from '~/store/repositories/repositories-actions';
60 import { loadKeepServicesPanel } from '~/store/keep-services/keep-services-actions';
61 import { loadUsersPanel, userBindedActions } from '~/store/users/users-actions';
62 import { loadLinkPanel, linkPanelActions } from '~/store/link-panel/link-panel-actions';
63 import { linkPanelColumns } from '~/views/link-panel/link-panel-root';
64 import { userPanelColumns } from '~/views/user-panel/user-panel';
65 import { loadComputeNodesPanel } from '~/store/compute-nodes/compute-nodes-actions';
66 import { loadApiClientAuthorizationsPanel } from '~/store/api-client-authorizations/api-client-authorizations-actions';
67 import * as groupPanelActions from '~/store/groups-panel/groups-panel-actions';
68 import { groupsPanelColumns } from '~/views/groups-panel/groups-panel';
69 import * as groupDetailsPanelActions from '~/store/group-details-panel/group-details-panel-actions';
70 import { groupDetailsPanelColumns } from '~/views/group-details-panel/group-details-panel';
72 export const WORKBENCH_LOADING_SCREEN = 'workbenchLoadingScreen';
74 export const isWorkbenchLoading = (state: RootState) => {
75 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
76 return progress ? progress.working : false;
79 const handleFirstTimeLoad = (action: any) =>
80 async (dispatch: Dispatch<any>, getState: () => RootState) => {
82 await dispatch(action);
84 if (isWorkbenchLoading(getState())) {
85 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
90 export const loadWorkbench = () =>
91 async (dispatch: Dispatch, getState: () => RootState) => {
92 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
93 const { auth, router } = getState();
94 const { user } = auth;
96 const userResource = await dispatch<any>(loadResource(user.uuid));
98 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
99 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
100 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
101 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
102 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
103 dispatch(searchResultsPanelActions.SET_COLUMNS({ columns: searchResultsPanelColumns }));
104 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
105 dispatch(groupPanelActions.GroupsPanelActions.SET_COLUMNS({ columns: groupsPanelColumns }));
106 dispatch(groupDetailsPanelActions.GroupDetailsPanelActions.SET_COLUMNS({columns: groupDetailsPanelColumns}));
107 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
108 dispatch<any>(initSidePanelTree());
109 if (router.location) {
110 const match = matchRootRoute(router.location.pathname);
112 dispatch(navigateToProject(userResource.uuid));
116 dispatch(userIsNotAuthenticated);
119 dispatch(userIsNotAuthenticated);
123 export const loadFavorites = () =>
125 (dispatch: Dispatch) => {
126 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
127 dispatch<any>(loadFavoritePanel());
128 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
131 export const loadTrash = () =>
133 (dispatch: Dispatch) => {
134 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
135 dispatch<any>(loadTrashPanel());
136 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
139 export const loadProject = (uuid: string) =>
141 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
142 const userUuid = services.authService.getUuid();
143 dispatch(setIsProjectPanelTrashed(false));
145 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
146 // Load another users home projects
147 dispatch(finishLoadingProject(uuid));
148 } else if (userUuid !== uuid) {
149 const match = await loadGroupContentsResource({ uuid, userUuid, services });
151 OWNED: async project => {
152 await dispatch(activateSidePanelTreeItem(uuid));
153 dispatch<any>(setSidePanelBreadcrumbs(uuid));
154 dispatch(finishLoadingProject(project));
157 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
158 dispatch(activateSidePanelTreeItem(uuid));
159 dispatch(finishLoadingProject(project));
161 TRASHED: project => {
162 dispatch<any>(setTrashBreadcrumbs(uuid));
163 dispatch(setIsProjectPanelTrashed(true));
164 dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
165 dispatch(finishLoadingProject(project));
169 await dispatch(activateSidePanelTreeItem(userUuid));
170 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
171 dispatch(finishLoadingProject(userUuid));
176 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) =>
177 async (dispatch: Dispatch) => {
178 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
180 dispatch(snackbarActions.OPEN_SNACKBAR({
181 message: "Project has been successfully created.",
184 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
185 dispatch<any>(reloadProjectMatchingUuid([newProject.ownerUuid]));
189 export const moveProject = (data: MoveToFormDialogData) =>
190 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
192 const oldProject = getResource(data.uuid)(getState().resources);
193 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : '';
194 const movedProject = await dispatch<any>(projectMoveActions.moveProject(data));
196 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Project has been moved', hideDuration: 2000 }));
198 await dispatch<any>(loadSidePanelTreeProjects(oldProject.ownerUuid));
200 dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
203 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
207 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) =>
208 async (dispatch: Dispatch) => {
209 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
210 if (updatedProject) {
211 dispatch(snackbarActions.OPEN_SNACKBAR({
212 message: "Project has been successfully updated.",
215 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
216 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
220 export const loadCollection = (uuid: string) =>
222 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
223 const userUuid = services.authService.getUuid();
225 const match = await loadGroupContentsResource({ uuid, userUuid, services });
227 OWNED: async collection => {
228 dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
229 dispatch(updateResources([collection]));
230 await dispatch(activateSidePanelTreeItem(collection.ownerUuid));
231 dispatch(setSidePanelBreadcrumbs(collection.ownerUuid));
232 dispatch(loadCollectionFiles(collection.uuid));
234 SHARED: collection => {
235 dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
236 dispatch(updateResources([collection]));
237 dispatch<any>(setSharedWithMeBreadcrumbs(collection.ownerUuid));
238 dispatch(activateSidePanelTreeItem(collection.ownerUuid));
239 dispatch(loadCollectionFiles(collection.uuid));
241 TRASHED: collection => {
242 dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource));
243 dispatch(updateResources([collection]));
244 dispatch(setTrashBreadcrumbs(''));
245 dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
246 dispatch(loadCollectionFiles(collection.uuid));
253 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) =>
254 async (dispatch: Dispatch) => {
255 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
257 dispatch(snackbarActions.OPEN_SNACKBAR({
258 message: "Collection has been successfully created.",
261 dispatch<any>(updateResources([collection]));
262 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
266 export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
267 async (dispatch: Dispatch) => {
268 const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
270 dispatch(snackbarActions.OPEN_SNACKBAR({
271 message: "Collection has been successfully updated.",
274 dispatch<any>(updateResources([collection]));
275 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
279 export const copyCollection = (data: CopyFormDialogData) =>
280 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
282 const copyToProject = getResource(data.ownerUuid)(getState().resources);
283 const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
284 if (copyToProject && collection) {
285 dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
286 dispatch(snackbarActions.OPEN_SNACKBAR({
287 message: 'Collection has been copied.',
289 kind: SnackbarKind.SUCCESS,
290 link: collection.ownerUuid
294 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000, kind: SnackbarKind.ERROR }));
298 export const moveCollection = (data: MoveToFormDialogData) =>
299 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
301 const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
302 dispatch<any>(updateResources([collection]));
303 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
304 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been moved.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
306 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
310 export const loadProcess = (uuid: string) =>
312 async (dispatch: Dispatch, getState: () => RootState) => {
313 dispatch<any>(loadProcessPanel(uuid));
314 const process = await dispatch<any>(processesActions.loadProcess(uuid));
315 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
316 dispatch<any>(setProcessBreadcrumbs(uuid));
317 dispatch(loadDetailsPanel(uuid));
320 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) =>
321 async (dispatch: Dispatch) => {
323 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
325 dispatch(snackbarActions.OPEN_SNACKBAR({
326 message: "Process has been successfully updated.",
329 dispatch<any>(updateResources([process]));
330 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
333 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
337 export const moveProcess = (data: MoveToFormDialogData) =>
338 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
340 const process = await dispatch<any>(processMoveActions.moveProcess(data));
341 dispatch<any>(updateResources([process]));
342 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
343 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been moved.', hideDuration: 2000 }));
345 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
349 export const copyProcess = (data: CopyFormDialogData) =>
350 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
352 const process = await dispatch<any>(processCopyActions.copyProcess(data));
353 dispatch<any>(updateResources([process]));
354 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
355 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been copied.', hideDuration: 2000 }));
357 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
361 export const loadProcessLog = (uuid: string) =>
363 async (dispatch: Dispatch) => {
364 const process = await dispatch<any>(processesActions.loadProcess(uuid));
365 dispatch<any>(setProcessBreadcrumbs(uuid));
366 dispatch<any>(initProcessLogsPanel(uuid));
367 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
370 export const resourceIsNotLoaded = (uuid: string) =>
371 snackbarActions.OPEN_SNACKBAR({
372 message: `Resource identified by ${uuid} is not loaded.`
375 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
376 message: 'User is not authenticated'
379 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
380 message: 'Could not load user'
383 export const reloadProjectMatchingUuid = (matchingUuids: string[]) =>
384 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
385 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
386 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
387 dispatch<any>(loadProject(currentProjectPanelUuid));
391 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
392 dispatch<any>(loadSharedWithMePanel());
393 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
394 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
397 export const loadRunProcess = handleFirstTimeLoad(
398 async (dispatch: Dispatch) => {
399 await dispatch<any>(loadRunProcessPanel());
403 export const loadWorkflow = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
404 dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.WORKFLOWS));
405 await dispatch(loadWorkflowPanel());
406 dispatch(setSidePanelBreadcrumbs(SidePanelTreeCategory.WORKFLOWS));
409 export const loadSearchResults = handleFirstTimeLoad(
410 async (dispatch: Dispatch<any>) => {
411 await dispatch(loadSearchResultsPanel());
414 export const loadLinks = handleFirstTimeLoad(
415 async (dispatch: Dispatch<any>) => {
416 await dispatch(loadLinkPanel());
419 export const loadVirtualMachines = handleFirstTimeLoad(
420 async (dispatch: Dispatch<any>) => {
421 await dispatch(loadVirtualMachinesPanel());
422 dispatch(setBreadcrumbs([{ label: 'Virtual Machines' }]));
425 export const loadRepositories = handleFirstTimeLoad(
426 async (dispatch: Dispatch<any>) => {
427 await dispatch(loadRepositoriesPanel());
428 dispatch(setBreadcrumbs([{ label: 'Repositories' }]));
431 export const loadSshKeys = handleFirstTimeLoad(
432 async (dispatch: Dispatch<any>) => {
433 await dispatch(loadSshKeysPanel());
436 export const loadMyAccount = handleFirstTimeLoad(
437 (dispatch: Dispatch<any>) => {
438 dispatch(loadMyAccountPanel());
441 export const loadKeepServices = handleFirstTimeLoad(
442 async (dispatch: Dispatch<any>) => {
443 await dispatch(loadKeepServicesPanel());
446 export const loadUsers = handleFirstTimeLoad(
447 async (dispatch: Dispatch<any>) => {
448 await dispatch(loadUsersPanel());
449 dispatch(setBreadcrumbs([{ label: 'Users' }]));
452 export const loadComputeNodes = handleFirstTimeLoad(
453 async (dispatch: Dispatch<any>) => {
454 await dispatch(loadComputeNodesPanel());
457 export const loadApiClientAuthorizations = handleFirstTimeLoad(
458 async (dispatch: Dispatch<any>) => {
459 await dispatch(loadApiClientAuthorizationsPanel());
462 export const loadGroupsPanel = handleFirstTimeLoad(
463 (dispatch: Dispatch<any>) => {
464 dispatch(setGroupsBreadcrumbs());
465 dispatch(groupPanelActions.loadGroupsPanel());
469 export const loadGroupDetailsPanel = (groupUuid: string) =>
471 (dispatch: Dispatch<any>) => {
472 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
473 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
476 const finishLoadingProject = (project: GroupContentsResource | string) =>
477 async (dispatch: Dispatch<any>) => {
478 const uuid = typeof project === 'string' ? project : project.uuid;
479 dispatch(openProjectPanel(uuid));
480 dispatch(loadDetailsPanel(uuid));
481 if (typeof project !== 'string') {
482 dispatch(updateResources([project]));
486 const loadGroupContentsResource = async (params: {
489 services: ServiceRepository
491 const filters = new FilterBuilder()
492 .addEqual('uuid', params.uuid)
494 const { items } = await params.services.groupsService.contents(params.userUuid, {
499 const resource = items.shift();
500 let handler: GroupContentsHandler;
502 handler = (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
503 ? groupContentsHandlers.TRASHED(resource)
504 : groupContentsHandlers.OWNED(resource);
506 const kind = extractUuidKind(params.uuid);
507 let resource: GroupContentsResource;
508 if (kind === ResourceKind.COLLECTION) {
509 resource = await params.services.collectionService.get(params.uuid);
510 } else if (kind === ResourceKind.PROJECT) {
511 resource = await params.services.projectService.get(params.uuid);
513 resource = await params.services.containerRequestService.get(params.uuid);
515 handler = groupContentsHandlers.SHARED(resource);
517 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) =>
518 groupContentsHandlers.match(handler, cases);
522 const groupContentsHandlersRecord = {
523 TRASHED: ofType<GroupContentsResource>(),
524 SHARED: ofType<GroupContentsResource>(),
525 OWNED: ofType<GroupContentsResource>(),
528 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
530 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;