1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { reduxForm, InjectedFormProps } from 'redux-form';
7 import { CommandInputParameter, CWLType, IntCommandInputParameter, BooleanCommandInputParameter, FileCommandInputParameter } from '~/models/workflow';
8 import { IntInput } from '~/views/run-process-panel/inputs/int-input';
9 import { StringInput } from '~/views/run-process-panel/inputs/string-input';
10 import { StringCommandInputParameter, FloatCommandInputParameter, isPrimitiveOfType, File, Directory, WorkflowInputsData, EnumCommandInputParameter } from '../../models/workflow';
11 import { FloatInput } from '~/views/run-process-panel/inputs/float-input';
12 import { BooleanInput } from './inputs/boolean-input';
13 import { FileInput } from './inputs/file-input';
14 import { connect } from 'react-redux';
15 import { compose } from 'redux';
16 import { Grid, StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core';
17 import { EnumInput } from './inputs/enum-input';
19 export const RUN_PROCESS_INPUTS_FORM = 'runProcessInputsForm';
21 export interface RunProcessInputFormProps {
22 inputs: CommandInputParameter[];
25 export const RunProcessInputsForm = compose(
26 connect((_: any, props: RunProcessInputFormProps) => ({
27 initialValues: props.inputs.reduce(
28 (values, input) => ({ ...values, [input.id]: input.default }),
31 reduxForm<WorkflowInputsData, RunProcessInputFormProps>({
32 form: RUN_PROCESS_INPUTS_FORM
34 (props: InjectedFormProps & RunProcessInputFormProps) =>
36 <Grid container spacing={32}>
37 {props.inputs.map(input =>
38 <InputItem input={input} key={input.id} />)}
42 type CssRules = 'inputItem';
44 const styles: StyleRulesCallback<CssRules> = theme => ({
46 marginBottom: theme.spacing.unit * 2,
50 const InputItem = withStyles(styles)(
51 (props: WithStyles<CssRules> & { input: CommandInputParameter }) =>
52 <Grid item xs={12} md={6} className={props.classes.inputItem}>
53 {getInputComponent(props.input)}
56 const getInputComponent = (input: CommandInputParameter) => {
58 case isPrimitiveOfType(input, CWLType.BOOLEAN):
59 return <BooleanInput input={input as BooleanCommandInputParameter} />;
61 case isPrimitiveOfType(input, CWLType.INT):
62 case isPrimitiveOfType(input, CWLType.LONG):
63 return <IntInput input={input as IntCommandInputParameter} />;
65 case isPrimitiveOfType(input, CWLType.FLOAT):
66 case isPrimitiveOfType(input, CWLType.DOUBLE):
67 return <FloatInput input={input as FloatCommandInputParameter} />;
69 case isPrimitiveOfType(input, CWLType.STRING):
70 return <StringInput input={input as StringCommandInputParameter} />;
72 case isPrimitiveOfType(input, CWLType.FILE):
73 return <FileInput input={input as FileCommandInputParameter} />;
75 case typeof input.type === 'object' &&
76 !(input.type instanceof Array) &&
77 input.type.type === 'enum':
78 return <EnumInput input={input as EnumCommandInputParameter} />;