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 } 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 } 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 { trashPanelColumns } from "~/views/trash-panel/trash-panel";
34 import { loadTrashPanel, trashPanelActions } from "~/store/trash-panel/trash-panel-action";
35 import { initProcessLogsPanel } from '../process-logs-panel/process-logs-panel-actions';
36 import { loadProcessPanel } from '~/store/process-panel/process-panel-actions';
39 export const loadWorkbench = () =>
40 async (dispatch: Dispatch, getState: () => RootState) => {
41 const { auth, router } = getState();
42 const { user } = auth;
44 const userResource = await dispatch<any>(loadResource(user.uuid));
46 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
47 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
48 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
49 dispatch<any>(initSidePanelTree());
50 if (router.location) {
51 const match = matchRootRoute(router.location.pathname);
53 dispatch(navigateToProject(userResource.uuid));
57 dispatch(userIsNotAuthenticated);
60 dispatch(userIsNotAuthenticated);
64 export const loadFavorites = () =>
65 (dispatch: Dispatch) => {
66 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
67 dispatch<any>(loadFavoritePanel());
68 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
71 export const loadTrash = () =>
72 (dispatch: Dispatch) => {
73 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
74 dispatch<any>(loadTrashPanel());
75 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
78 export const loadProject = (uuid: string) =>
79 async (dispatch: Dispatch) => {
80 await dispatch<any>(activateSidePanelTreeItem(uuid));
81 dispatch<any>(setProjectBreadcrumbs(uuid));
82 dispatch<any>(openProjectPanel(uuid));
83 dispatch(loadDetailsPanel(uuid));
86 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) =>
87 async (dispatch: Dispatch) => {
88 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
90 dispatch(snackbarActions.OPEN_SNACKBAR({
91 message: "Project has been successfully created.",
94 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
95 dispatch<any>(reloadProjectMatchingUuid([newProject.ownerUuid]));
99 export const moveProject = (data: MoveToFormDialogData) =>
100 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
102 const oldProject = getResource(data.uuid)(getState().resources);
103 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : '';
104 const movedProject = await dispatch<any>(projectMoveActions.moveProject(data));
106 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Project has been moved', hideDuration: 2000 }));
108 await dispatch<any>(loadSidePanelTreeProjects(oldProject.ownerUuid));
110 dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
113 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
117 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) =>
118 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
119 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
120 if (updatedProject) {
121 dispatch(snackbarActions.OPEN_SNACKBAR({
122 message: "Project has been successfully updated.",
125 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
126 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
130 export const loadCollection = (uuid: string) =>
131 async (dispatch: Dispatch) => {
132 const collection = await dispatch<any>(loadCollectionPanel(uuid));
133 await dispatch<any>(activateSidePanelTreeItem(collection.ownerUuid));
134 dispatch<any>(setCollectionBreadcrumbs(collection.uuid));
135 dispatch(loadDetailsPanel(uuid));
138 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) =>
139 async (dispatch: Dispatch) => {
140 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
142 dispatch(snackbarActions.OPEN_SNACKBAR({
143 message: "Collection has been successfully created.",
146 dispatch<any>(updateResources([collection]));
147 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
151 export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
152 async (dispatch: Dispatch) => {
153 const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
155 dispatch(snackbarActions.OPEN_SNACKBAR({
156 message: "Collection has been successfully updated.",
159 dispatch<any>(updateResources([collection]));
160 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
164 export const copyCollection = (data: collectionCopyActions.CollectionCopyFormDialogData) =>
165 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
167 const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
168 dispatch<any>(updateResources([collection]));
169 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
170 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been copied.', hideDuration: 2000 }));
172 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
176 export const moveCollection = (data: MoveToFormDialogData) =>
177 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
179 const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
180 dispatch<any>(updateResources([collection]));
181 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
182 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been moved.', hideDuration: 2000 }));
184 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
188 export const loadProcess = (uuid: string) =>
189 async (dispatch: Dispatch, getState: () => RootState) => {
190 dispatch<any>(loadProcessPanel(uuid));
191 const process = await dispatch<any>(processesActions.loadProcess(uuid));
192 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
193 dispatch<any>(setProcessBreadcrumbs(uuid));
194 dispatch(loadDetailsPanel(uuid));
198 export const moveProcess = (data: MoveToFormDialogData) =>
199 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
201 const process = await dispatch<any>(processMoveActions.moveProcess(data));
202 dispatch<any>(updateResources([process]));
203 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
204 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been moved.', hideDuration: 2000 }));
206 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
210 export const loadProcessLog = (uuid: string) =>
211 async (dispatch: Dispatch) => {
212 const process = await dispatch<any>(processesActions.loadProcess(uuid));
213 dispatch<any>(setProcessBreadcrumbs(uuid));
214 dispatch<any>(initProcessLogsPanel(uuid));
215 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
218 export const resourceIsNotLoaded = (uuid: string) =>
219 snackbarActions.OPEN_SNACKBAR({
220 message: `Resource identified by ${uuid} is not loaded.`
223 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
224 message: 'User is not authenticated'
227 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
228 message: 'Could not load user'
231 export const reloadProjectMatchingUuid = (matchingUuids: string[]) =>
232 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
233 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
234 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
235 dispatch<any>(loadProject(currentProjectPanelUuid));