1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { reduxForm, InjectedFormProps } from 'redux-form';
7 import { CommandInputParameter, CWLType, IntCommandInputParameter, BooleanCommandInputParameter, FileCommandInputParameter, DirectoryCommandInputParameter, DirectoryArrayCommandInputParameter, FloatArrayCommandInputParameter, IntArrayCommandInputParameter } 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, WorkflowInputsData, EnumCommandInputParameter, isArrayOfType, StringArrayCommandInputParameter, FileArrayCommandInputParameter } 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';
18 import { DirectoryInput } from './inputs/directory-input';
19 import { StringArrayInput } from './inputs/string-array-input';
20 import { createStructuredSelector, createSelector } from 'reselect';
21 import { FileArrayInput } from './inputs/file-array-input';
22 import { DirectoryArrayInput } from './inputs/directory-array-input';
23 import { FloatArrayInput } from './inputs/float-array-input';
24 import { IntArrayInput } from './inputs/int-array-input';
26 export const RUN_PROCESS_INPUTS_FORM = 'runProcessInputsForm';
28 export interface RunProcessInputFormProps {
29 inputs: CommandInputParameter[];
32 const inputsSelector = (props: RunProcessInputFormProps) =>
35 const initialValuesSelector = createSelector(
37 inputs => inputs.reduce(
38 (values, input) => ({ ...values, [input.id]: input.value || input.default }),
41 const propsSelector = createStructuredSelector({
42 initialValues: initialValuesSelector,
45 const mapStateToProps = (_: any, props: RunProcessInputFormProps) =>
48 export const RunProcessInputsForm = compose(
49 connect(mapStateToProps),
50 reduxForm<WorkflowInputsData, RunProcessInputFormProps>({
51 form: RUN_PROCESS_INPUTS_FORM
53 (props: InjectedFormProps & RunProcessInputFormProps) =>
55 <Grid container spacing={32}>
56 {props.inputs.map(input =>
57 <InputItem input={input} key={input.id} />)}
61 type CssRules = 'inputItem';
63 const styles: StyleRulesCallback<CssRules> = theme => ({
65 marginBottom: theme.spacing.unit * 2,
69 const InputItem = withStyles(styles)(
70 (props: WithStyles<CssRules> & { input: CommandInputParameter }) =>
71 <Grid item xs={12} md={6} className={props.classes.inputItem}>
72 {getInputComponent(props.input)}
75 const getInputComponent = (input: CommandInputParameter) => {
77 case isPrimitiveOfType(input, CWLType.BOOLEAN):
78 return <BooleanInput input={input as BooleanCommandInputParameter} />;
80 case isPrimitiveOfType(input, CWLType.INT):
81 case isPrimitiveOfType(input, CWLType.LONG):
82 return <IntInput input={input as IntCommandInputParameter} />;
84 case isPrimitiveOfType(input, CWLType.FLOAT):
85 case isPrimitiveOfType(input, CWLType.DOUBLE):
86 return <FloatInput input={input as FloatCommandInputParameter} />;
88 case isPrimitiveOfType(input, CWLType.STRING):
89 return <StringInput input={input as StringCommandInputParameter} />;
91 case isPrimitiveOfType(input, CWLType.FILE):
92 return <FileInput options={{ showOnlyOwned: false, showOnlyWritable: false }} input={input as FileCommandInputParameter} />;
94 case isPrimitiveOfType(input, CWLType.DIRECTORY):
95 return <DirectoryInput options={{ showOnlyOwned: false, showOnlyWritable: false }} input={input as DirectoryCommandInputParameter} />;
97 case typeof input.type === 'object' &&
98 !(input.type instanceof Array) &&
99 input.type.type === 'enum':
100 return <EnumInput input={input as EnumCommandInputParameter} />;
102 case isArrayOfType(input, CWLType.STRING):
103 return <StringArrayInput input={input as StringArrayCommandInputParameter} />;
105 case isArrayOfType(input, CWLType.INT):
106 case isArrayOfType(input, CWLType.LONG):
107 return <IntArrayInput input={input as IntArrayCommandInputParameter} />;
109 case isArrayOfType(input, CWLType.FLOAT):
110 case isArrayOfType(input, CWLType.DOUBLE):
111 return <FloatArrayInput input={input as FloatArrayCommandInputParameter} />;
113 case isArrayOfType(input, CWLType.FILE):
114 return <FileArrayInput options={{ showOnlyOwned: false, showOnlyWritable: false }} input={input as FileArrayCommandInputParameter} />;
116 case isArrayOfType(input, CWLType.DIRECTORY):
117 return <DirectoryArrayInput options={{ showOnlyOwned: false, showOnlyWritable: false }} input={input as DirectoryArrayCommandInputParameter} />;