added side-panel-reducer file, minor code cleanup Arvados-DCO-1.1-Signed-off-by:...
[arvados.git] / src / views / process-panel / process-details-card.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import {
7     StyleRulesCallback,
8     WithStyles,
9     withStyles,
10     Card,
11     CardHeader,
12     IconButton,
13     CardContent,
14     Tooltip,
15     Typography,
16 } from '@material-ui/core';
17 import { ArvadosTheme } from 'common/custom-theme';
18 import { CloseIcon, MoreOptionsIcon, ProcessIcon } from 'components/icon/icon';
19 import { Process } from 'store/processes/process';
20 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
21 import { ProcessDetailsAttributes } from './process-details-attributes';
22 import { ProcessStatus } from 'views-components/data-explorer/renderers';
23 import { ContainerState } from 'models/container';
24
25 type CssRules = 'card' | 'content' | 'title' | 'header' | 'cancelButton' | 'avatar' | 'iconHeader';
26
27 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
28     card: {
29         height: '100%'
30     },
31     header: {
32         paddingTop: theme.spacing.unit,
33         paddingBottom: theme.spacing.unit,
34     },
35     iconHeader: {
36         fontSize: '1.875rem',
37         color: theme.customs.colors.green700,
38     },
39     avatar: {
40         alignSelf: 'flex-start',
41         paddingTop: theme.spacing.unit * 0.5
42     },
43     content: {
44         padding: theme.spacing.unit * 1.0,
45         paddingTop: theme.spacing.unit * 0.5,
46         '&:last-child': {
47             paddingBottom: theme.spacing.unit * 1,
48         }
49     },
50     title: {
51         overflow: 'hidden',
52         paddingTop: theme.spacing.unit * 0.5
53     },
54     cancelButton: {
55         paddingRight: theme.spacing.unit * 2,
56         fontSize: '14px',
57         color: theme.customs.colors.red900,
58         "&:hover": {
59             cursor: 'pointer'
60         }
61     },
62 });
63
64 export interface ProcessDetailsCardDataProps {
65     process: Process;
66     cancelProcess: (uuid: string) => void;
67     onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
68 }
69
70 type ProcessDetailsCardProps = ProcessDetailsCardDataProps & WithStyles<CssRules> & MPVPanelProps;
71
72 export const ProcessDetailsCard = withStyles(styles)(
73     ({ cancelProcess, onContextMenu, classes, process, doHidePanel, panelName }: ProcessDetailsCardProps) => {
74         return <Card className={classes.card}>
75             <CardHeader
76                 className={classes.header}
77                 classes={{
78                     content: classes.title,
79                     avatar: classes.avatar,
80                 }}
81                 avatar={<ProcessIcon className={classes.iconHeader} />}
82                 title={
83                     <Tooltip title={process.containerRequest.name} placement="bottom-start">
84                         <Typography noWrap variant='h6' color='inherit'>
85                             {process.containerRequest.name}
86                         </Typography>
87                     </Tooltip>
88                 }
89                 subheader={
90                     <Tooltip title={getDescription(process)} placement="bottom-start">
91                         <Typography noWrap variant='body1' color='inherit'>
92                             {getDescription(process)}
93                         </Typography>
94                     </Tooltip>}
95                 action={
96                     <div>
97                         {process.container && process.container.state === ContainerState.RUNNING &&
98                             <span className={classes.cancelButton} onClick={() => cancelProcess(process.containerRequest.uuid)}>Cancel</span>}
99                         <ProcessStatus uuid={process.containerRequest.uuid} />
100                         <Tooltip title="More options" disableFocusListener>
101                             <IconButton
102                                 aria-label="More options"
103                                 onClick={event => onContextMenu(event)}>
104                                 <MoreOptionsIcon />
105                             </IconButton>
106                         </Tooltip>
107                         { doHidePanel &&
108                         <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
109                             <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
110                         </Tooltip> }
111                     </div>
112                 } />
113             <CardContent className={classes.content}>
114                 <ProcessDetailsAttributes request={process.containerRequest} twoCol hideProcessPanelRedundantFields />
115             </CardContent>
116         </Card>;
117     }
118 );
119
120 const getDescription = (process: Process) =>
121     process.containerRequest.description || '(no-description)';