X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cfff00494c45cb6f8a53373a64d72dbd2fe8cd85..b04ed9ad5145bf8335cc5749b3d2f0ac166ef60f:/src/views/run-process-panel/inputs/float-input.tsx

diff --git a/src/views/run-process-panel/inputs/float-input.tsx b/src/views/run-process-panel/inputs/float-input.tsx
index 664425d3ae..14b06fd459 100644
--- a/src/views/run-process-panel/inputs/float-input.tsx
+++ b/src/views/run-process-panel/inputs/float-input.tsx
@@ -2,44 +2,43 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { getInputLabel, FloatCommandInputParameter } from '~/models/workflow';
-import { Field, WrappedFieldProps } from 'redux-form';
-import { TextField } from '~/components/text-field/text-field';
-import { isNumber } from '~/validators/is-number';
+import React from 'react';
+import { memoize } from 'lodash/fp';
+import { FloatCommandInputParameter, isRequiredInput } from 'models/workflow';
+import { Field } from 'redux-form';
+import { isNumber } from 'validators/is-number';
+import { GenericInputProps, GenericInput } from './generic-input';
+import { FloatInput as FloatInputComponent } from 'components/float-input/float-input';
 export interface FloatInputProps {
     input: FloatCommandInputParameter;
 }
 export const FloatInput = ({ input }: FloatInputProps) =>
     <Field
         name={input.id}
-        label={getInputLabel(input)}
-        component={DecimalInput}
+        commandInput={input}
+        component={Input}
         parse={parseFloat}
-        format={value => isNaN(value) ? '' : JSON.stringify(value)}
-        validate={[isNumber]} />;
+        format={format}
+        validate={getValidation(input)} />;
 
+const format = (value: any) => isNaN(value) ? '' : JSON.stringify(value);
 
-class DecimalInput extends React.Component<WrappedFieldProps & { label?: string }> {
-    state = {
-        endsWithDecimalSeparator: false,
-    };
+const getValidation = memoize(
+    (input: FloatCommandInputParameter) => ([
+        isRequiredInput(input)
+            ? isNumber
+            : () => undefined,])
+);
 
-    handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
-        const [base, fraction] = event.target.value.split('.');
-        this.setState({ endsWithDecimalSeparator: fraction === '' });
-        this.props.input.onChange(event);
-    }
+const Input = (props: GenericInputProps) =>
+    <GenericInput
+        component={InputComponent}
+        {...props} />;
+
+const InputComponent = ({ input, meta, commandInput }: GenericInputProps) =>
+    <FloatInputComponent
+        fullWidth
+        error={meta.touched && !!meta.error}
+        disabled={commandInput.disabled}
+        {...input} />;
 
-    render() {
-        const props = {
-            ...this.props,
-            input: {
-                ...this.props.input,
-                value: this.props.input.value + (this.state.endsWithDecimalSeparator ? '.' : ''),
-                onChange: this.handleChange,
-            },
-        };
-        return <TextField {...props} />;
-    }
-}
