create subprocesses card
[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 import { SubprocessesCard } from '~/views/process-panel/subprocesses-card';
20
21 type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'content' | 'chip' | 'headerText' | 'link';
22
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
24     card: {
25         marginBottom: theme.spacing.unit * 2,
26         width: '60%'
27     },
28     iconHeader: {
29         fontSize: '1.875rem',
30         color: theme.customs.colors.green700
31     },
32     label: {
33         fontSize: '0.875rem',
34     },
35     value: {
36         textTransform: 'none',
37         fontSize: '0.875rem'
38     },
39     content: {
40         display: 'flex',
41         paddingBottom: '0px ',
42         paddingTop: '0px',
43         '&:last-child': {
44             paddingBottom: '0px ',
45         }
46     },
47     link: {
48         fontSize: '0.875rem',
49         '&:hover': {
50             color: theme.palette.primary.main,
51             cursor: 'pointer'
52         }
53     },
54     chip: {
55         height: theme.spacing.unit * 2.5,
56         width: theme.spacing.unit * 12,
57         backgroundColor: theme.customs.colors.green700,
58         color: theme.palette.common.white,
59         fontSize: '0.875rem',
60         borderRadius: theme.spacing.unit * 0.625
61     },
62     headerText: {
63         fontSize: '0.875rem',
64         display: 'flex',
65         position: 'relative',
66         justifyContent: 'flex-start',
67         top: -theme.spacing.unit * 4.5,
68         left: theme.spacing.unit * 3,
69     }
70 });
71
72 interface ProcessPanelDataProps {
73     item: ProcessResource;
74 }
75
76 interface ProcessPanelActionProps {
77     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: ProcessResource) => void;
78 }
79
80 type ProcessPanelProps = ProcessPanelDataProps & ProcessPanelActionProps & DispatchProp & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
81
82 export const ProcessPanel = withStyles(styles)(
83     connect((state: RootState) => ({
84         item: state.collectionPanel.item,
85         tags: state.collectionPanel.tags
86     }))(
87         class extends React.Component<ProcessPanelProps> {
88             render() {
89                 const { classes } = this.props;
90
91                 return <div>
92                     <Card className={classes.card}>
93                         <CardHeader
94                             avatar={<ProcessIcon className={classes.iconHeader} />}
95                             action={
96                                 <IconButton
97                                     aria-label="More options"
98                                     onClick={this.handleContextMenu}>
99                                     <MoreOptionsIcon />
100                                 </IconButton>
101                             }
102                             title="Pipeline template that generates a config file from a template" />
103                         <CardContent className={classes.content}>
104                             <Grid container direction="column">
105                                 <Grid item xs={8}>
106                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
107                                         label='Status' value={<Chip label="Complete" className={classes.chip} />} />
108                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
109                                         label='Started at' value="1:25 PM 3/23/2018" />
110                                     <DetailsAttribute classLabel={classes.label} classValue={classes.value}
111                                         label='Finished at' value='1:25 PM 3/23/2018' />
112                                 </Grid>
113                             </Grid>
114                             <Grid container direction="column">
115                                 <Grid item xs={8}>
116                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
117                                         label='Container output' />
118                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
119                                         label='Show inputs' />
120                                     <DetailsAttribute classLabel={classes.link} classValue={classes.value}
121                                         label='Show command' />
122                                 </Grid>
123                             </Grid>
124                         </CardContent>
125                         <span className={classes.headerText}>This container request was created from the workflow FastQC MultiQC</span>
126                     </Card>
127                     <SubprocessesCard />
128                 </div>;
129             }
130
131             handleContextMenu = (event: React.MouseEvent<any>) => {
132                 // const { uuid, name, description } = this.props.item;
133                 const resource = {
134                     uuid: '',
135                     name: '',
136                     description: '',
137                     kind: ContextMenuKind.PROCESS
138                 };
139                 this.props.dispatch<any>(openContextMenu(event, resource));
140             }
141         }
142     )
143 );