X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2f320e4890a5c74bda5d10fedf6011d23585a4b0..4db2f095ecbf66553a4c29ad44f5cdd18da33cfd:/src/views/run-process-panel/inputs/int-input.tsx diff --git a/src/views/run-process-panel/inputs/int-input.tsx b/src/views/run-process-panel/inputs/int-input.tsx index 60a49b61f5..3273f35458 100644 --- a/src/views/run-process-panel/inputs/int-input.tsx +++ b/src/views/run-process-panel/inputs/int-input.tsx @@ -3,10 +3,12 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { IntCommandInputParameter, getInputLabel, isRequiredInput } from '~/models/workflow'; +import { memoize } from 'lodash/fp'; +import { IntCommandInputParameter, isRequiredInput } from '~/models/workflow'; import { Field } from 'redux-form'; -import { TextField } from '~/components/text-field/text-field'; import { isInteger } from '~/validators/is-integer'; +import { GenericInputProps, GenericInput } from '~/views/run-process-panel/inputs/generic-input'; +import { IntInput as IntInputComponent } from '~/components/int-input/int-input'; export interface IntInputProps { input: IntCommandInputParameter; @@ -14,13 +16,34 @@ export interface IntInputProps { export const IntInput = ({ input }: IntInputProps) => parseInt(value, 10)} - format={value => isNaN(value) ? '' : JSON.stringify(value)} - validate={[ - isRequiredInput(input) - ? isInteger - : () => undefined, - ]} />; + commandInput={input} + component={InputComponent} + parse={parse} + format={format} + validate={getValidation(input)} />; + +export const parse = (value: any) => value === '' ? '' : parseInt(value, 10); + +export const format = (value: any) => isNaN(value) ? '' : JSON.stringify(value); + +const getValidation = memoize( + (input: IntCommandInputParameter) => ([ + isRequiredInput(input) + ? isInteger + : () => undefined, + ])); + +const InputComponent = (props: GenericInputProps) => + ; + + +const Input = (props: GenericInputProps) => + ;