1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
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 { CloseIcon, 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 import classNames from 'classnames';
17 import { ContainerState } from 'models/container';
18 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
20 type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'chip' | 'link' | 'content' | 'title' | 'avatar' | 'cancelButton' | 'header';
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
27 paddingTop: theme.spacing.unit,
28 paddingBottom: theme.spacing.unit,
32 color: theme.customs.colors.green700,
35 alignSelf: 'flex-start',
36 paddingTop: theme.spacing.unit * 0.5
40 justifyContent: 'flex-end',
42 marginRight: theme.spacing.unit * 3,
43 paddingRight: theme.spacing.unit
46 textTransform: 'none',
51 color: theme.palette.primary.main,
57 height: theme.spacing.unit * 3,
58 width: theme.spacing.unit * 12,
59 color: theme.palette.common.white,
61 borderRadius: theme.spacing.unit * 0.625,
65 paddingBottom: theme.spacing.unit * 2,
70 paddingTop: theme.spacing.unit * 0.5
73 paddingRight: theme.spacing.unit * 2,
75 color: theme.customs.colors.red900,
82 export interface ProcessInformationCardDataProps {
84 onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
85 openProcessInputDialog: (uuid: string) => void;
86 navigateToOutput: (uuid: string) => void;
87 openWorkflow: (uuid: string) => void;
88 cancelProcess: (uuid: string) => void;
91 type ProcessInformationCardProps = ProcessInformationCardDataProps & WithStyles<CssRules, true> & MPVPanelProps;
93 export const ProcessInformationCard = withStyles(styles, { withTheme: true })(
94 ({ classes, process, onContextMenu, theme, openProcessInputDialog, navigateToOutput, openWorkflow, cancelProcess, doHidePanel, panelName }: ProcessInformationCardProps) => {
95 const { container } = process;
96 const startedAt = container ? formatDate(container.startedAt) : 'N/A';
97 const finishedAt = container ? formatDate(container.finishedAt) : 'N/A';
98 return <Card className={classes.card}>
100 className={classes.header}
102 content: classes.title,
103 avatar: classes.avatar
105 avatar={<ProcessIcon className={classes.iconHeader} />}
108 {process.container && process.container.state === ContainerState.RUNNING &&
109 <span className={classes.cancelButton} onClick={() => cancelProcess(process.containerRequest.uuid)}>Cancel</span>}
110 <Chip label={getProcessStatus(process)}
111 className={classes.chip}
112 style={{ backgroundColor: getProcessStatusColor(getProcessStatus(process), theme as ArvadosTheme) }} />
113 <Tooltip title="More options" disableFocusListener>
115 aria-label="More options"
116 onClick={event => onContextMenu(event)}>
121 <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
122 <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
127 <Tooltip title={process.containerRequest.name} placement="bottom-start">
128 <Typography noWrap variant='h6' color='inherit'>
129 {process.containerRequest.name}
134 <Tooltip title={getDescription(process)} placement="bottom-start">
135 <Typography noWrap variant='body1' color='inherit'>
136 {getDescription(process)}
139 <CardContent className={classes.content}>
142 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
145 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
147 value={finishedAt} />
148 {process.containerRequest.properties.workflowUuid &&
149 <span onClick={() => openWorkflow(process.containerRequest.properties.workflowUuid)}>
150 <DetailsAttribute classLabel={classes.label} classValue={classNames(classes.value, classes.link)}
151 label='Workflow' value={process.containerRequest.properties.workflowName} />
155 <span onClick={() => navigateToOutput(process.containerRequest.outputUuid!)}>
156 <DetailsAttribute classLabel={classes.link} label='Outputs' />
158 <span onClick={() => openProcessInputDialog(process.containerRequest.uuid)}>
159 <DetailsAttribute classLabel={classes.link} label='Inputs' />
168 const getDescription = (process: Process) =>
169 process.containerRequest.description || '(no-description)';