Send new user data to server
[arvados-workbench2.git] / src / views / run-process-panel / inputs / boolean-input.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { BooleanCommandInputParameter } from '~/models/workflow';
7 import { Field } from 'redux-form';
8 import { Switch } from '@material-ui/core';
9 import { GenericInputProps, GenericInput } from './generic-input';
10
11 export interface BooleanInputProps {
12     input: BooleanCommandInputParameter;
13 }
14 export const BooleanInput = ({ input }: BooleanInputProps) =>
15     <Field
16         name={input.id}
17         commandInput={input}
18         component={BooleanInputComponent}
19         normalize={(value, prevValue) => !prevValue}
20     />;
21
22 const BooleanInputComponent = (props: GenericInputProps) =>
23     <GenericInput
24         component={Input}
25         {...props} />;
26
27 const Input = (props: GenericInputProps) =>
28     <Switch
29         color='primary'
30         checked={props.input.value}
31         onChange={() => props.input.onChange(props.input.value)} 
32         disabled={props.commandInput.disabled} />;