Send new user data to server
[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, isRequiredInput } from '~/models/workflow';
7 import { Field } from 'redux-form';
8 import { isInteger } from '~/validators/is-integer';
9 import { GenericInputProps, GenericInput } from '~/views/run-process-panel/inputs/generic-input';
10 import { IntInput as IntInputComponent } from '~/components/int-input/int-input';
11
12 export interface IntInputProps {
13     input: IntCommandInputParameter;
14 }
15 export const IntInput = ({ input }: IntInputProps) =>
16     <Field
17         name={input.id}
18         commandInput={input}
19         component={InputComponent}
20         parse={value => parseInt(value, 10)}
21         format={value => isNaN(value) ? '' : JSON.stringify(value)}
22         validate={[
23             isRequiredInput(input)
24                 ? isInteger
25                 : () => undefined,
26         ]} />;
27
28 const InputComponent = (props: GenericInputProps) =>
29     <GenericInput
30         component={Input}
31         {...props} />;
32
33
34 const Input = (props: GenericInputProps) =>
35     <IntInputComponent
36         fullWidth
37         type='number'
38         error={props.meta.touched && !!props.meta.error}
39         disabled={props.commandInput.disabled}
40         {...props.input} />;
41