15407: Simplifies code handling workflow json mounts.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Tue, 20 Aug 2019 17:51:58 +0000 (14:51 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Tue, 20 Aug 2019 17:51:58 +0000 (14:51 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

src/models/process.ts
src/models/workflow.ts
src/store/processes/process-input-actions.ts
src/store/processes/processes-actions.ts
src/views-components/process-input-dialog/process-input-dialog.tsx

index 9762d50411d45c40be0bb9efbc389e10e3e2e35e..b89e3bef51397077f9d67c4b8f83958300dc4b50 100644 (file)
@@ -9,6 +9,9 @@ import { WorkflowInputsData } from './workflow';
 
 export type ProcessResource = ContainerRequestResource;
 
+export const MOUNT_PATH_CWL_WORKFLOW = '/var/lib/cwl/workflow.json';
+export const MOUNT_PATH_CWL_INPUT = '/var/lib/cwl/cwl.input.json';
+
 export const createWorkflowMounts = (workflow: WorkflowResource, inputs: WorkflowInputsData): { [path: string]: MountType } => {
     return {
         '/var/spool/cwl': {
index 4fc70419e5be1fbd6b5ddeb86c321e5ad99dcdd8..8d0b37de21cacbdac56e41202f71411f27e59d20 100644 (file)
@@ -122,7 +122,8 @@ export const parseWorkflowDefinition = (workflow: WorkflowResource): WorkflowRes
 };
 
 export const getWorkflowInputs = (workflowDefinition: WorkflowResourceDefinition) => {
-    const mainWorkflow = workflowDefinition.$graph!.find(item => item.class === 'Workflow' && item.id === '#main');
+    if (!workflowDefinition.$graph) { return undefined; }
+    const mainWorkflow = workflowDefinition.$graph.find(item => item.class === 'Workflow' && item.id === '#main');
     return mainWorkflow
         ? mainWorkflow.inputs
         : undefined;
index 88624d082334c15b49a076850960a9c9ab0d185c..7e22b53f1496275b470fdeca5aea63d350fafa40 100644 (file)
@@ -5,8 +5,11 @@
 import { dialogActions } from '~/store/dialog/dialog-actions';
 import { RootState } from '~/store/store';
 import { Dispatch } from 'redux';
-import { getProcess } from '~/store/processes/process';
+import { getProcess, Process } from '~/store/processes/process';
 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
+import { getWorkflowInputs } from '~/models/workflow';
+import { JSONMount } from '~/models/mount-types';
+import { MOUNT_PATH_CWL_WORKFLOW } from '~/models/process';
 
 export const PROCESS_INPUT_DIALOG_NAME = 'processInputDialog';
 
@@ -15,10 +18,17 @@ export const openProcessInputDialog = (processUuid: string) =>
         const process = getProcess(processUuid)(getState().resources);
         if (process) {
             const data: any = process;
-            if (data && data.containerRequest.mounts["/var/lib/cwl/workflow.json"] && data.containerRequest.mounts["/var/lib/cwl/workflow.json"].content.$graph.find((a: any) => a.class === 'Workflow' && a.id === '#main') && data.containerRequest.mounts["/var/lib/cwl/workflow.json"].content.$graph.find((a: any) => a.class === 'Workflow' && a.id === '#main').inputs.length > 0) {
+            const inputs = getInputsFromWFMount(process);
+            if (inputs && inputs.length > 0) {
                 dispatch(dialogActions.OPEN_DIALOG({ id: PROCESS_INPUT_DIALOG_NAME, data }));
             } else {
                 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'There are no inputs in this process!', kind: SnackbarKind.ERROR }));
             }
         }
-    };
\ No newline at end of file
+    };
+
+const getInputsFromWFMount = (process: Process) => {
+    if (!process || !process.containerRequest[MOUNT_PATH_CWL_WORKFLOW] ) { return undefined; }
+    const mnt = process.containerRequest.mounts[MOUNT_PATH_CWL_WORKFLOW] as JSONMount;
+    return getWorkflowInputs(mnt.content);
+};
\ No newline at end of file
index 91996dde45bd762540aa199beb1e8c5d7c129ca6..b65a22027352a3a94b33c26ca620ca861aa0e920 100644 (file)
@@ -18,6 +18,8 @@ import { getResource } from '~/store/resources/resources';
 import { initialize } from "redux-form";
 import { RUN_PROCESS_BASIC_FORM, RunProcessBasicFormData } from "~/views/run-process-panel/run-process-basic-form";
 import { RunProcessAdvancedFormData, RUN_PROCESS_ADVANCED_FORM } from "~/views/run-process-panel/run-process-advanced-form";
+import { MOUNT_PATH_CWL_WORKFLOW, MOUNT_PATH_CWL_INPUT } from '~/models/process';
+import { getWorkflowInputs } from "~/models/workflow";
 
 export const loadProcess = (containerRequestUuid: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<Process> => {
@@ -84,10 +86,9 @@ export const reRunProcess = (processUuid: string, workflowUuid: string) =>
         const workflows = getState().runProcessPanel.searchWorkflows;
         const workflow = workflows.find(workflow => workflow.uuid === workflowUuid);
         if (workflow && process) {
-            const newValues = getInputs(process);
-            process.mounts["/var/lib/cwl/workflow.json"].content.$graph.find(
-                (a: any) => a.id === '#main').inputs = newValues;
-            const stringifiedDefinition = JSON.stringify(process.mounts["/var/lib/cwl/workflow.json"].content);
+            let inputs = getWorkflowInputs(process.mounts[MOUNT_PATH_CWL_WORKFLOW]);
+            inputs = getInputs(process);
+            const stringifiedDefinition = JSON.stringify(process.mounts[MOUNT_PATH_CWL_WORKFLOW].content);
             const newWorkflow = { ...workflow, definition: stringifiedDefinition };
 
             const basicInitialData: RunProcessBasicFormData = { name: `Copy of: ${process.name}`, description: process.description };
@@ -112,19 +113,21 @@ export const reRunProcess = (processUuid: string, workflowUuid: string) =>
         }
     };
 
-const getInputs = (data: any) =>
-    data && data.mounts["/var/lib/cwl/workflow.json"] ? data.mounts["/var/lib/cwl/workflow.json"].content.$graph.find(
-        (a: any) => a.id === '#main').inputs.map(
-            (it: any) => (
-                {
-                    type: it.type,
-                    id: it.id,
-                    label: it.label,
-                    default: data.mounts["/var/lib/cwl/cwl.input.json"].content[it.id],
-                    doc: it.doc
-                }
-            )
-        ) : [];
+const getInputs = (data: any) => {
+    if (!data || !data.mounts || !data.mounts[MOUNT_PATH_CWL_WORKFLOW]) { return []; }
+    const inputs = getWorkflowInputs(data.mounts[MOUNT_PATH_CWL_WORKFLOW].content);
+    return inputs ? inputs.map(
+        (it: any) => (
+            {
+                type: it.type,
+                id: it.id,
+                label: it.label,
+                default: data.mounts[MOUNT_PATH_CWL_INPUT].content[it.id],
+                doc: it.doc
+            }
+    )
+    ) : [];
+};
 
 export const openRemoveProcessDialog = (uuid: string) =>
     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
index 1650c902db0adacde3b85b7f69c81be8d25dfa07..a2d5940777ed4286586517732e80e42e0b807745 100644 (file)
@@ -8,6 +8,8 @@ import { WithDialogProps } from '~/store/dialog/with-dialog';
 import { withDialog } from "~/store/dialog/with-dialog";
 import { PROCESS_INPUT_DIALOG_NAME } from '~/store/processes/process-input-actions';
 import { RunProcessInputsForm } from "~/views/run-process-panel/run-process-inputs-form";
+import { MOUNT_PATH_CWL_WORKFLOW, MOUNT_PATH_CWL_INPUT } from "~/models/process";
+import { getWorkflowInputs } from "~/models/workflow";
 
 export const ProcessInputDialog = withDialog(PROCESS_INPUT_DIALOG_NAME)(
     (props: WithDialogProps<any>) =>
@@ -31,16 +33,18 @@ export const ProcessInputDialog = withDialog(PROCESS_INPUT_DIALOG_NAME)(
         </Dialog>
 );
 
-const getInputs = (data: any) =>
-    data && data.mounts["/var/lib/cwl/workflow.json"] ? data.mounts["/var/lib/cwl/workflow.json"].content.$graph.find(
-        (a: any) => a.id === '#main').inputs.map(
-            (it: any) => (
-                {
-                    type: it.type,
-                    id: it.id,
-                    label: it.label,
-                    value: data.mounts["/var/lib/cwl/cwl.input.json"].content[it.id],
-                    disabled: true
-                }
-            )
-        ) : [];
+const getInputs = (data: any) => {
+    if (!data || !data.mounts || !data.mounts[MOUNT_PATH_CWL_WORKFLOW]) { return []; }
+    const inputs = getWorkflowInputs(data.mounts[MOUNT_PATH_CWL_WORKFLOW].content);
+    return inputs ? inputs.map(
+        (it: any) => (
+            {
+                type: it.type,
+                id: it.id,
+                label: it.label,
+                value: data.mounts[MOUNT_PATH_CWL_INPUT].content[it.id],
+                disabled: true
+            }
+        )
+    ) : [];
+};