information card in separate file
[arvados.git] / src / views / process-panel / information-card.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 { MoreOptionsIcon, ProcessIcon } from '~/components/icon/icon';
14 import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
15 import { RootState } from '~/store/store';
16 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
17 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
18
19 type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'content' | 'chip' | 'headerText' | 'link';
20
21 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
22     card: {
23         marginBottom: theme.spacing.unit * 2,
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         color: theme.palette.primary.main,
47         '&:hover': {
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         position: 'relative',
62         top: -theme.spacing.unit * 4.5,
63         left: theme.spacing.unit * 3,
64     }
65 });
66
67 interface ProcessInformationCardDataProps {
68     item: ProcessResource;
69 }
70
71 type InformationCardProps = ProcessInformationCardDataProps & DispatchProp & WithStyles<CssRules>;
72
73 export const InformationCard = withStyles(styles)(
74     connect((state: RootState) => ({
75         item: state.collectionPanel.item
76     }))(
77         class extends React.Component<InformationCardProps> {
78             render() {
79                 const { classes } = this.props;
80
81                 return <div>
82                     <Card className={classes.card}>
83                         <CardHeader
84                             avatar={<ProcessIcon className={classes.iconHeader} />}
85                             action={
86                                 <IconButton
87                                     aria-label="More options"
88                                     onClick={this.handleContextMenu}>
89                                     <MoreOptionsIcon />
90                                 </IconButton>
91                             }
92                             title="Pipeline template that generates a config file from a template" />
93                         <CardContent className={classes.content}>
94                             <Grid container direction="column">
95                                 <Grid item xs={8}>
96                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
97                                         label='Status' value={<Chip label="Complete" className={classes.chip} />} />
98                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
99                                         label='Started at' value="1:25 PM 3/23/2018" />
100                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
101                                         label='Finished at' value='1:25 PM 3/23/2018' />
102                                 </Grid>
103                             </Grid>
104                             <Grid container direction="column">
105                                 <Grid item xs={8}>
106                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
107                                         label='Container output' />
108                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
109                                         label='Show inputs' />
110                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
111                                         label='Show command' />
112                                 </Grid>
113                             </Grid>
114                         </CardContent>
115                         <span className={classes.headerText}>This container request was created from the workflow <span className={classes.link}>FastQC MultiQC</span></span>
116                     </Card>
117                 </div>;
118             }
119
120             handleContextMenu = (event: React.MouseEvent<any>) => {
121                 // const { uuid, name, description } = this.props.item;
122                 const resource = {
123                     uuid: '',
124                     name: '',
125                     description: '',
126                     kind: ContextMenuKind.PROCESS
127                 };
128                 this.props.dispatch<any>(openContextMenu(event, resource));
129             }
130         }
131     )
132 );