17782: Fixes almost all tests (4 left) mostly by fixing namespace-type imports.
[arvados-workbench2.git] / src / views / run-process-panel / inputs / int-input.tsx
index cac8a27c7d31896344eb1e6886af46d568003e4b..aa4fe9bba658add4abeb5cb094243d3c6d6564b2 100644 (file)
@@ -2,12 +2,13 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { IntCommandInputParameter, isRequiredInput } from '~/models/workflow';
+import 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';
-import { GenericInputProps, GenericInput } from '~/views/run-process-panel/inputs/generic-input';
-import { IntInput as IntInputComponent } from '~/components/int-input/int-input';
+import { isInteger } from 'validators/is-integer';
+import { GenericInputProps, GenericInput } from 'views/run-process-panel/inputs/generic-input';
+import { IntInput as IntInputComponent } from 'components/int-input/int-input';
 
 export interface IntInputProps {
     input: IntCommandInputParameter;
@@ -19,15 +20,18 @@ export const IntInput = ({ input }: IntInputProps) =>
         component={InputComponent}
         parse={parse}
         format={format}
-        validate={[
-            isRequiredInput(input)
-                ? isInteger
-                : () => undefined,
-        ]} />;
+        validate={getValidation(input)} />;
 
-const parse = (value: any) => parseInt(value, 10);
+export const parse = (value: any) => value === '' ? '' : parseInt(value, 10);
 
-const format = (value: any) => isNaN(value) ? '' : JSON.stringify(value);
+export const format = (value: any) => isNaN(value) ? '' : JSON.stringify(value);
+
+const getValidation = memoize(
+    (input: IntCommandInputParameter) => ([
+        isRequiredInput(input)
+            ? isInteger
+            : () => undefined,
+    ]));
 
 const InputComponent = (props: GenericInputProps) =>
     <GenericInput