information-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 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
18 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
19
20 type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'content' | 'chip' | 'headerText' | 'link';
21
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
23     card: {
24         marginBottom: theme.spacing.unit * 2,
25         width: '60%'
26     },
27     iconHeader: {
28         fontSize: '1.875rem',
29         color: theme.customs.colors.green700
30     },
31     label: {
32         fontSize: '0.875rem',
33     },
34     value: {
35         textTransform: 'none',
36         fontSize: '0.875rem'
37     },
38     content: {
39         display: 'flex',
40         paddingBottom: '0px ',
41         paddingTop: '0px',
42         '&:last-child': {
43             paddingBottom: '0px ',
44         }
45     },
46     link: {
47         fontSize: '0.875rem',
48         color: theme.palette.primary.main,
49         '&:hover': {
50             cursor: 'pointer'
51         }
52     },
53     chip: {
54         height: theme.spacing.unit * 2.5,
55         width: theme.spacing.unit * 12,
56         backgroundColor: theme.customs.colors.green700,
57         color: theme.palette.common.white,
58         fontSize: '0.875rem',
59         borderRadius: theme.spacing.unit * 0.625
60     },
61     headerText: {
62         fontSize: '0.875rem',
63         position: 'relative',
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 } = 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={this.handleContextMenu}>
96                                     <MoreOptionsIcon />
97                                 </IconButton>
98                             }
99                             title="Pipeline template that generates a config file from a template" />
100                         <CardContent className={classes.content}>
101                             <Grid container direction="column">
102                                 <Grid item xs={8}>
103                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
104                                         label='Status' value={<Chip label="Complete" className={classes.chip} />} />
105                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
106                                         label='Started at' value="1:25 PM 3/23/2018" />
107                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
108                                         label='Finished at' value='1:25 PM 3/23/2018' />
109                                 </Grid>
110                             </Grid>
111                             <Grid container direction="column">
112                                 <Grid item xs={8}>
113                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
114                                         label='Container output' />
115                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
116                                         label='Show inputs' />
117                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
118                                         label='Show command' />
119                                 </Grid>
120                             </Grid>
121                         </CardContent>
122                         <span className={classes.headerText}>This container request was created from the workflow <span className={classes.link}>FastQC MultiQC</span></span>
123                     </Card>
124                 </div>;
125             }
126
127             handleContextMenu = (event: React.MouseEvent<any>) => {
128                 // const { uuid, name, description } = this.props.item;
129                 const resource = {
130                     uuid: '',
131                     name: '',
132                     description: '',
133                     kind: ContextMenuKind.PROCESS
134                 };
135                 this.props.dispatch<any>(openContextMenu(event, resource));
136             }
137         }
138     )
139 );