info-card-view
[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';
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     chip: {
45         height: theme.spacing.unit * 2.5,
46         width: theme.spacing.unit * 12,
47         backgroundColor: theme.customs.colors.green700,
48         color: theme.palette.common.white,
49         fontSize: '0.875rem',
50         borderRadius: theme.spacing.unit * 0.625
51     },
52     headerText: {
53         fontSize: '0.875rem',
54         display: 'flex',
55         position: 'relative',
56         justifyContent: 'flex-end',
57         top: -theme.spacing.unit * 4.5,
58         right: theme.spacing.unit * 2,
59     }
60 });
61
62 interface ProcessPanelDataProps {
63     item: ProcessResource;
64 }
65
66 interface ProcessPanelActionProps {
67     onItemRouteChange: (processId: string) => void;
68     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProcessResource) => void;
69 }
70
71 type ProcessPanelProps = ProcessPanelDataProps & ProcessPanelActionProps & DispatchProp & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
72
73 export const ProcessPanel = withStyles(styles)(
74     connect((state: RootState) => ({
75         item: state.collectionPanel.item,
76         tags: state.collectionPanel.tags
77     }))(
78         class extends React.Component<ProcessPanelProps> {
79             render() {
80                 const { classes, onContextMenu, item } = this.props;
81
82                 return <div>
83                     <Card className={classes.card}>
84                         <CardHeader
85                             avatar={<ProcessIcon className={classes.iconHeader} />}
86                             action={
87                                 <IconButton
88                                     aria-label="More options"
89                                     onClick={event => onContextMenu(event, item)}>
90                                     <MoreOptionsIcon />
91                                 </IconButton>
92                             }
93                             title="Pipeline template that generates a config file from a template"
94                              />
95                         <CardContent className={classes.content}>
96                             <Grid container direction="column">
97                                 <Grid item xs={8}>
98                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
99                                         label='Status' value={<Chip label="Complete" className={classes.chip} />} />
100                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
101                                         label='Started at' value="1:25 PM 3/23/2018" />
102                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
103                                         label='Finished at' value='1:25 PM 3/23/2018' />
104                                 </Grid>
105                             </Grid>
106                             <Grid container direction="column">
107                                 <Grid item xs={8}>
108                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
109                                         label='Container output' />
110                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
111                                         label='Show inputs' />
112                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
113                                         label='Show command' />
114                                 </Grid>
115                             </Grid>
116                         </CardContent>
117                         <span className={classes.headerText}>This container request was created from the workflow FastQC MultiQC</span>
118                     </Card>
119                 </div>;
120             }
121             componentWillReceiveProps({ match, item, onItemRouteChange }: ProcessPanelProps) {
122                 if (!item || match.params.id !== item.uuid) {
123                     onItemRouteChange(match.params.id);
124                 }
125             }
126         }
127     )
128 );