Init string array input
[arvados.git] / src / views / run-process-panel / inputs / string-array-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 { isRequiredInput, StringArrayCommandInputParameter } from '~/models/workflow';
7 import { Field } from 'redux-form';
8 import { ERROR_MESSAGE } from '~/validators/require';
9 import { GenericInputProps, GenericInput } from '~/views/run-process-panel/inputs/generic-input';
10 import { ChipsInput } from '../../../components/chips-input/chips-input';
11
12 export interface StringArrayInputProps {
13     input: StringArrayCommandInputParameter;
14 }
15 export const StringArrayInput = ({ input }: StringArrayInputProps) =>
16     <Field
17         name={input.id}
18         commandInput={input}
19         component={StringArrayInputComponent}
20         validate={[
21             isRequiredInput(input)
22                 ? (value: string[]) => value.length > 0 ? undefined : ERROR_MESSAGE
23                 : () => undefined,
24         ]} />;
25
26 const StringArrayInputComponent = (props: GenericInputProps) =>
27     <GenericInput
28         component={Input}
29         {...props} />;
30
31 const Input = (props: GenericInputProps) =>
32     <ChipsInput
33         values={props.input.value}
34         onChange={props.input.onChange}
35         createNewValue={v => v} />;