1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { dialogActions } from "store/dialog/dialog-actions";
7 import { startSubmit, stopSubmit, initialize, FormErrors } from "redux-form";
8 import { ServiceRepository } from "services/services";
9 import { RootState } from "store/store";
10 import { getCommonResourceServiceError, CommonResourceServiceError } from "services/common-service/common-resource-service";
11 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
12 import { MoveToFormDialogData } from "store/move-to-dialog/move-to-dialog";
13 import { resetPickerProjectTree } from "store/project-tree-picker/project-tree-picker-actions";
14 import { projectPanelActions } from "store/project-panel/project-panel-action-bind";
15 import { getProcess } from "store/processes/process";
16 import { initProjectsTreePicker } from "store/tree-picker/tree-picker-actions";
18 export const PROCESS_MOVE_FORM_NAME = "processMoveFormName";
20 export const openMoveProcessDialog =
21 (resource: { name: string; uuid: string }) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
22 const process = getProcess(resource.uuid)(getState().resources);
24 dispatch<any>(resetPickerProjectTree());
25 dispatch<any>(initProjectsTreePicker(PROCESS_MOVE_FORM_NAME));
26 dispatch(initialize(PROCESS_MOVE_FORM_NAME, resource));
27 dispatch(dialogActions.OPEN_DIALOG({ id: PROCESS_MOVE_FORM_NAME, data: {} }));
29 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Process not found", hideDuration: 2000, kind: SnackbarKind.ERROR }));
33 export const moveProcess = (resource: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
34 dispatch(startSubmit(PROCESS_MOVE_FORM_NAME));
36 const process = await services.containerRequestService.get(resource.uuid);
37 await services.containerRequestService.update(resource.uuid, { ownerUuid: resource.ownerUuid });
38 dispatch(projectPanelActions.REQUEST_ITEMS());
39 dispatch(dialogActions.CLOSE_DIALOG({ id: PROCESS_MOVE_FORM_NAME }));
42 const error = getCommonResourceServiceError(e);
43 if (error === CommonResourceServiceError.UNIQUE_NAME_VIOLATION) {
45 stopSubmit(PROCESS_MOVE_FORM_NAME, { ownerUuid: "A process with the same name already exists in the target project." } as FormErrors)
48 dispatch(dialogActions.CLOSE_DIALOG({ id: PROCESS_MOVE_FORM_NAME }));
49 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Could not move the process.", hideDuration: 2000, kind: SnackbarKind.ERROR }));