Extract IntInput's getValidation function
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Thu, 29 Nov 2018 13:35:47 +0000 (14:35 +0100)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Thu, 29 Nov 2018 13:35:47 +0000 (14:35 +0100)
Feature #14524

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

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

index cac8a27c7d31896344eb1e6886af46d568003e4b..32ebeb75c27bc8ee6be8ed186b5051a5dcff0ab0 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';
@@ -19,16 +20,19 @@ 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);
 
 const format = (value: any) => isNaN(value) ? '' : JSON.stringify(value);
 
+const getValidation = memoize(
+    (input: IntCommandInputParameter) => ([
+        isRequiredInput(input)
+            ? isInteger
+            : () => undefined,
+    ]));
+
 const InputComponent = (props: GenericInputProps) =>
     <GenericInput
         component={Input}