merge master
[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         '&:hover': {
49             color: theme.palette.primary.main,
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         display: 'flex',
64         position: 'relative',
65         justifyContent: 'flex-start',
66         top: -theme.spacing.unit * 4.5,
67         left: theme.spacing.unit * 3,
68     }
69 });
70
71 interface ProcessPanelDataProps {
72     item: ProcessResource;
73 }
74
75 interface ProcessPanelActionProps {
76     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProcessResource) => void;
77 }
78
79 type ProcessPanelProps = ProcessPanelDataProps & ProcessPanelActionProps & DispatchProp & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
80
81 export const ProcessPanel = withStyles(styles)(
82     connect((state: RootState) => ({
83         item: state.collectionPanel.item,
84         tags: state.collectionPanel.tags
85     }))(
86         class extends React.Component<ProcessPanelProps> {
87             render() {
88                 const { classes } = this.props;
89
90                 return <div>
91                     <Card className={classes.card}>
92                         <CardHeader
93                             avatar={<ProcessIcon className={classes.iconHeader} />}
94                             action={
95                                 <IconButton
96                                     aria-label="More options"
97                                     onClick={this.handleContextMenu}>
98                                     <MoreOptionsIcon />
99                                 </IconButton>
100                             }
101                             title="Pipeline template that generates a config file from a template" />
102                         <CardContent className={classes.content}>
103                             <Grid container direction="column">
104                                 <Grid item xs={8}>
105                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
106                                         label='Status' value={<Chip label="Complete" className={classes.chip} />} />
107                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
108                                         label='Started at' value="1:25 PM 3/23/2018" />
109                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
110                                         label='Finished at' value='1:25 PM 3/23/2018' />
111                                 </Grid>
112                             </Grid>
113                             <Grid container direction="column">
114                                 <Grid item xs={8}>
115                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
116                                         label='Container output' />
117                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
118                                         label='Show inputs' />
119                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
120                                         label='Show command' />
121                                 </Grid>
122                             </Grid>
123                         </CardContent>
124                         <span className={classes.headerText}>This container request was created from the workflow FastQC MultiQC</span>
125                     </Card>
126                 </div>;
127             }
128
129             handleContextMenu = (event: React.MouseEvent<any>) => {
130                 // const { uuid, name, description } = this.props.item;
131                 const resource = {
132                     uuid: '',
133                     name: '',
134                     description: '',
135                     kind: ContextMenuKind.PROCESS
136                 };
137                 this.props.dispatch<any>(openContextMenu(event, resource));
138             }
139         }
140     )
141 );