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