X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/428d454e2681d66bb14558946cfe2fb77a2c8dce..33c03ae3c79936cc1a69129f07fba33fe2d28fd8:/src/views/run-process-panel/run-process-inputs-form.tsx

diff --git a/src/views/run-process-panel/run-process-inputs-form.tsx b/src/views/run-process-panel/run-process-inputs-form.tsx
index 193e5abe..45b97117 100644
--- a/src/views/run-process-panel/run-process-inputs-form.tsx
+++ b/src/views/run-process-panel/run-process-inputs-form.tsx
@@ -4,34 +4,119 @@
 
 import * as React from 'react';
 import { reduxForm, InjectedFormProps } from 'redux-form';
-import { WorkflowResource, CommandInputParameter, CWLType, IntCommandInputParameter } from '~/models/workflow';
+import { CommandInputParameter, CWLType, IntCommandInputParameter, BooleanCommandInputParameter, FileCommandInputParameter, DirectoryCommandInputParameter, DirectoryArrayCommandInputParameter, FloatArrayCommandInputParameter, IntArrayCommandInputParameter } 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 { StringCommandInputParameter, FloatCommandInputParameter, isPrimitiveOfType, WorkflowInputsData, EnumCommandInputParameter, isArrayOfType, StringArrayCommandInputParameter, FileArrayCommandInputParameter } from '../../models/workflow';
 import { FloatInput } from '~/views/run-process-panel/inputs/float-input';
+import { BooleanInput } from './inputs/boolean-input';
+import { FileInput } from './inputs/file-input';
+import { connect } from 'react-redux';
+import { compose } from 'redux';
+import { Grid, StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core';
+import { EnumInput } from './inputs/enum-input';
+import { DirectoryInput } from './inputs/directory-input';
+import { StringArrayInput } from './inputs/string-array-input';
+import { createStructuredSelector, createSelector } from 'reselect';
+import { FileArrayInput } from './inputs/file-array-input';
+import { DirectoryArrayInput } from './inputs/directory-array-input';
+import { FloatArrayInput } from './inputs/float-array-input';
+import { IntArrayInput } from './inputs/int-array-input';
 
-const RUN_PROCESS_INPUTS_FORM = 'runProcessInputsForm';
+export const RUN_PROCESS_INPUTS_FORM = 'runProcessInputsForm';
 
 export interface RunProcessInputFormProps {
     inputs: CommandInputParameter[];
 }
 
-export const RunProcessInputsForm = reduxForm<any, RunProcessInputFormProps>({
-    form: RUN_PROCESS_INPUTS_FORM
-})((props: InjectedFormProps & RunProcessInputFormProps) =>
-    <form>
-        {props.inputs.map(input => {
-            switch (true) {
-                case input.type === CWLType.INT:
-                case input.type === CWLType.LONG:
-                    return <IntInput key={input.id} input={input as IntCommandInputParameter} />;
-                case input.type === CWLType.FLOAT:
-                case input.type === CWLType.DOUBLE:
-                    return <FloatInput key={input.id} input={input as FloatCommandInputParameter} />;
-                case input.type === CWLType.STRING:
-                    return <StringInput key={input.id} input={input as StringCommandInputParameter} />;
-                default:
-                    return null;
-            }
-        })}
-    </form>);
\ No newline at end of file
+const inputsSelector = (props: RunProcessInputFormProps) =>
+    props.inputs;
+
+const initialValuesSelector = createSelector(
+    inputsSelector,
+    inputs => inputs.reduce(
+        (values, input) => ({ ...values, [input.id]: input.value || input.default }),
+        {}));
+
+const propsSelector = createStructuredSelector({
+    initialValues: initialValuesSelector,
+});
+
+const mapStateToProps = (_: any, props: RunProcessInputFormProps) =>
+    propsSelector(props);
+
+export const RunProcessInputsForm = compose(
+    connect(mapStateToProps),
+    reduxForm<WorkflowInputsData, RunProcessInputFormProps>({
+        form: RUN_PROCESS_INPUTS_FORM
+    }))(
+        (props: InjectedFormProps & RunProcessInputFormProps) =>
+            <form>
+                <Grid container spacing={32}>
+                    {props.inputs.map(input =>
+                        <InputItem input={input} key={input.id} />)}
+                </Grid>
+            </form>);
+
+type CssRules = 'inputItem';
+
+const styles: StyleRulesCallback<CssRules> = theme => ({
+    inputItem: {
+        marginBottom: theme.spacing.unit * 2,
+    }
+});
+
+const InputItem = withStyles(styles)(
+    (props: WithStyles<CssRules> & { input: CommandInputParameter }) =>
+        <Grid item xs={12} md={6} className={props.classes.inputItem}>
+            {getInputComponent(props.input)}
+        </Grid>);
+
+const getInputComponent = (input: CommandInputParameter) => {
+    switch (true) {
+        case isPrimitiveOfType(input, CWLType.BOOLEAN):
+            return <BooleanInput input={input as BooleanCommandInputParameter} />;
+
+        case isPrimitiveOfType(input, CWLType.INT):
+        case isPrimitiveOfType(input, CWLType.LONG):
+            return <IntInput input={input as IntCommandInputParameter} />;
+
+        case isPrimitiveOfType(input, CWLType.FLOAT):
+        case isPrimitiveOfType(input, CWLType.DOUBLE):
+            return <FloatInput input={input as FloatCommandInputParameter} />;
+
+        case isPrimitiveOfType(input, CWLType.STRING):
+            return <StringInput input={input as StringCommandInputParameter} />;
+
+        case isPrimitiveOfType(input, CWLType.FILE):
+            return <FileInput input={input as FileCommandInputParameter} />;
+
+        case isPrimitiveOfType(input, CWLType.DIRECTORY):
+            return <DirectoryInput input={input as DirectoryCommandInputParameter} />;
+
+        case typeof input.type === 'object' &&
+            !(input.type instanceof Array) &&
+            input.type.type === 'enum':
+            return <EnumInput input={input as EnumCommandInputParameter} />;
+
+        case isArrayOfType(input, CWLType.STRING):
+            return <StringArrayInput input={input as StringArrayCommandInputParameter} />;
+
+        case isArrayOfType(input, CWLType.INT):
+        case isArrayOfType(input, CWLType.LONG):
+            return <IntArrayInput input={input as IntArrayCommandInputParameter} />;
+
+        case isArrayOfType(input, CWLType.FLOAT):
+        case isArrayOfType(input, CWLType.DOUBLE):
+            return <FloatArrayInput input={input as FloatArrayCommandInputParameter} />;
+
+        case isArrayOfType(input, CWLType.FILE):
+            return <FileArrayInput input={input as FileArrayCommandInputParameter} />;
+
+        case isArrayOfType(input, CWLType.DIRECTORY):
+            return <DirectoryArrayInput input={input as DirectoryArrayCommandInputParameter} />;
+
+        default:
+            return null;
+    }
+};
