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, getEnumType } 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 { CustomStyleRulesCallback } from 'common/custom-theme';
17 import { Grid } from '@mui/material';
18 import { WithStyles } from '@mui/styles';
19 import withStyles from '@mui/styles/withStyles';
20 import { EnumInput } from './inputs/enum-input';
21 import { DirectoryInput } from './inputs/directory-input';
22 import { StringArrayInput } from './inputs/string-array-input';
23 import { createStructuredSelector, createSelector } from 'reselect';
24 import { FileArrayInput } from './inputs/file-array-input';
25 import { DirectoryArrayInput } from './inputs/directory-array-input';
26 import { FloatArrayInput } from './inputs/float-array-input';
27 import { IntArrayInput } from './inputs/int-array-input';
29 export const RUN_PROCESS_INPUTS_FORM = 'runProcessInputsForm';
31 export interface RunProcessInputFormProps {
32 inputs: CommandInputParameter[];
35 const inputsSelector = (props: RunProcessInputFormProps) =>
38 const initialValuesSelector = createSelector(
40 inputs => inputs.reduce(
41 (values, input) => ({ ...values, [input.id]: input.value || input.default }),
44 const propsSelector = createStructuredSelector({
45 initialValues: initialValuesSelector,
48 const mapStateToProps = (_: any, props: RunProcessInputFormProps) =>
51 export const RunProcessInputsForm = compose(
52 connect(mapStateToProps),
53 reduxForm<WorkflowInputsData, RunProcessInputFormProps>({
54 form: RUN_PROCESS_INPUTS_FORM
56 (props: InjectedFormProps & RunProcessInputFormProps) =>
58 <Grid container spacing={4}>
59 {props.inputs.map(input =>
60 <InputItem input={input} key={input.id} />)}
64 type CssRules = 'inputItem';
66 const styles: CustomStyleRulesCallback<CssRules> = theme => ({
68 marginBottom: theme.spacing(2),
72 const InputItem = withStyles(styles)(
73 (props: WithStyles<CssRules> & { input: CommandInputParameter }) =>
74 <Grid item xs={12} md={6} className={props.classes.inputItem}>
75 {getInputComponent(props.input)}
78 const getInputComponent = (input: CommandInputParameter) => {
80 case isPrimitiveOfType(input, CWLType.BOOLEAN):
81 return <BooleanInput input={input as BooleanCommandInputParameter} />;
83 case isPrimitiveOfType(input, CWLType.INT):
84 case isPrimitiveOfType(input, CWLType.LONG):
85 return <IntInput input={input as IntCommandInputParameter} />;
87 case isPrimitiveOfType(input, CWLType.FLOAT):
88 case isPrimitiveOfType(input, CWLType.DOUBLE):
89 return <FloatInput input={input as FloatCommandInputParameter} />;
91 case isPrimitiveOfType(input, CWLType.STRING):
92 return <StringInput input={input as StringCommandInputParameter} />;
94 case isPrimitiveOfType(input, CWLType.FILE):
95 return <FileInput options={{ showOnlyOwned: false, showOnlyWritable: false }} input={input as FileCommandInputParameter} />;
97 case isPrimitiveOfType(input, CWLType.DIRECTORY):
98 return <DirectoryInput options={{ showOnlyOwned: false, showOnlyWritable: false }} input={input as DirectoryCommandInputParameter} />;
100 case getEnumType(input) !== null:
101 return <EnumInput input={input as EnumCommandInputParameter} />;
103 case isArrayOfType(input, CWLType.STRING):
104 return <StringArrayInput input={input as StringArrayCommandInputParameter} />;
106 case isArrayOfType(input, CWLType.INT):
107 case isArrayOfType(input, CWLType.LONG):
108 return <IntArrayInput input={input as IntArrayCommandInputParameter} />;
110 case isArrayOfType(input, CWLType.FLOAT):
111 case isArrayOfType(input, CWLType.DOUBLE):
112 return <FloatArrayInput input={input as FloatArrayCommandInputParameter} />;
114 case isArrayOfType(input, CWLType.FILE):
115 return <FileArrayInput options={{ showOnlyOwned: false, showOnlyWritable: false }} input={input as FileArrayCommandInputParameter} />;
117 case isArrayOfType(input, CWLType.DIRECTORY):
118 return <DirectoryArrayInput options={{ showOnlyOwned: false, showOnlyWritable: false }} input={input as DirectoryArrayCommandInputParameter} />;