16086: Don't re-parse dates on process information card.
[arvados-workbench2.git] / src / views / run-process-panel / inputs / int-input.tsx
index 6758bae6023253d403872c4e0b60ac996136ac46..3273f35458c5e0aedd214ec838f60e7d4189592f 100644 (file)
@@ -3,6 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as 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';
@@ -18,14 +19,19 @@ export const IntInput = ({ input }: IntInputProps) =>
         commandInput={input}
         component={InputComponent}
         parse={parse}
-        format={value => isNaN(value) ? '' : JSON.stringify(value)}
-        validate={[
-            isRequiredInput(input)
-                ? isInteger
-                : () => undefined,
-        ]} />;
-
-const parse = (value: any) => parseInt(value, 10);
+        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) =>
     <GenericInput