X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/424f5418a6fd9f49baa1cc79bf0b51f9ab65ac58..3c7e3cdc547ad5468421e1c049daa94b0d4b8bc0:/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 193de26c..aa4fe9bb 100644 --- a/src/views/run-process-panel/inputs/int-input.tsx +++ b/src/views/run-process-panel/inputs/int-input.tsx @@ -2,12 +2,13 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; -import { IntCommandInputParameter, getInputLabel, isRequiredInput } from '~/models/workflow'; +import React from 'react'; +import { memoize } from 'lodash/fp'; +import { IntCommandInputParameter, isRequiredInput } from 'models/workflow'; import { Field } from 'redux-form'; -import { isInteger } from '~/validators/is-integer'; -import { GenericInputProps, GenericInput } from '~/views/run-process-panel/inputs/generic-input'; -import { Input as MaterialInput } from '@material-ui/core'; +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; @@ -16,21 +17,33 @@ export const IntInput = ({ input }: IntInputProps) => parseInt(value, 10)} - format={value => isNaN(value) ? '' : JSON.stringify(value)} - validate={[ - isRequiredInput(input) - ? isInteger - : () => undefined, - ]} />; - -const IntInputComponent = (props: GenericInputProps) => + 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) => - ; + ;