Update process float input to use shared FloatInput
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Sun, 21 Oct 2018 19:23:47 +0000 (21:23 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Sun, 21 Oct 2018 19:23:47 +0000 (21:23 +0200)
Feature #13862

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/views/run-process-panel/inputs/float-input.tsx

index aeaf6cdd48dd8aa4bb0d420b7a7d24e314bad7ff..9558fd8d2f1ab4c7d09cab418ce3edfb0cd8c5cc 100644 (file)
@@ -6,9 +6,8 @@ import * as React from 'react';
 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,7 +15,7 @@ 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={[
@@ -24,31 +23,11 @@ export const FloatInput = ({ input }: FloatInputProps) =>
                 ? isNumber
                 : () => undefined,]} />;
 
-class FloatInputComponent extends React.Component<GenericInputProps> {
-    state = {
-        endsWithDecimalSeparator: false,
-    };
-
-    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} />;
 
-    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 InputComponent = ({ input, meta }: GenericInputProps) =>
+    <FloatInputComponent fullWidth {...input} error={meta.touched && !!meta.error} />;
 
-const Input = (props: GenericInputProps) =>
-    <MaterialInput fullWidth {...props.input} error={props.meta.touched && !!props.meta.error} />;