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';
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
28 color: theme.customs.colors.green700,
31 alignSelf: 'flex-start',
32 paddingTop: theme.spacing.unit * 0.5
36 justifyContent: 'flex-end',
38 marginRight: theme.spacing.unit * 3,
39 paddingRight: theme.spacing.unit
42 textTransform: 'none',
47 color: theme.palette.primary.main,
53 height: theme.spacing.unit * 3,
54 width: theme.spacing.unit * 12,
55 color: theme.palette.common.white,
57 borderRadius: theme.spacing.unit * 0.625,
61 paddingBottom: theme.spacing.unit * 2,
66 paddingTop: theme.spacing.unit * 0.5
69 paddingRight: theme.spacing.unit * 2,
71 color: theme.customs.colors.red900,
78 export interface ProcessInformationCardDataProps {
80 onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
81 openProcessInputDialog: (uuid: string) => void;
82 navigateToOutput: (uuid: string) => void;
83 openWorkflow: (uuid: string) => void;
84 cancelProcess: (uuid: string) => void;
87 type ProcessInformationCardProps = ProcessInformationCardDataProps & WithStyles<CssRules, true> & MPVPanelProps;
89 export const ProcessInformationCard = withStyles(styles, { withTheme: true })(
90 ({ classes, process, onContextMenu, theme, openProcessInputDialog, navigateToOutput, openWorkflow, cancelProcess, doHidePanel, panelName }: ProcessInformationCardProps) => {
91 const { container } = process;
92 const startedAt = container ? formatDate(container.startedAt) : 'N/A';
93 const finishedAt = container ? formatDate(container.finishedAt) : 'N/A';
94 return <Card className={classes.card}>
97 content: classes.title,
98 avatar: classes.avatar
100 avatar={<ProcessIcon className={classes.iconHeader} />}
103 {process.container && process.container.state === ContainerState.RUNNING &&
104 <span className={classes.cancelButton} onClick={() => cancelProcess(process.containerRequest.uuid)}>Cancel</span>}
105 <Chip label={getProcessStatus(process)}
106 className={classes.chip}
107 style={{ backgroundColor: getProcessStatusColor(getProcessStatus(process), theme as ArvadosTheme) }} />
108 <Tooltip title="More options" disableFocusListener>
110 aria-label="More options"
111 onClick={event => onContextMenu(event)}>
116 <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
117 <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
122 <Tooltip title={process.containerRequest.name} placement="bottom-start">
123 <Typography noWrap variant='h6' color='inherit'>
124 {process.containerRequest.name}
129 <Tooltip title={getDescription(process)} placement="bottom-start">
130 <Typography noWrap variant='body1' color='inherit'>
131 {getDescription(process)}
134 <CardContent className={classes.content}>
137 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
140 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
142 value={finishedAt} />
143 {process.containerRequest.properties.workflowUuid &&
144 <span onClick={() => openWorkflow(process.containerRequest.properties.workflowUuid)}>
145 <DetailsAttribute classLabel={classes.label} classValue={classNames(classes.value, classes.link)}
146 label='Workflow' value={process.containerRequest.properties.workflowName} />
150 <span onClick={() => navigateToOutput(process.containerRequest.outputUuid!)}>
151 <DetailsAttribute classLabel={classes.link} label='Outputs' />
153 <span onClick={() => openProcessInputDialog(process.containerRequest.uuid)}>
154 <DetailsAttribute classLabel={classes.link} label='Inputs' />
163 const getDescription = (process: Process) =>
164 process.containerRequest.description || '(no-description)';