467f7278fda1214e61022d14c85422d77473e1be
[arvados-workbench2.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' | 'chip' | 'headerText' | 'link';
20
21 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
22     card: {
23         marginBottom: theme.spacing.unit * 2,
24         paddingBottom: theme.spacing.unit * 3,
25         position: 'relative'
26     },
27     iconHeader: {
28         fontSize: '1.875rem',
29         color: theme.customs.colors.green700
30     },
31     label: {
32         display: 'flex',
33         justifyContent: 'flex-end',
34         fontSize: '0.875rem',
35         marginRight: theme.spacing.unit * 3
36     },
37     value: {
38         textTransform: 'none',
39         fontSize: '0.875rem',
40     },
41     link: {
42         fontSize: '0.875rem',
43         color: theme.palette.primary.main,
44         '&:hover': {
45             cursor: 'pointer'
46         }
47     },
48     chip: {
49         height: theme.spacing.unit * 3,
50         width: theme.spacing.unit * 12,
51         backgroundColor: theme.customs.colors.green700,
52         color: theme.palette.common.white,
53         fontSize: '0.875rem',
54         borderRadius: theme.spacing.unit * 0.625,
55         position: 'absolute',
56         top: theme.spacing.unit * 2.5,
57         right: theme.spacing.unit * 8,
58     },
59     headerText: {
60         fontSize: '0.875rem',
61         marginLeft: theme.spacing.unit * 3,
62     }
63 });
64
65 interface ProcessInformationCardDataProps {
66     item: ProcessResource;
67 }
68
69 type InformationCardProps = ProcessInformationCardDataProps & DispatchProp & WithStyles<CssRules>;
70
71 export const InformationCard = withStyles(styles)(
72     connect((state: RootState) => ({
73         item: state.collectionPanel.item
74     }))(
75         class extends React.Component<InformationCardProps> {
76             render() {
77                 const { classes } = this.props;
78
79                 return <div>
80                     <Card className={classes.card}>
81                         <CardHeader
82                             avatar={<ProcessIcon className={classes.iconHeader} />}
83                             action={
84                                 <IconButton
85                                     aria-label="More options"
86                                     onClick={this.handleContextMenu}>
87                                     <MoreOptionsIcon />
88                                 </IconButton>}
89                             title="Pipeline template that generates a config file from a template"
90                             subheader="(no description)" />
91                             <Chip label="Complete" className={classes.chip} />
92                         <CardContent>
93                             <Grid container>
94                                 <Grid item xs={6}>
95                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
96                                         label='From' value="1:25 PM 3/23/2018" />
97                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
98                                         label='To' value='1:25 PM 3/23/2018' />
99                                     <DetailsAttribute classLabel={classes.label} classValue={classes.link}
100                                         label='Workflow' value='FastQC MultiQC' />
101                                 </Grid>
102                                 <Grid item xs={6}>
103                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
104                                         label='Outputs' />
105                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
106                                         label='Inputs' />
107                                 </Grid>
108                             </Grid>
109                         </CardContent>
110                     </Card>
111                 </div>;
112             }
113
114             handleContextMenu = (event: React.MouseEvent<any>) => {
115                 const resource = {
116                     uuid: '',
117                     name: '',
118                     description: '',
119                     kind: ContextMenuKind.PROCESS
120                 };
121                 this.props.dispatch<any>(openContextMenu(event, resource));
122             }
123         }
124     )
125 );