From: Lucas Di Pentima Date: Tue, 20 Aug 2019 17:51:58 +0000 (-0300) Subject: 15407: Simplifies code handling workflow json mounts. X-Git-Tag: 2.0.0~40^2~1 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/c5fa0c4eed19a9d0c163ea1727189970533f0203 15407: Simplifies code handling workflow json mounts. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/models/process.ts b/src/models/process.ts index 9762d504..b89e3bef 100644 --- a/src/models/process.ts +++ b/src/models/process.ts @@ -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': { diff --git a/src/models/workflow.ts b/src/models/workflow.ts index 4fc70419..8d0b37de 100644 --- a/src/models/workflow.ts +++ b/src/models/workflow.ts @@ -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; diff --git a/src/store/processes/process-input-actions.ts b/src/store/processes/process-input-actions.ts index 88624d08..7e22b53f 100644 --- a/src/store/processes/process-input-actions.ts +++ b/src/store/processes/process-input-actions.ts @@ -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 diff --git a/src/store/processes/processes-actions.ts b/src/store/processes/processes-actions.ts index 91996dde..b65a2202 100644 --- a/src/store/processes/processes-actions.ts +++ b/src/store/processes/processes-actions.ts @@ -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 => { @@ -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) => { diff --git a/src/views-components/process-input-dialog/process-input-dialog.tsx b/src/views-components/process-input-dialog/process-input-dialog.tsx index 1650c902..a2d59407 100644 --- a/src/views-components/process-input-dialog/process-input-dialog.tsx +++ b/src/views-components/process-input-dialog/process-input-dialog.tsx @@ -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) => @@ -31,16 +33,18 @@ export const ProcessInputDialog = withDialog(PROCESS_INPUT_DIALOG_NAME)( ); -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 + } + ) + ) : []; +};