added side-panel-reducer file, minor code cleanup Arvados-DCO-1.1-Signed-off-by:...
[arvados.git] / src / views / keep-service-panel / keep-service-panel-root.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles, Card, CardContent, Grid, Table, TableHead, TableRow, TableCell, TableBody, Tooltip, IconButton, Checkbox } from '@material-ui/core';
7 import { ArvadosTheme } from 'common/custom-theme';
8 import { MoreOptionsIcon } from 'components/icon/icon';
9 import { KeepServiceResource } from 'models/keep-services';
10
11 type CssRules = 'root' | 'tableRow';
12
13 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
14     root: {
15         width: '100%',
16         overflow: 'auto'
17     },
18     tableRow: {
19         '& td, th': {
20             whiteSpace: 'nowrap'
21         }
22     }
23 });
24
25 export interface KeepServicePanelRootActionProps {
26     openRowOptions: (event: React.MouseEvent<HTMLElement>, keepService: KeepServiceResource) => void;
27 }
28
29 export interface KeepServicePanelRootDataProps {
30     keepServices: KeepServiceResource[];
31     hasKeepSerices: boolean;
32 }
33
34 type KeepServicePanelRootProps = KeepServicePanelRootActionProps & KeepServicePanelRootDataProps & WithStyles<CssRules>;
35
36 export const KeepServicePanelRoot = withStyles(styles)(
37     ({ classes, hasKeepSerices, keepServices, openRowOptions }: KeepServicePanelRootProps) => 
38         <Card className={classes.root}>
39             <CardContent>
40                 {hasKeepSerices && <Grid container direction="row">
41                     <Grid item xs={12}>
42                         <Table>
43                             <TableHead>
44                                 <TableRow className={classes.tableRow}>
45                                     <TableCell>UUID</TableCell>
46                                     <TableCell>Read only</TableCell>
47                                     <TableCell>Service host</TableCell>
48                                     <TableCell>Service port</TableCell>
49                                     <TableCell>Service SSL flag</TableCell>
50                                     <TableCell>Service type</TableCell>
51                                     <TableCell />
52                                 </TableRow>
53                             </TableHead>
54                             <TableBody>
55                                 {keepServices.map((keepService, index) =>
56                                     <TableRow key={index} className={classes.tableRow}>
57                                         <TableCell>{keepService.uuid}</TableCell>
58                                         <TableCell>
59                                             <Checkbox
60                                                 disableRipple
61                                                 color="primary"
62                                                 checked={keepService.readOnly} />
63                                         </TableCell>
64                                         <TableCell>{keepService.serviceHost}</TableCell>
65                                         <TableCell>{keepService.servicePort}</TableCell>
66                                         <TableCell>
67                                             <Checkbox
68                                                 disableRipple
69                                                 color="primary"
70                                                 checked={keepService.serviceSslFlag} />
71                                         </TableCell>
72                                         <TableCell>{keepService.serviceType}</TableCell>
73                                         <TableCell>
74                                             <Tooltip title="More options" disableFocusListener>
75                                                 <IconButton onClick={event => openRowOptions(event, keepService)}>
76                                                     <MoreOptionsIcon />
77                                                 </IconButton>
78                                             </Tooltip>
79                                         </TableCell>
80                                     </TableRow>)}
81                             </TableBody>
82                         </Table>
83                     </Grid>
84                 </Grid>}
85             </CardContent>
86         </Card>
87 );