15088: Removes navigation after second login
[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 { ArvadosTheme } from '~/common/custom-theme';
11 import { MoreOptionsIcon } from '~/components/icon/icon';
12 import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
13 import { Process, getProcessStatus, getProcessRuntime } from '~/store/processes/process';
14 import { formatTime } from '~/common/formatters';
15 import { getProcessStatusColor } from '~/store/processes/process';
16
17 export type CssRules = 'label' | 'value' | 'title' | 'content' | 'action' | 'options' | 'status' | 'rightSideHeader' | 'titleHeader' | 'header' | 'moreOptions';
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.75,
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     moreOptions: {
60         position: 'absolute'
61     }
62 });
63
64 export interface SubprocessItemProps {
65     title: string;
66     status: string;
67     runtime?: string;
68 }
69
70 export interface ProcessSubprocessesCardDataProps {
71     onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
72     subprocess: Process;
73 }
74
75 type ProcessSubprocessesCardProps = ProcessSubprocessesCardDataProps & WithStyles<CssRules, true>;
76
77 export const ProcessSubprocessesCard = withStyles(styles, { withTheme: true })(
78     ({ classes, onContextMenu, subprocess, theme }: ProcessSubprocessesCardProps) => {
79         return <Card>
80             <CardHeader
81                 className={classes.header}
82                 style={{ backgroundColor: getProcessStatusColor(getProcessStatus(subprocess), theme as ArvadosTheme) }}
83                 classes={{ content: classes.title, action: classes.action }}
84                 action={
85                     <div className={classes.rightSideHeader}>
86                         <Typography noWrap variant='body1' className={classes.status}>
87                             {getProcessStatus(subprocess)}
88                         </Typography>
89                         <Tooltip title="More options" disableFocusListener>
90                             <IconButton
91                                 className={classes.options}
92                                 aria-label="More options"
93                                 onClick={onContextMenu}>
94                                 <MoreOptionsIcon className={classes.moreOptions} />
95                             </IconButton>
96                         </Tooltip>
97                     </div>
98                 }
99                 title={
100                     <Tooltip title={subprocess.containerRequest.name}>
101                         <Typography noWrap variant='body1' className={classes.titleHeader}>
102                             {subprocess.containerRequest.name}
103                         </Typography>
104                     </Tooltip>
105                 } />
106             <CardContent className={classes.content}>
107                 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
108                     label="Runtime" value={subprocess.container && subprocess.container.startedAt && subprocess.container.finishedAt
109                         ? formatTime(getProcessRuntime(subprocess)) :
110                         '(none)'} />
111             </CardContent>
112         </Card>;
113     });