merge master
[arvados-workbench2.git] / src / views / process-panel / process-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, Typography, Tooltip
9 } from '@material-ui/core';
10 import * as classnames from "classnames";
11 import { ArvadosTheme } from '~/common/custom-theme';
12 import { MoreOptionsIcon, ProcessIcon } from '~/components/icon/icon';
13 import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
14 import { Process } from '~/store/processes/process';
15 import { getProcessStatus } from '~/store/processes/process';
16 import { getBackgroundColorStatus } from '~/views/process-panel/process-panel-root';
17
18 type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'chip' | 'link' | 'content' | 'title' | 'avatar'
19     | 'headerActive' | 'headerCompleted' | 'headerQueued' | 'headerFailed' | 'headerCanceled';
20
21 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
22     card: {
23         marginBottom: theme.spacing.unit * 2
24     },
25     iconHeader: {
26         fontSize: '1.875rem',
27         color: theme.customs.colors.green700,
28     },
29     avatar: {
30         alignSelf: 'flex-start',
31         paddingTop: theme.spacing.unit * 0.5
32     },
33     label: {
34         display: 'flex',
35         justifyContent: 'flex-end',
36         fontSize: '0.875rem',
37         marginRight: theme.spacing.unit * 3,
38         paddingRight: theme.spacing.unit
39     },
40     value: {
41         textTransform: 'none',
42         fontSize: '0.875rem',
43     },
44     link: {
45         fontSize: '0.875rem',
46         color: theme.palette.primary.main,
47         '&:hover': {
48             cursor: 'pointer'
49         }
50     },
51     chip: {
52         height: theme.spacing.unit * 3,
53         width: theme.spacing.unit * 12,
54         color: theme.palette.common.white,
55         fontSize: '0.875rem',
56         borderRadius: theme.spacing.unit * 0.625,
57     },
58     content: {
59         '&:last-child': {
60             paddingBottom: theme.spacing.unit * 2,
61             paddingTop: '0px'
62         }
63     },
64     title: {
65         overflow: 'hidden',
66         paddingTop: theme.spacing.unit * 0.5
67     },
68     headerActive: {
69         backgroundColor: theme.customs.colors.blue500,
70     },
71     headerCompleted: {
72         backgroundColor: theme.customs.colors.green700,
73     },
74     headerQueued: {
75         backgroundColor: theme.customs.colors.grey500,
76     },
77     headerFailed: {
78         backgroundColor: theme.customs.colors.red900,
79     },
80     headerCanceled: {
81         backgroundColor: theme.customs.colors.red900,
82     },
83 });
84
85 export interface ProcessInformationCardDataProps {
86     process: Process;
87     onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
88 }
89
90 type ProcessInformationCardProps = ProcessInformationCardDataProps & WithStyles<CssRules>;
91
92 export const ProcessInformationCard = withStyles(styles)(
93     ({ classes, process, onContextMenu }: ProcessInformationCardProps) =>
94         <Card className={classes.card}>
95             <CardHeader
96                 classes={{
97                     content: classes.title,
98                     avatar: classes.avatar
99                 }}
100                 avatar={<ProcessIcon className={classes.iconHeader} />}
101                 action={
102                     <div>
103                         <Chip label={getProcessStatus(process)}
104                             className={classnames([classes.chip, getBackgroundColorStatus(getProcessStatus(process), classes)])} />
105                         <IconButton
106                             aria-label="More options"
107                             onClick={event => onContextMenu(event)}>
108                             <MoreOptionsIcon />
109                         </IconButton>
110                     </div>
111                 }
112                 title={
113                     <Tooltip title={process.containerRequest.name}>
114                         <Typography noWrap variant="title">
115                            {process.containerRequest.name}
116                         </Typography>
117                     </Tooltip>
118                 }
119                 subheader={process.containerRequest.description} />
120             <CardContent className={classes.content}>
121                 <Grid container>
122                     <Grid item xs={6}>
123                         <DetailsAttribute classLabel={classes.label} classValue={classes.value}
124                             label='From' value={process.container ? process.container.startedAt : 'N/A'} />
125                         <DetailsAttribute classLabel={classes.label} classValue={classes.value}
126                             label='To' value={process.container ? process.container.finishedAt : 'N/A'} />
127                         <DetailsAttribute classLabel={classes.label} classValue={classes.link}
128                             label='Workflow' value='???' />
129                     </Grid>
130                     <Grid item xs={6}>
131                         <DetailsAttribute classLabel={classes.link} label='Outputs' />
132                         <DetailsAttribute classLabel={classes.link} label='Inputs' />
133                     </Grid>
134                 </Grid>
135             </CardContent>
136         </Card>
137 );