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";
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';
42 import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
44 export const loadWorkbench = () =>
45 async (dispatch: Dispatch, getState: () => RootState) => {
46 const { auth, router } = getState();
47 const { user } = auth;
49 const userResource = await dispatch<any>(loadResource(user.uuid));
51 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
52 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
53 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
54 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
55 dispatch<any>(initSidePanelTree());
56 if (router.location) {
57 const match = matchRootRoute(router.location.pathname);
59 dispatch(navigateToProject(userResource.uuid));
63 dispatch(userIsNotAuthenticated);
66 dispatch(userIsNotAuthenticated);
70 export const loadFavorites = () =>
71 (dispatch: Dispatch) => {
72 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
73 dispatch<any>(loadFavoritePanel());
74 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
77 export const loadTrash = () =>
78 (dispatch: Dispatch) => {
79 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
80 dispatch<any>(loadTrashPanel());
81 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
84 export const loadProject = (uuid: string) =>
85 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
86 dispatch(openProjectPanel(uuid));
87 await dispatch(activateSidePanelTreeItem(uuid));
88 dispatch(setProjectBreadcrumbs(uuid));
89 dispatch(loadDetailsPanel(uuid));
92 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) =>
93 async (dispatch: Dispatch) => {
94 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
96 dispatch(snackbarActions.OPEN_SNACKBAR({
97 message: "Project has been successfully created.",
100 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
101 dispatch<any>(reloadProjectMatchingUuid([newProject.ownerUuid]));
105 export const moveProject = (data: MoveToFormDialogData) =>
106 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
108 const oldProject = getResource(data.uuid)(getState().resources);
109 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : '';
110 const movedProject = await dispatch<any>(projectMoveActions.moveProject(data));
112 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Project has been moved', hideDuration: 2000 }));
114 await dispatch<any>(loadSidePanelTreeProjects(oldProject.ownerUuid));
116 dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
119 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
123 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) =>
124 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
125 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
126 if (updatedProject) {
127 dispatch(snackbarActions.OPEN_SNACKBAR({
128 message: "Project has been successfully updated.",
131 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
132 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
136 export const loadCollection = (uuid: string) =>
137 async (dispatch: Dispatch) => {
138 const collection = await dispatch<any>(loadCollectionPanel(uuid));
139 await dispatch<any>(activateSidePanelTreeItem(collection.ownerUuid));
140 dispatch<any>(setCollectionBreadcrumbs(collection.uuid));
141 dispatch(loadDetailsPanel(uuid));
144 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) =>
145 async (dispatch: Dispatch) => {
146 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
148 dispatch(snackbarActions.OPEN_SNACKBAR({
149 message: "Collection has been successfully created.",
152 dispatch<any>(updateResources([collection]));
153 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
157 export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
158 async (dispatch: Dispatch) => {
159 const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
161 dispatch(snackbarActions.OPEN_SNACKBAR({
162 message: "Collection has been successfully updated.",
165 dispatch<any>(updateResources([collection]));
166 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
170 export const copyCollection = (data: CopyFormDialogData) =>
171 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
173 const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
174 dispatch<any>(updateResources([collection]));
175 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
176 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been copied.', hideDuration: 2000 }));
178 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
182 export const moveCollection = (data: MoveToFormDialogData) =>
183 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
185 const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
186 dispatch<any>(updateResources([collection]));
187 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
188 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been moved.', hideDuration: 2000 }));
190 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
194 export const loadProcess = (uuid: string) =>
195 async (dispatch: Dispatch, getState: () => RootState) => {
196 dispatch<any>(loadProcessPanel(uuid));
197 const process = await dispatch<any>(processesActions.loadProcess(uuid));
198 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
199 dispatch<any>(setProcessBreadcrumbs(uuid));
200 dispatch(loadDetailsPanel(uuid));
204 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) =>
205 async (dispatch: Dispatch) => {
207 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
209 dispatch(snackbarActions.OPEN_SNACKBAR({
210 message: "Process has been successfully updated.",
213 dispatch<any>(updateResources([process]));
214 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
217 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
221 export const moveProcess = (data: MoveToFormDialogData) =>
222 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
224 const process = await dispatch<any>(processMoveActions.moveProcess(data));
225 dispatch<any>(updateResources([process]));
226 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
227 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been moved.', hideDuration: 2000 }));
229 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
233 export const copyProcess = (data: CopyFormDialogData) =>
234 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
236 const process = await dispatch<any>(processCopyActions.copyProcess(data));
237 dispatch<any>(updateResources([process]));
238 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
239 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been copied.', hideDuration: 2000 }));
241 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
245 export const loadProcessLog = (uuid: string) =>
246 async (dispatch: Dispatch) => {
247 const process = await dispatch<any>(processesActions.loadProcess(uuid));
248 dispatch<any>(setProcessBreadcrumbs(uuid));
249 dispatch<any>(initProcessLogsPanel(uuid));
250 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
253 export const resourceIsNotLoaded = (uuid: string) =>
254 snackbarActions.OPEN_SNACKBAR({
255 message: `Resource identified by ${uuid} is not loaded.`
258 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
259 message: 'User is not authenticated'
262 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
263 message: 'Could not load user'
266 export const reloadProjectMatchingUuid = (matchingUuids: string[]) =>
267 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
268 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
269 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
270 dispatch<any>(loadProject(currentProjectPanelUuid));
274 export const loadSharedWithMe = (dispatch: Dispatch) => {
275 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
276 dispatch<any>(loadSharedWithMePanel());
277 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));