1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch, AnyAction } from 'redux';
6 import { RootState } from "../store";
7 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
8 import { loadCollectionPanel } from '~/store/collection-panel/collection-panel-action';
9 import { snackbarActions } from '../snackbar/snackbar-actions';
10 import { loadFavoritePanel } from '../favorite-panel/favorite-panel-action';
11 import { openProjectPanel, projectPanelActions } from '~/store/project-panel/project-panel-action';
12 import { activateSidePanelTreeItem, initSidePanelTree, SidePanelTreeCategory, loadSidePanelTreeProjects, getSidePanelTreeNodeAncestorsIds } from '../side-panel-tree/side-panel-tree-actions';
13 import { loadResource, updateResources } from '../resources/resources-actions';
14 import { favoritePanelActions } from '~/store/favorite-panel/favorite-panel-action';
15 import { projectPanelColumns } from '~/views/project-panel/project-panel';
16 import { favoritePanelColumns } from '~/views/favorite-panel/favorite-panel';
17 import { matchRootRoute } from '~/routes/routes';
18 import { setCollectionBreadcrumbs, setProjectBreadcrumbs, setSidePanelBreadcrumbs, setProcessBreadcrumbs, setSharedWithMeBreadcrumbs } from '../breadcrumbs/breadcrumbs-actions';
19 import { navigateToProject } from '../navigation/navigation-action';
20 import { MoveToFormDialogData } from '~/store/move-to-dialog/move-to-dialog';
21 import { ServiceRepository } from '~/services/services';
22 import { getResource } from '../resources/resources';
23 import { getProjectPanelCurrentUuid } from '../project-panel/project-panel-action';
24 import * as projectCreateActions from '~/store/projects/project-create-actions';
25 import * as projectMoveActions from '~/store/projects/project-move-actions';
26 import * as projectUpdateActions from '~/store/projects/project-update-actions';
27 import * as collectionCreateActions from '~/store/collections/collection-create-actions';
28 import * as collectionCopyActions from '~/store/collections/collection-copy-actions';
29 import * as collectionUpdateActions from '~/store/collections/collection-update-actions';
30 import * as collectionMoveActions from '~/store/collections/collection-move-actions';
31 import * as processesActions from '../processes/processes-actions';
32 import * as processMoveActions from '~/store/processes/process-move-actions';
33 import * as processUpdateActions from '~/store/processes/process-update-actions';
34 import * as processCopyActions from '~/store/processes/process-copy-actions';
35 import { trashPanelColumns } from "~/views/trash-panel/trash-panel";
36 import { loadTrashPanel, trashPanelActions } from "~/store/trash-panel/trash-panel-action";
37 import { initProcessLogsPanel } from '../process-logs-panel/process-logs-panel-actions';
38 import { loadProcessPanel } from '~/store/process-panel/process-panel-actions';
39 import { sharedWithMePanelActions } from '~/store/shared-with-me-panel/shared-with-me-panel-actions';
40 import { loadSharedWithMePanel } from '../shared-with-me-panel/shared-with-me-panel-actions';
41 import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
42 import { loadWorkflowPanel, workflowPanelActions } from '~/store/workflow-panel/workflow-panel-actions';
43 import { workflowPanelColumns } from '~/views/workflow-panel/workflow-panel-view';
44 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
45 import { getProgressIndicator } from '../progress-indicator/progress-indicator-reducer';
47 export const WORKBENCH_LOADING_SCREEN = 'workbenchLoadingScreen';
49 export const isWorkbenchLoading = (state: RootState) => {
50 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
51 return progress ? progress.working : false;
54 const handleFirstTimeLoad = (action: any) =>
55 async (dispatch: Dispatch<any>, getState: () => RootState) => {
57 await dispatch(action);
59 if (isWorkbenchLoading(getState())) {
60 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
66 export const loadWorkbench = () =>
67 async (dispatch: Dispatch, getState: () => RootState) => {
68 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
69 const { auth, router } = getState();
70 const { user } = auth;
72 const userResource = await dispatch<any>(loadResource(user.uuid));
74 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
75 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
76 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
77 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
78 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
79 dispatch<any>(initSidePanelTree());
80 if (router.location) {
81 const match = matchRootRoute(router.location.pathname);
83 dispatch(navigateToProject(userResource.uuid));
87 dispatch(userIsNotAuthenticated);
90 dispatch(userIsNotAuthenticated);
94 export const loadFavorites = () =>
96 (dispatch: Dispatch) => {
97 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
98 dispatch<any>(loadFavoritePanel());
99 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
102 export const loadTrash = () =>
104 (dispatch: Dispatch) => {
105 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
106 dispatch<any>(loadTrashPanel());
107 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
110 export const loadProject = (uuid: string) =>
112 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
113 dispatch(openProjectPanel(uuid));
114 await dispatch(activateSidePanelTreeItem(uuid));
115 dispatch(setProjectBreadcrumbs(uuid));
116 dispatch(loadDetailsPanel(uuid));
119 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) =>
120 async (dispatch: Dispatch) => {
121 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
123 dispatch(snackbarActions.OPEN_SNACKBAR({
124 message: "Project has been successfully created.",
127 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
128 dispatch<any>(reloadProjectMatchingUuid([newProject.ownerUuid]));
132 export const moveProject = (data: MoveToFormDialogData) =>
133 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
135 const oldProject = getResource(data.uuid)(getState().resources);
136 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : '';
137 const movedProject = await dispatch<any>(projectMoveActions.moveProject(data));
139 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Project has been moved', hideDuration: 2000 }));
141 await dispatch<any>(loadSidePanelTreeProjects(oldProject.ownerUuid));
143 dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
146 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
150 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) =>
151 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
152 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
153 if (updatedProject) {
154 dispatch(snackbarActions.OPEN_SNACKBAR({
155 message: "Project has been successfully updated.",
158 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
159 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
163 export const loadCollection = (uuid: string) =>
165 async (dispatch: Dispatch) => {
166 const collection = await dispatch<any>(loadCollectionPanel(uuid));
167 await dispatch<any>(activateSidePanelTreeItem(collection.ownerUuid));
168 dispatch<any>(setCollectionBreadcrumbs(collection.uuid));
169 dispatch(loadDetailsPanel(uuid));
172 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) =>
173 async (dispatch: Dispatch) => {
174 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
176 dispatch(snackbarActions.OPEN_SNACKBAR({
177 message: "Collection has been successfully created.",
180 dispatch<any>(updateResources([collection]));
181 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
185 export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
186 async (dispatch: Dispatch) => {
187 const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
189 dispatch(snackbarActions.OPEN_SNACKBAR({
190 message: "Collection has been successfully updated.",
193 dispatch<any>(updateResources([collection]));
194 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
198 export const copyCollection = (data: CopyFormDialogData) =>
199 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
201 const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
202 dispatch<any>(updateResources([collection]));
203 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
204 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been copied.', hideDuration: 2000 }));
206 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
210 export const moveCollection = (data: MoveToFormDialogData) =>
211 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
213 const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
214 dispatch<any>(updateResources([collection]));
215 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
216 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been moved.', hideDuration: 2000 }));
218 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
222 export const loadProcess = (uuid: string) =>
224 async (dispatch: Dispatch, getState: () => RootState) => {
225 dispatch<any>(loadProcessPanel(uuid));
226 const process = await dispatch<any>(processesActions.loadProcess(uuid));
227 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
228 dispatch<any>(setProcessBreadcrumbs(uuid));
229 dispatch(loadDetailsPanel(uuid));
232 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) =>
233 async (dispatch: Dispatch) => {
235 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
237 dispatch(snackbarActions.OPEN_SNACKBAR({
238 message: "Process has been successfully updated.",
241 dispatch<any>(updateResources([process]));
242 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
245 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
249 export const moveProcess = (data: MoveToFormDialogData) =>
250 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
252 const process = await dispatch<any>(processMoveActions.moveProcess(data));
253 dispatch<any>(updateResources([process]));
254 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
255 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been moved.', hideDuration: 2000 }));
257 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
261 export const copyProcess = (data: CopyFormDialogData) =>
262 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
264 const process = await dispatch<any>(processCopyActions.copyProcess(data));
265 dispatch<any>(updateResources([process]));
266 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
267 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been copied.', hideDuration: 2000 }));
269 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
273 export const loadProcessLog = (uuid: string) =>
275 async (dispatch: Dispatch) => {
276 const process = await dispatch<any>(processesActions.loadProcess(uuid));
277 dispatch<any>(setProcessBreadcrumbs(uuid));
278 dispatch<any>(initProcessLogsPanel(uuid));
279 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
282 export const resourceIsNotLoaded = (uuid: string) =>
283 snackbarActions.OPEN_SNACKBAR({
284 message: `Resource identified by ${uuid} is not loaded.`
287 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
288 message: 'User is not authenticated'
291 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
292 message: 'Could not load user'
295 export const reloadProjectMatchingUuid = (matchingUuids: string[]) =>
296 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
297 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
298 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
299 dispatch<any>(loadProject(currentProjectPanelUuid));
303 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
304 dispatch<any>(loadSharedWithMePanel());
305 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
306 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
309 export const loadWorkflow = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
310 dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.WORKFLOWS));
311 await dispatch(loadWorkflowPanel());
312 dispatch(setSidePanelBreadcrumbs(SidePanelTreeCategory.WORKFLOWS));