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 const ancestors = getSidePanelTreeNodeAncestorsIds(uuid)(getState().treePicker);
89 if (ancestors.find(uuid => uuid === services.authService.getUuid())) {
90 dispatch(setProjectBreadcrumbs(uuid));
92 dispatch(setSharedWithMeBreadcrumbs(uuid));
93 dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
95 dispatch(loadDetailsPanel(uuid));
98 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) =>
99 async (dispatch: Dispatch) => {
100 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
102 dispatch(snackbarActions.OPEN_SNACKBAR({
103 message: "Project has been successfully created.",
106 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
107 dispatch<any>(reloadProjectMatchingUuid([newProject.ownerUuid]));
111 export const moveProject = (data: MoveToFormDialogData) =>
112 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
114 const oldProject = getResource(data.uuid)(getState().resources);
115 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : '';
116 const movedProject = await dispatch<any>(projectMoveActions.moveProject(data));
118 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Project has been moved', hideDuration: 2000 }));
120 await dispatch<any>(loadSidePanelTreeProjects(oldProject.ownerUuid));
122 dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
125 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
129 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) =>
130 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
131 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
132 if (updatedProject) {
133 dispatch(snackbarActions.OPEN_SNACKBAR({
134 message: "Project has been successfully updated.",
137 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
138 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
142 export const loadCollection = (uuid: string) =>
143 async (dispatch: Dispatch) => {
144 const collection = await dispatch<any>(loadCollectionPanel(uuid));
145 await dispatch<any>(activateSidePanelTreeItem(collection.ownerUuid));
146 dispatch<any>(setCollectionBreadcrumbs(collection.uuid));
147 dispatch(loadDetailsPanel(uuid));
150 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) =>
151 async (dispatch: Dispatch) => {
152 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
154 dispatch(snackbarActions.OPEN_SNACKBAR({
155 message: "Collection has been successfully created.",
158 dispatch<any>(updateResources([collection]));
159 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
163 export const updateCollection = (data: collectionUpdateActions.CollectionUpdateFormDialogData) =>
164 async (dispatch: Dispatch) => {
165 const collection = await dispatch<any>(collectionUpdateActions.updateCollection(data));
167 dispatch(snackbarActions.OPEN_SNACKBAR({
168 message: "Collection has been successfully updated.",
171 dispatch<any>(updateResources([collection]));
172 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
176 export const copyCollection = (data: CopyFormDialogData) =>
177 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
179 const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
180 dispatch<any>(updateResources([collection]));
181 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
182 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been copied.', hideDuration: 2000 }));
184 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
188 export const moveCollection = (data: MoveToFormDialogData) =>
189 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
191 const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
192 dispatch<any>(updateResources([collection]));
193 dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
194 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Collection has been moved.', hideDuration: 2000 }));
196 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
200 export const loadProcess = (uuid: string) =>
201 async (dispatch: Dispatch, getState: () => RootState) => {
202 dispatch<any>(loadProcessPanel(uuid));
203 const process = await dispatch<any>(processesActions.loadProcess(uuid));
204 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
205 dispatch<any>(setProcessBreadcrumbs(uuid));
206 dispatch(loadDetailsPanel(uuid));
210 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) =>
211 async (dispatch: Dispatch) => {
213 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
215 dispatch(snackbarActions.OPEN_SNACKBAR({
216 message: "Process has been successfully updated.",
219 dispatch<any>(updateResources([process]));
220 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
223 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
227 export const moveProcess = (data: MoveToFormDialogData) =>
228 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
230 const process = await dispatch<any>(processMoveActions.moveProcess(data));
231 dispatch<any>(updateResources([process]));
232 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
233 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been moved.', hideDuration: 2000 }));
235 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
239 export const copyProcess = (data: CopyFormDialogData) =>
240 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
242 const process = await dispatch<any>(processCopyActions.copyProcess(data));
243 dispatch<any>(updateResources([process]));
244 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
245 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been copied.', hideDuration: 2000 }));
247 dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
251 export const loadProcessLog = (uuid: string) =>
252 async (dispatch: Dispatch) => {
253 const process = await dispatch<any>(processesActions.loadProcess(uuid));
254 dispatch<any>(setProcessBreadcrumbs(uuid));
255 dispatch<any>(initProcessLogsPanel(uuid));
256 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
259 export const resourceIsNotLoaded = (uuid: string) =>
260 snackbarActions.OPEN_SNACKBAR({
261 message: `Resource identified by ${uuid} is not loaded.`
264 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
265 message: 'User is not authenticated'
268 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
269 message: 'Could not load user'
272 export const reloadProjectMatchingUuid = (matchingUuids: string[]) =>
273 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
274 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
275 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
276 dispatch<any>(loadProject(currentProjectPanelUuid));
280 export const loadSharedWithMe = (dispatch: Dispatch) => {
281 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
282 dispatch<any>(loadSharedWithMePanel());
283 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));