clean code
[arvados-workbench2.git] / src / views / process-panel / process-panel.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 {
7     StyleRulesCallback, WithStyles, withStyles, Card,
8     CardHeader, IconButton, CardContent, Grid, Chip
9 } from '@material-ui/core';
10 import { ArvadosTheme } from '~/common/custom-theme';
11 import { ProcessResource } from '~/models/process';
12 import { DispatchProp, connect } from 'react-redux';
13 import { RouteComponentProps } from 'react-router';
14 import { MoreOptionsIcon, ProcessIcon } from '~/components/icon/icon';
15 import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
16 import { RootState } from '~/store/store';
17
18 type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'content' | 'chip' | 'headerText' | 'link';
19
20 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
21     card: {
22         marginBottom: theme.spacing.unit * 2,
23         width: '60%'
24     },
25     iconHeader: {
26         fontSize: '1.875rem',
27         color: theme.customs.colors.green700
28     },
29     label: {
30         fontSize: '0.875rem',
31     },
32     value: {
33         textTransform: 'none',
34         fontSize: '0.875rem'
35     },
36     content: {
37         display: 'flex',
38         paddingBottom: '0px ',
39         paddingTop: '0px',
40         '&:last-child': {
41             paddingBottom: '0px ',
42         }
43     },
44     link: {
45         fontSize: '0.875rem',
46         '&:hover': {
47             color: theme.palette.primary.main,
48             cursor: 'pointer'
49         }
50     },
51     chip: {
52         height: theme.spacing.unit * 2.5,
53         width: theme.spacing.unit * 12,
54         backgroundColor: theme.customs.colors.green700,
55         color: theme.palette.common.white,
56         fontSize: '0.875rem',
57         borderRadius: theme.spacing.unit * 0.625
58     },
59     headerText: {
60         fontSize: '0.875rem',
61         display: 'flex',
62         position: 'relative',
63         justifyContent: 'flex-start',
64         top: -theme.spacing.unit * 4.5,
65         left: theme.spacing.unit * 3,
66     }
67 });
68
69 interface ProcessPanelDataProps {
70     item: ProcessResource;
71 }
72
73 interface ProcessPanelActionProps {
74     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProcessResource) => void;
75 }
76
77 type ProcessPanelProps = ProcessPanelDataProps & ProcessPanelActionProps & DispatchProp & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
78
79 export const ProcessPanel = withStyles(styles)(
80     connect((state: RootState) => ({
81         item: state.collectionPanel.item,
82         tags: state.collectionPanel.tags
83     }))(
84         class extends React.Component<ProcessPanelProps> {
85             render() {
86                 const { classes, onContextMenu, item } = this.props;
87
88                 return <div>
89                     <Card className={classes.card}>
90                         <CardHeader
91                             avatar={<ProcessIcon className={classes.iconHeader} />}
92                             action={
93                                 <IconButton
94                                     aria-label="More options"
95                                     onClick={event => onContextMenu(event, item)}>
96                                     <MoreOptionsIcon />
97                                 </IconButton>
98                             }
99                             title="Pipeline template that generates a config file from a template"
100                              />
101                         <CardContent className={classes.content}>
102                             <Grid container direction="column">
103                                 <Grid item xs={8}>
104                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
105                                         label='Status' value={<Chip label="Complete" className={classes.chip} />} />
106                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
107                                         label='Started at' value="1:25 PM 3/23/2018" />
108                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
109                                         label='Finished at' value='1:25 PM 3/23/2018' />
110                                 </Grid>
111                             </Grid>
112                             <Grid container direction="column">
113                                 <Grid item xs={8}>
114                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
115                                         label='Container output' />
116                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
117                                         label='Show inputs' />
118                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
119                                         label='Show command' />
120                                 </Grid>
121                             </Grid>
122                         </CardContent>
123                         <span className={classes.headerText}>This container request was created from the workflow FastQC MultiQC</span>
124                     </Card>
125                 </div>;
126             }
127         }
128     )
129 );