Merge branch 'master' into 14452-my-account
[arvados-workbench2.git] / src / views / run-process-panel / inputs / boolean-input.tsx
index 2d0d8c661138e1c52830b43d4efa83a66036c454..6a214e9dd846aa0a6907bbefbdfd6cc47e7680e2 100644 (file)
@@ -3,10 +3,11 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { BooleanCommandInputParameter, getInputLabel, isRequiredInput } from '~/models/workflow';
-import { Field, WrappedFieldProps } from 'redux-form';
-import { TextField } from '~/components/text-field/text-field';
-import { FormGroup, FormLabel, FormHelperText, Switch } from '@material-ui/core';
+import { memoize } from 'lodash/fp';
+import { BooleanCommandInputParameter } from '~/models/workflow';
+import { Field } from 'redux-form';
+import { Switch } from '@material-ui/core';
+import { GenericInputProps, GenericInput } from './generic-input';
 
 export interface BooleanInputProps {
     input: BooleanCommandInputParameter;
@@ -14,16 +15,25 @@ export interface BooleanInputProps {
 export const BooleanInput = ({ input }: BooleanInputProps) =>
     <Field
         name={input.id}
-        label={getInputLabel(input)}
+        commandInput={input}
         component={BooleanInputComponent}
-        normalize={(value, prevValue) => !prevValue}
+        normalize={normalize}
     />;
 
-const BooleanInputComponent = (props: WrappedFieldProps & { label?: string }) =>
-    <FormGroup>
-        <FormLabel>{props.label}</FormLabel>
-        <Switch
-            color='primary'
-            checked={props.input.value}
-            onChange={() => props.input.onChange(props.input.value)} />
-    </FormGroup>;
\ No newline at end of file
+const normalize = (_: any, prevValue: boolean) => !prevValue;
+
+const BooleanInputComponent = (props: GenericInputProps) =>
+    <GenericInput
+        component={Input}
+        {...props} />;
+
+const Input = ({ input, commandInput }: GenericInputProps) =>
+    <Switch
+        color='primary'
+        checked={input.value}
+        onChange={handleChange(input.onChange, input.value)}
+        disabled={commandInput.disabled} />;
+
+const handleChange = memoize(
+    (onChange: (value: string) => void, value: string) => () => onChange(value)
+);