Merge branch '13776-update-process-status-calculation'
[arvados-workbench2.git] / src / components / subprocess-filter / subprocess-filter.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 { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
7 import { ArvadosTheme } from '~/common/custom-theme';
8 import { Grid, Typography, Switch } from '@material-ui/core';
9
10 type CssRules = 'grid' | 'label' | 'value' | 'switch';
11
12 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
13     grid: {
14         display: 'flex'
15     },
16     label: {
17         width: '86px',
18         color: theme.palette.grey["500"],
19         textAlign: 'right'
20     },
21     value: {
22         width: '24px',
23         paddingLeft: theme.spacing.unit
24     },
25     switch: {
26         '& span:first-child': {
27             height: '18px'
28         }
29     }
30 });
31
32 export interface SubprocessFilterDataProps {
33     label: string;
34     value: number;
35     checked?: boolean;
36     key?: string;
37     onToggle?: () => void;
38 }
39
40 type SubprocessFilterProps = SubprocessFilterDataProps & WithStyles<CssRules>;
41
42 export const SubprocessFilter = withStyles(styles)(
43     ({ classes, label, value, key, checked, onToggle }: SubprocessFilterProps) =>
44         <Grid item className={classes.grid} md={12} lg={6} >
45             <Typography component="span" className={classes.label}>{label}:</Typography>
46             <Typography component="span" className={classes.value}>{value}</Typography>
47             {onToggle && <Switch classes={{ root: classes.switch }}
48                 checked={checked}
49                 onChange={onToggle}
50                 value={key}
51                 color="primary" />
52             }
53         </Grid>
54 );