Merge branch '14524-run-a-process-white-screen'
[arvados-workbench2.git] / src / views / run-process-panel / inputs / boolean-input.tsx
index d3b93662bc119fadb3ffb77d56a4c76e39dd9b35..6a214e9dd846aa0a6907bbefbdfd6cc47e7680e2 100644 (file)
@@ -3,6 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
+import { memoize } from 'lodash/fp';
 import { BooleanCommandInputParameter } from '~/models/workflow';
 import { Field } from 'redux-form';
 import { Switch } from '@material-ui/core';
@@ -26,9 +27,13 @@ const BooleanInputComponent = (props: GenericInputProps) =>
         component={Input}
         {...props} />;
 
-const Input = (props: GenericInputProps) =>
+const Input = ({ input, commandInput }: GenericInputProps) =>
     <Switch
         color='primary'
-        checked={props.input.value}
-        onChange={() => props.input.onChange(props.input.value)} 
-        disabled={props.commandInput.disabled} />;
\ No newline at end of file
+        checked={input.value}
+        onChange={handleChange(input.onChange, input.value)}
+        disabled={commandInput.disabled} />;
+
+const handleChange = memoize(
+    (onChange: (value: string) => void, value: string) => () => onChange(value)
+);