make a copy process
authorPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Mon, 10 Sep 2018 09:07:46 +0000 (11:07 +0200)
committerPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Mon, 10 Sep 2018 09:07:46 +0000 (11:07 +0200)
Feature #14097

Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>

src/store/collections/collection-copy-actions.ts
src/store/copy-dialog/copy-dialog.ts [new file with mode: 0644]
src/store/processes/process-copy-actions.ts
src/store/workbench/workbench-actions.ts
src/views-components/context-menu/action-sets/process-action-set.ts
src/views-components/context-menu/action-sets/process-resource-action-set.ts
src/views-components/dialog-copy/dialog-copy.tsx [moved from src/views-components/dialog-copy/dialog-collection-copy.tsx with 89% similarity]
src/views-components/dialog-forms/copy-collection-dialog.ts
src/views-components/dialog-forms/copy-process-dialog.ts
src/views/workbench/workbench.tsx

index 87ba0424be5df6bba68f31dbade878b57559077c..09d4e04e7659aa13a54e137ec7b5571feae980ab 100644 (file)
@@ -9,24 +9,19 @@ import { resetPickerProjectTree } from '~/store/project-tree-picker/project-tree
 import { RootState } from '~/store/store';
 import { ServiceRepository } from '~/services/services';
 import { getCommonResourceServiceError, CommonResourceServiceError } from '~/services/common-service/common-resource-service';
+import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
 
 export const COLLECTION_COPY_FORM_NAME = 'collectionCopyFormName';
 
-export interface CollectionCopyFormDialogData {
-    name: string;
-    ownerUuid: string;
-    uuid: string;
-}
-
 export const openCollectionCopyDialog = (resource: { name: string, uuid: string }) =>
     (dispatch: Dispatch) => {
         dispatch<any>(resetPickerProjectTree());
-        const initialData: CollectionCopyFormDialogData = { name: `Copy of: ${resource.name}`, ownerUuid: '', uuid: resource.uuid };
+        const initialData: CopyFormDialogData = { name: `Copy of: ${resource.name}`, ownerUuid: '', uuid: resource.uuid };
         dispatch<any>(initialize(COLLECTION_COPY_FORM_NAME, initialData));
         dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_COPY_FORM_NAME, data: {} }));
     };
 
-export const copyCollection = (resource: CollectionCopyFormDialogData) =>
+export const copyCollection = (resource: CopyFormDialogData) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         dispatch(startSubmit(COLLECTION_COPY_FORM_NAME));
         try {
diff --git a/src/store/copy-dialog/copy-dialog.ts b/src/store/copy-dialog/copy-dialog.ts
new file mode 100644 (file)
index 0000000..4450cfc
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export interface CopyFormDialogData {
+    name: string;
+    uuid: string;
+    ownerUuid: string;
+}
\ No newline at end of file
index e3c5acca9578251b3b283536ddaefeb4fe7c32ba..a9ae64e6769fcb5d0096047dc4cda85a02b012b6 100644 (file)
@@ -2,10 +2,51 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { Dispatch } from "redux";
+import { dialogActions } from "~/store/dialog/dialog-actions";
+import { initialize, startSubmit } from 'redux-form';
+import { resetPickerProjectTree } from '~/store/project-tree-picker/project-tree-picker-actions';
+import { RootState } from '~/store/store';
+import { ServiceRepository } from '~/services/services';
+import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
+import { getProcess, ProcessStatus, getProcessStatus } from '~/store/processes/process';
+import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+
 export const PROCESS_COPY_FORM_NAME = 'processCopyFormName';
 
-export interface ProcessCopyFormDialogData {
-    name: string;
-    ownerUuid: string;
-    uuid: string;
-}
\ No newline at end of file
+export const openCopyProcessDialog = (resource: { name: string, uuid: string }) =>
+    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        const process = getProcess(resource.uuid)(getState().resources);
+        if (process) {
+            const processStatus = getProcessStatus(process);
+            if (processStatus === ProcessStatus.DRAFT) {
+                dispatch<any>(resetPickerProjectTree());
+                const initialData: CopyFormDialogData = { name: `Copy of: ${resource.name}`, uuid: resource.uuid, ownerUuid: '' };
+                dispatch<any>(initialize(PROCESS_COPY_FORM_NAME, initialData));
+                dispatch(dialogActions.OPEN_DIALOG({ id: PROCESS_COPY_FORM_NAME, data: {} }));
+            } else {
+                dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'You can copy only draft processes.', hideDuration: 2000 }));
+            }
+        } else {
+            dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process not found', hideDuration: 2000 }));
+        }
+    };
+
+export const copyProcess = (resource: CopyFormDialogData) =>
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        dispatch(startSubmit(PROCESS_COPY_FORM_NAME));
+        try {
+            const process = await services.containerRequestService.get(resource.uuid);
+            const uuidKey = 'uuid';
+            delete process[uuidKey];
+            await services.containerRequestService.create({ ...process, ownerUuid: resource.ownerUuid, name: resource.name });
+            dispatch(dialogActions.CLOSE_DIALOG({ id: PROCESS_COPY_FORM_NAME }));
+            return process;
+        } catch (e) {
+            if (e) {
+                dispatch(dialogActions.CLOSE_DIALOG({ id: PROCESS_COPY_FORM_NAME }));
+                throw new Error('Could not copy the process.');
+            }
+            return;
+        }
+    };
\ No newline at end of file
index cb65c24ec7b8940a2c000630f04d23cc7c80db5b..647395bd77ead7d1b286e2a5a07840bace194d80 100644 (file)
@@ -30,10 +30,12 @@ import * as collectionUpdateActions from '~/store/collections/collection-update-
 import * as collectionMoveActions from '~/store/collections/collection-move-actions';
 import * as processesActions from '../processes/processes-actions';
 import * as processMoveActions from '~/store/processes/process-move-actions';
+import * as processCopyActions from '~/store/processes/process-copy-actions';
 import { trashPanelColumns } from "~/views/trash-panel/trash-panel";
 import { loadTrashPanel, trashPanelActions } from "~/store/trash-panel/trash-panel-action";
 import { initProcessLogsPanel } from '../process-logs-panel/process-logs-panel-actions';
 import { loadProcessPanel } from '~/store/process-panel/process-panel-actions';
+import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
 
 
 export const loadWorkbench = () =>
@@ -161,7 +163,7 @@ export const updateCollection = (data: collectionUpdateActions.CollectionUpdateF
         }
     };
 
-export const copyCollection = (data: collectionCopyActions.CollectionCopyFormDialogData) =>
+export const copyCollection = (data: CopyFormDialogData) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         try {
             const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
@@ -207,6 +209,18 @@ export const moveProcess = (data: MoveToFormDialogData) =>
         }
     };
 
+export const copyProcess = (data: CopyFormDialogData) =>
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        try {
+            const process = await dispatch<any>(processCopyActions.copyProcess(data));
+            dispatch<any>(updateResources([process]));
+            dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
+            dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Process has been copied.', hideDuration: 2000 }));
+        } catch (e) {
+            dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.message, hideDuration: 2000 }));
+        }
+    };
+
 export const loadProcessLog = (uuid: string) =>
     async (dispatch: Dispatch) => {
         const process = await dispatch<any>(processesActions.loadProcess(uuid));
index 3a824ecc6772b19cbff0ac2612135cb51cb4c4d0..891064bad89a0456946e20bc04b3849db13a6b29 100644 (file)
@@ -12,6 +12,7 @@ import {
 import { favoritePanelActions } from "~/store/favorite-panel/favorite-panel-action";
 import { navigateToProcessLogs } from '~/store/navigation/navigation-action';
 import { openMoveProcessDialog } from '~/store/processes/process-move-actions';
+import { openCopyProcessDialog } from '~/store/processes/process-copy-actions';
 
 export const processActionSet: ContextMenuActionSet = [[
     {
@@ -44,9 +45,7 @@ export const processActionSet: ContextMenuActionSet = [[
     {
         icon: CopyIcon,
         name: "Copy to project",
-        execute: (dispatch, resource) => {
-            // add code
-        }
+        execute: (dispatch, resource) => dispatch<any>(openCopyProcessDialog(resource))
     },
     {
         icon: ReRunProcessIcon,
index 64e30f7e2769af9b47fb3cf136ddc963194e4492..ac092268f755ec8321bb19896c5962231200d1ff 100644 (file)
@@ -8,6 +8,7 @@ import { toggleFavorite } from "~/store/favorites/favorites-actions";
 import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, RemoveIcon } from "~/components/icon/icon";
 import { favoritePanelActions } from "~/store/favorite-panel/favorite-panel-action";
 import { openMoveProcessDialog } from '~/store/processes/process-move-actions';
+import { openCopyProcessDialog } from '~/store/processes/process-copy-actions';
 
 export const processResourceActionSet: ContextMenuActionSet = [[
     {
@@ -40,9 +41,7 @@ export const processResourceActionSet: ContextMenuActionSet = [[
     {
         icon: CopyIcon,
         name: "Copy to project",
-        execute: (dispatch, resource) => {
-            // add code
-        }
+        execute: (dispatch, resource) => dispatch<any>(openCopyProcessDialog(resource))
     },
     {
         icon: DetailsIcon,
similarity index 89%
rename from src/views-components/dialog-copy/dialog-collection-copy.tsx
rename to src/views-components/dialog-copy/dialog-copy.tsx
index 33d16b8a2ca87d9e07b42f02140434e29fcb3fcb..415541595c564ff1d3b672062852af92aaf25461 100644 (file)
@@ -9,9 +9,9 @@ import { FormDialog } from '~/components/form-dialog/form-dialog';
 import { ProjectTreePickerField } from '~/views-components/project-tree-picker/project-tree-picker';
 import { COPY_NAME_VALIDATION, COPY_FILE_VALIDATION } from '~/validators/validators';
 import { TextField } from "~/components/text-field/text-field";
-import { CollectionCopyFormDialogData } from "~/store/collections/collection-copy-actions";
+import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
 
-type CopyFormDialogProps = WithDialogProps<string> & InjectedFormProps<CollectionCopyFormDialogData>;
+type CopyFormDialogProps = WithDialogProps<string> & InjectedFormProps<CopyFormDialogData>;
 
 export const DialogCopy = (props: CopyFormDialogProps) =>
     <FormDialog
index 17823900edabf74e2998b6630ac9fd015e679b67..41309fdff6952762ed9ae9d9c2922f53dc3e5082 100644 (file)
@@ -5,13 +5,14 @@
 import { compose } from "redux";
 import { withDialog } from "~/store/dialog/with-dialog";
 import { reduxForm } from 'redux-form';
-import { COLLECTION_COPY_FORM_NAME, CollectionCopyFormDialogData } from '~/store/collections/collection-copy-actions';
-import { DialogCopy } from "~/views-components/dialog-copy/dialog-collection-copy";
+import { COLLECTION_COPY_FORM_NAME } from '~/store/collections/collection-copy-actions';
+import { DialogCopy } from "~/views-components/dialog-copy/dialog-copy";
 import { copyCollection } from '~/store/workbench/workbench-actions';
+import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
 
 export const CopyCollectionDialog = compose(
     withDialog(COLLECTION_COPY_FORM_NAME),
-    reduxForm<CollectionCopyFormDialogData>({
+    reduxForm<CopyFormDialogData>({
         form: COLLECTION_COPY_FORM_NAME,
         onSubmit: (data, dispatch) => {
             dispatch(copyCollection(data));
index d063562817a942594e8a5622420eadad68fc973c..4ec17c65da870a95b4a0b5255652c66b141179e7 100644 (file)
@@ -5,16 +5,17 @@
 import { compose } from "redux";
 import { withDialog } from "~/store/dialog/with-dialog";
 import { reduxForm } from 'redux-form';
-import { PROCESS_COPY_FORM_NAME, ProcessCopyFormDialogData } from '~/store/processes/process-copy-actions';
-import { DialogCopy } from "~/views-components/dialog-copy/dialog-collection-copy";
-import { copyCollection } from '~/store/workbench/workbench-actions';
+import { PROCESS_COPY_FORM_NAME } from '~/store/processes/process-copy-actions';
+import { DialogCopy } from "~/views-components/dialog-copy/dialog-copy";
+import { copyProcess } from '~/store/workbench/workbench-actions';
+import { CopyFormDialogData } from '~/store/copy-dialog/copy-dialog';
 
 export const CopyProcessDialog = compose(
     withDialog(PROCESS_COPY_FORM_NAME),
-    reduxForm<ProcessCopyFormDialogData>({
+    reduxForm<CopyFormDialogData>({
         form: PROCESS_COPY_FORM_NAME,
         onSubmit: (data, dispatch) => {
-            dispatch(copyCollection(data));
+            dispatch(copyProcess(data));
         }
     })
 )(DialogCopy);
\ No newline at end of file
index 4d231a0cc1134602d1ebdf56fe053e1c22f64039..0e85ca3e8488bde391901ababc45f7a53523f518 100644 (file)
@@ -30,6 +30,7 @@ import { ProcessLogPanel } from '~/views/process-log-panel/process-log-panel';
 import { CreateProjectDialog } from '~/views-components/dialog-forms/create-project-dialog';
 import { CreateCollectionDialog } from '~/views-components/dialog-forms/create-collection-dialog';
 import { CopyCollectionDialog } from '~/views-components/dialog-forms/copy-collection-dialog';
+import { CopyProcessDialog } from '~/views-components/dialog-forms/copy-process-dialog';
 import { UpdateCollectionDialog } from '~/views-components/dialog-forms/update-collection-dialog';
 import { UpdateProjectDialog } from '~/views-components/dialog-forms/update-project-dialog';
 import { MoveProcessDialog } from '~/views-components/dialog-forms/move-process-dialog';
@@ -149,6 +150,7 @@ export const Workbench = withStyles(styles)(
                     <PartialCopyCollectionDialog />
                     <FileRemoveDialog />
                     <CopyCollectionDialog />
+                    <CopyProcessDialog />
                     <FileRemoveDialog />
                     <MultipleFilesRemoveDialog />
                     <UpdateCollectionDialog />