Merge branch '13858-process-view-information-card' into 13860-status-for-subprocesses
[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' | '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 ProcessInformationCardProps = ProcessInformationCardDataProps & DispatchProp & WithStyles<CssRules>;
70
71 export const ProcessInformationCard = withStyles(styles)(
72     connect((state: RootState) => ({
73         item: state.collectionPanel.item
74     }))(
75         class extends React.Component<ProcessInformationCardProps> {
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} label='Outputs' />
104                                     <DetailsAttribute classLabel={classes.link} label='Inputs' />
105                                 </Grid>
106                             </Grid>
107                         </CardContent>
108                     </Card>
109                 </div>;
110             }
111
112             handleContextMenu = (event: React.MouseEvent<any>) => {
113                 const resource = {
114                     uuid: '',
115                     name: '',
116                     description: '',
117                     kind: ContextMenuKind.PROCESS
118                 };
119                 this.props.dispatch<any>(openContextMenu(event, resource));
120             }
121         }
122     )
123 );