merge master
[arvados-workbench2.git] / src / views / process-panel / process-subprocesses-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, Typography, Tooltip
9 } from '@material-ui/core';
10 import * as classnames from "classnames";
11 import { ArvadosTheme } from '~/common/custom-theme';
12 import { MoreOptionsIcon } from '~/components/icon/icon';
13 import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
14 import { getBackgroundColorStatus } from '~/views/process-panel/process-panel-root';
15
16 export type CssRules = 'label' | 'value' | 'title' | 'content' | 'action' | 'options' | 'status' | 'rightSideHeader' | 'titleHeader'
17     | 'header' | 'headerActive' | 'headerCompleted' | 'headerQueued' | 'headerFailed' | 'headerCanceled';
18
19 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
20     label: {
21         fontSize: '0.875rem',
22     },
23     value: {
24         textTransform: 'none',
25         fontSize: '0.875rem',
26     },
27     title: {
28         overflow: 'hidden'
29     },
30     content: {
31         paddingTop: theme.spacing.unit * 0.5,
32         '&:last-child': {
33             paddingBottom: 0
34         }
35     },
36     action: {
37         marginTop: 0
38     },
39     options: {
40         width: theme.spacing.unit * 4,
41         height: theme.spacing.unit * 4,
42         color: theme.palette.common.white,
43     },
44     status: {
45         paddingTop: theme.spacing.unit * 0.5,
46         color: theme.palette.common.white,
47     },
48     rightSideHeader: {
49         display: 'flex'
50     },
51     titleHeader: {
52         color: theme.palette.common.white,
53         fontWeight: 600
54     },
55     header: {
56         paddingTop: 0,
57         paddingBottom: 0,
58     },
59     headerActive: {
60         backgroundColor: theme.customs.colors.blue500,
61     },
62     headerCompleted: {
63         backgroundColor: theme.customs.colors.green700,
64     },
65     headerQueued: {
66         backgroundColor: theme.customs.colors.grey500,
67     },
68     headerFailed: {
69         backgroundColor: theme.customs.colors.red900,
70     },
71     headerCanceled: {
72         backgroundColor: theme.customs.colors.red900,
73     },
74 });
75
76 export interface ProcessSubprocessesCardDataProps {
77     onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
78     items: any;
79 }
80
81 type ProcessSubprocessesCardProps = ProcessSubprocessesCardDataProps & WithStyles<CssRules>;
82
83 export const ProcessSubprocessesCard = withStyles(styles)(
84     ({ classes, onContextMenu, items }: ProcessSubprocessesCardProps) => {
85         return <Card>
86             <CardHeader
87                 className={classnames([classes.header, getBackgroundColorStatus(items.status, classes)])}
88                 classes={{ content: classes.title, action: classes.action }}
89                 action={
90                     <div className={classes.rightSideHeader}>
91                         <Typography noWrap variant="body2" className={classes.status}>
92                             {items.status}
93                         </Typography>
94                         <IconButton
95                             className={classes.options}
96                             aria-label="More options"
97                             onClick={event => onContextMenu(event)}>
98                             <MoreOptionsIcon />
99                         </IconButton>
100                     </div>
101                 }
102                 title={
103                     <Tooltip title={items.title}>
104                         <Typography noWrap variant="body2" className={classes.titleHeader}>
105                             {items.title}
106                         </Typography>
107                     </Tooltip>
108                 } />
109             <CardContent className={classes.content}>
110                 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
111                     label='Runtime' value="0h 2m" />
112             </CardContent>
113         </Card>;
114     });