Merge branch '13863-workflow-inputs-processing'
[arvados-workbench2.git] / src / views / run-process-panel / inputs / generic-input.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { WrappedFieldProps } from 'redux-form';
7 import { FormGroup, FormLabel, Input, FormHelperText, FormControl } from '@material-ui/core';
8 import { GenericCommandInputParameter, getInputLabel, isRequiredInput } from '../../../models/workflow';
9
10 export type GenericInputProps = WrappedFieldProps & {
11     commandInput: GenericCommandInputParameter<any, any>;
12 };
13
14 type GenericInputContainerProps = GenericInputProps & {
15     component: React.ComponentType<GenericInputProps>;
16 };
17 export const GenericInput = ({ component: Component, ...props }: GenericInputContainerProps) => {
18     return <FormGroup>
19         <FormLabel
20             focused={props.meta.active}
21             required={isRequiredInput(props.commandInput)}
22             error={props.meta.touched && !!props.meta.error}>
23             {getInputLabel(props.commandInput)}
24         </FormLabel>
25         <Component {...props} />
26         <FormHelperText error={props.meta.touched && !!props.meta.error}>
27             {
28                 props.meta.touched && props.meta.error
29                     ? props.meta.error
30                     : props.commandInput.doc
31             }
32         </FormHelperText>
33     </FormGroup>;
34 };