Extract IntInput's parse function
[arvados-workbench2.git] / src / views / run-process-panel / inputs / int-input.tsx
index 6d0307a821065b35a2fe9e5cb07f6ae5d70da3f1..6758bae6023253d403872c4e0b60ac996136ac46 100644 (file)
@@ -3,11 +3,11 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { IntCommandInputParameter, getInputLabel, isRequiredInput } from '~/models/workflow';
+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 { IntInput as IntInputComponent } from '~/components/int-input/int-input';
 
 export interface IntInputProps {
     input: IntCommandInputParameter;
@@ -16,8 +16,8 @@ export const IntInput = ({ input }: IntInputProps) =>
     <Field
         name={input.id}
         commandInput={input}
-        component={IntInputComponent}
-        parse={value => parseInt(value, 10)}
+        component={InputComponent}
+        parse={parse}
         format={value => isNaN(value) ? '' : JSON.stringify(value)}
         validate={[
             isRequiredInput(input)
@@ -25,12 +25,19 @@ export const IntInput = ({ input }: IntInputProps) =>
                 : () => undefined,
         ]} />;
 
-const IntInputComponent = (props: GenericInputProps) =>
+const parse = (value: any) => parseInt(value, 10);
+
+const InputComponent = (props: GenericInputProps) =>
     <GenericInput
         component={Input}
         {...props} />;
 
 
 const Input = (props: GenericInputProps) =>
-    <MaterialInput type='number' {...props.input} />;
+    <IntInputComponent
+        fullWidth
+        type='number'
+        error={props.meta.touched && !!props.meta.error}
+        disabled={props.commandInput.disabled}
+        {...props.input} />;