Add conditional validation detection to int and float inputs
[arvados-workbench2.git] / src / views / run-process-panel / inputs / int-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 { IntCommandInputParameter, getInputLabel, isRequiredInput } from '~/models/workflow';
7 import { Field } from 'redux-form';
8 import { TextField } from '~/components/text-field/text-field';
9 import { isInteger } from '~/validators/is-integer';
10
11 export interface IntInputProps {
12     input: IntCommandInputParameter;
13 }
14 export const IntInput = ({ input }: IntInputProps) =>
15     <Field
16         name={input.id}
17         label={getInputLabel(input)}
18         component={TextField}
19         parse={value => parseInt(value, 10)}
20         format={value => isNaN(value) ? '' : JSON.stringify(value)}
21         validate={[
22             isRequiredInput(input)
23                 ? isInteger
24                 : () => undefined,
25         ]} />;
26