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 { initialize, startSubmit } from 'redux-form';
8 import { resetPickerProjectTree } from 'store/project-tree-picker/project-tree-picker-actions';
9 import { RootState } from 'store/store';
10 import { ServiceRepository } from 'services/services';
11 import { CopyFormDialogData } from 'store/copy-dialog/copy-dialog';
12 import { getProcess } from 'store/processes/process';
13 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
14 import { initProjectsTreePicker } from 'store/tree-picker/tree-picker-actions';
15 import { ContainerRequestState } from 'models/container-request';
17 export const PROCESS_COPY_FORM_NAME = 'processCopyFormName';
18 export const MULTI_PROCESS_COPY_FORM_NAME = 'multiProcessCopyFormName';
20 export const openCopyProcessDialog =
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_COPY_FORM_NAME));
26 const initialData: CopyFormDialogData = { name: `Copy of: ${resource.name}`, uuid: resource.uuid, ownerUuid: '' };
27 dispatch<any>(initialize(PROCESS_COPY_FORM_NAME, initialData));
28 dispatch(dialogActions.OPEN_DIALOG({ id: PROCESS_COPY_FORM_NAME, data: {} }));
30 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process not found', hideDuration: 2000, kind: SnackbarKind.ERROR }));
34 export const copyProcess = (resource: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
35 dispatch(startSubmit(PROCESS_COPY_FORM_NAME));
37 const process = await services.containerRequestService.get(resource.uuid);
57 const newProcess = await services.containerRequestService.create({
72 ownerUuid: resource.ownerUuid,
77 state: ContainerRequestState.UNCOMMITTED,
80 dispatch(dialogActions.CLOSE_DIALOG({ id: PROCESS_COPY_FORM_NAME }));
83 dispatch(dialogActions.CLOSE_DIALOG({ id: PROCESS_COPY_FORM_NAME }));
84 throw new Error('Could not copy the process.');