X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/8a85c509e4f2100082cfed6157d31c8651b861c9..fa9e1f065eefa7265879869e4b45eb76be64b4ce:/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 aeaf6cdd..a5905dc5 100644
--- a/src/views/run-process-panel/inputs/float-input.tsx
+++ b/src/views/run-process-panel/inputs/float-input.tsx
@@ -3,12 +3,12 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as 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 { GenericInput } from '~/views/run-process-panel/inputs/generic-input';
-import { Input as MaterialInput } from '@material-ui/core';
-import { GenericInputProps } from './generic-input';
+import { GenericInputProps, GenericInput } from './generic-input';
+import { FloatInput as FloatInputComponent } from '~/components/float-input/float-input';
 export interface FloatInputProps {
     input: FloatCommandInputParameter;
 }
@@ -16,39 +16,29 @@ export const FloatInput = ({ input }: FloatInputProps) =>
     <Field
         name={input.id}
         commandInput={input}
-        component={FloatInputComponent}
+        component={Input}
         parse={parseFloat}
-        format={value => isNaN(value) ? '' : JSON.stringify(value)}
-        validate={[
-            isRequiredInput(input)
-                ? isNumber
-                : () => undefined,]} />;
+        format={format}
+        validate={getValidation(input)} />;
 
-class FloatInputComponent extends React.Component<GenericInputProps> {
-    state = {
-        endsWithDecimalSeparator: false,
-    };
+const format = (value: any) => isNaN(value) ? '' : JSON.stringify(value);
 
-    handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
-        const [base, fraction] = event.target.value.split('.');
-        this.setState({ endsWithDecimalSeparator: fraction === '' });
-        this.props.input.onChange(event);
-    }
-
-    render() {
-        const props = {
-            ...this.props,
-            input: {
-                ...this.props.input,
-                value: this.props.input.value + (this.state.endsWithDecimalSeparator ? '.' : ''),
-                onChange: this.handleChange,
-            },
-        };
-        return <GenericInput
-            component={Input}
-            {...props} />;
-    }
-}
+const getValidation = memoize(
+    (input: FloatCommandInputParameter) => ([
+        isRequiredInput(input)
+            ? isNumber
+            : () => undefined,])
+);
 
 const Input = (props: GenericInputProps) =>
-    <MaterialInput fullWidth {...props.input} error={props.meta.touched && !!props.meta.error} />;
+    <GenericInput
+        component={InputComponent}
+        {...props} />;
+
+const InputComponent = ({ input, meta, commandInput }: GenericInputProps) =>
+    <FloatInputComponent
+        fullWidth
+        error={meta.touched && !!meta.error}
+        disabled={commandInput.disabled}
+        {...input} />;
+
