From: Michal Klobukowski Date: Fri, 28 Sep 2018 15:38:56 +0000 (+0200) Subject: RunProcessInputsForm [WIP] X-Git-Tag: 1.3.0~72^2~18 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/428d454e2681d66bb14558946cfe2fb77a2c8dce RunProcessInputsForm [WIP] Feature #13863 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- diff --git a/src/models/workflow.ts b/src/models/workflow.ts index 95cc926f..1cb3d46e 100644 --- a/src/models/workflow.ts +++ b/src/models/workflow.ts @@ -118,7 +118,20 @@ export const getWorkflowInputs = (workflowDefinition: WorkflowResoruceDefinition ? mainWorkflow.inputs : undefined; }; +export const getInputLabel = (input: CommandInputParameter) => { + return `${input.label || input.id}${isRequiredInput(input) ? '*' : ''}`; +}; +export const isRequiredInput = ({ type }: CommandInputParameter) => { + if (type instanceof Array) { + for (const t of type) { + if (t === CWLType.NULL) { + return false; + } + } + } + return true; +}; export const stringifyInputType = ({ type }: CommandInputParameter) => { if (typeof type === 'string') { return type; diff --git a/src/validators/is-float.tsx b/src/validators/is-float.tsx new file mode 100644 index 00000000..9bde5f94 --- /dev/null +++ b/src/validators/is-float.tsx @@ -0,0 +1,11 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { isInteger, isNumber } from 'lodash'; + +const ERROR_MESSAGE = 'This field must be a float'; + +export const isFloat = (value: any) => { + return isNumber(value) ? undefined : ERROR_MESSAGE; +}; diff --git a/src/validators/is-integer.tsx b/src/validators/is-integer.tsx new file mode 100644 index 00000000..fbfe8fbc --- /dev/null +++ b/src/validators/is-integer.tsx @@ -0,0 +1,11 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { isInteger as isInt } from 'lodash'; + +const ERROR_MESSAGE = 'This field must be an integer'; + +export const isInteger = (value: any) => { + return isInt(value) ? undefined : ERROR_MESSAGE; +}; diff --git a/src/validators/is-number.tsx b/src/validators/is-number.tsx new file mode 100644 index 00000000..9b548b94 --- /dev/null +++ b/src/validators/is-number.tsx @@ -0,0 +1,10 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { isNumber as isNum } from 'lodash'; +const ERROR_MESSAGE = 'This field must be a number'; + +export const isNumber = (value: any) => { + return isNum(value) ? undefined : ERROR_MESSAGE; +}; diff --git a/src/views/run-process-panel/inputs/float-input.tsx b/src/views/run-process-panel/inputs/float-input.tsx new file mode 100644 index 00000000..0f5a1162 --- /dev/null +++ b/src/views/run-process-panel/inputs/float-input.tsx @@ -0,0 +1,22 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from 'react'; +import { getInputLabel, FloatCommandInputParameter } from '~/models/workflow'; +import { Field } from 'redux-form'; +import { TextField } from '~/components/text-field/text-field'; +import { isNumber } from '~/validators/is-number'; +import { toNumber } from 'lodash'; +export interface FloatInputProps { + input: FloatCommandInputParameter; +} +export const FloatInput = ({ input }: FloatInputProps) => + toNumber(value)} + format={value => isNaN(value) ? '' : JSON.stringify(value)} + validate={[isNumber]} />; + diff --git a/src/views/run-process-panel/inputs/int-input.tsx b/src/views/run-process-panel/inputs/int-input.tsx new file mode 100644 index 00000000..5b6f95db --- /dev/null +++ b/src/views/run-process-panel/inputs/int-input.tsx @@ -0,0 +1,22 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from 'react'; +import { IntCommandInputParameter, getInputLabel } from '~/models/workflow'; +import { Field } from 'redux-form'; +import { TextField } from '~/components/text-field/text-field'; +import { isInteger } from '~/validators/is-integer'; + +export interface IntInputProps { + input: IntCommandInputParameter; +} +export const IntInput = ({ input }: IntInputProps) => + parseInt(value, 10)} + format={value => isNaN(value) ? '' : JSON.stringify(value)} + validate={[isInteger]} />; + diff --git a/src/views/run-process-panel/inputs/string-input.tsx b/src/views/run-process-panel/inputs/string-input.tsx new file mode 100644 index 00000000..8c72a469 --- /dev/null +++ b/src/views/run-process-panel/inputs/string-input.tsx @@ -0,0 +1,24 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from 'react'; +import { getInputLabel, isRequiredInput, StringCommandInputParameter } from '~/models/workflow'; +import { Field } from 'redux-form'; +import { TextField } from '~/components/text-field/text-field'; +import { require } from '~/validators/require'; + +export interface StringInputProps { + input: StringCommandInputParameter; +} +export const StringInput = ({ input }: StringInputProps) => + undefined, + ]} />; + diff --git a/src/views/run-process-panel/run-process-inputs-form.tsx b/src/views/run-process-panel/run-process-inputs-form.tsx new file mode 100644 index 00000000..193e5abe --- /dev/null +++ b/src/views/run-process-panel/run-process-inputs-form.tsx @@ -0,0 +1,37 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from 'react'; +import { reduxForm, InjectedFormProps } from 'redux-form'; +import { WorkflowResource, CommandInputParameter, CWLType, IntCommandInputParameter } from '~/models/workflow'; +import { IntInput } from '~/views/run-process-panel/inputs/int-input'; +import { StringInput } from '~/views/run-process-panel/inputs/string-input'; +import { StringCommandInputParameter, FloatCommandInputParameter } from '../../models/workflow'; +import { FloatInput } from '~/views/run-process-panel/inputs/float-input'; + +const RUN_PROCESS_INPUTS_FORM = 'runProcessInputsForm'; + +export interface RunProcessInputFormProps { + inputs: CommandInputParameter[]; +} + +export const RunProcessInputsForm = reduxForm({ + form: RUN_PROCESS_INPUTS_FORM +})((props: InjectedFormProps & RunProcessInputFormProps) => +
+ {props.inputs.map(input => { + switch (true) { + case input.type === CWLType.INT: + case input.type === CWLType.LONG: + return ; + case input.type === CWLType.FLOAT: + case input.type === CWLType.DOUBLE: + return ; + case input.type === CWLType.STRING: + return ; + default: + return null; + } + })} + ); \ No newline at end of file diff --git a/src/views/workflow-panel/workflow-description-card.tsx b/src/views/workflow-panel/workflow-description-card.tsx index f6b2fcba..c297276e 100644 --- a/src/views/workflow-panel/workflow-description-card.tsx +++ b/src/views/workflow-panel/workflow-description-card.tsx @@ -9,6 +9,7 @@ import { WorkflowIcon } from '~/components/icon/icon'; import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view'; import { WorkflowResource, parseWorkflowDefinition, getWorkflowInputs } from '~/models/workflow'; import { WorkflowInput } from '~/components/workflow-inputs-form/workflow-input'; +import { RunProcessInputsForm } from '../run-process-panel/run-process-inputs-form'; export type CssRules = 'root' | 'tab'; @@ -54,7 +55,7 @@ export const WorkflowDetailsCard = withStyles(styles)( } {value === 1 && {workflow && this.inputs - ? this.inputs.map(input => ) + ? : }