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';
19 import { ProcessRuntimeStatus } from 'views-components/process-runtime-status/process-runtime-status';
21 type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'chip' | 'link' | 'content' | 'title' | 'avatar' | 'cancelButton' | 'header';
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
28 paddingTop: theme.spacing.unit,
29 paddingBottom: theme.spacing.unit,
33 color: theme.customs.colors.green700,
36 alignSelf: 'flex-start',
37 paddingTop: theme.spacing.unit * 0.5
41 justifyContent: 'flex-start',
43 marginRight: theme.spacing.unit * 3,
44 paddingRight: theme.spacing.unit
47 textTransform: 'none',
52 color: theme.palette.primary.main,
58 height: theme.spacing.unit * 3,
59 width: theme.spacing.unit * 12,
60 color: theme.palette.common.white,
62 borderRadius: theme.spacing.unit * 0.625,
66 paddingLeft: theme.spacing.unit * 1,
67 paddingRight: theme.spacing.unit * 1,
69 paddingBottom: theme.spacing.unit * 1,
74 paddingTop: theme.spacing.unit * 0.5
77 paddingRight: theme.spacing.unit * 2,
79 color: theme.customs.colors.red900,
86 export interface ProcessInformationCardDataProps {
88 onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
89 openProcessInputDialog: (uuid: string) => void;
90 navigateToOutput: (uuid: string) => void;
91 openWorkflow: (uuid: string) => void;
92 cancelProcess: (uuid: string) => void;
95 type ProcessInformationCardProps = ProcessInformationCardDataProps & WithStyles<CssRules, true> & MPVPanelProps;
97 export const ProcessInformationCard = withStyles(styles, { withTheme: true })(
98 ({ classes, process, onContextMenu, theme, openProcessInputDialog, navigateToOutput, openWorkflow, cancelProcess, doHidePanel, panelName }: ProcessInformationCardProps) => {
99 const { container } = process;
100 const startedAt = container ? formatDate(container.startedAt) : 'N/A';
101 const finishedAt = container ? formatDate(container.finishedAt) : 'N/A';
102 return <Card className={classes.card}>
104 className={classes.header}
106 content: classes.title,
107 avatar: classes.avatar
109 avatar={<ProcessIcon className={classes.iconHeader} />}
112 {process.container && process.container.state === ContainerState.RUNNING &&
113 <span className={classes.cancelButton} onClick={() => cancelProcess(process.containerRequest.uuid)}>Cancel</span>}
114 <Chip label={getProcessStatus(process)}
115 className={classes.chip}
116 style={{ backgroundColor: getProcessStatusColor(getProcessStatus(process), theme as ArvadosTheme) }} />
117 <Tooltip title="More options" disableFocusListener>
119 aria-label="More options"
120 onClick={event => onContextMenu(event)}>
125 <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
126 <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
130 title={ !!process.containerRequest.name &&
131 <Typography noWrap variant='h6' color='inherit'>
132 {process.containerRequest.name}
136 <Typography noWrap variant='body1' color='inherit'>
137 {process.containerRequest.description}
141 <CardContent className={classes.content}>
144 <ProcessRuntimeStatus runtimeStatus={process.container?.runtimeStatus} />
147 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
150 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
152 value={finishedAt} />
153 {process.containerRequest.properties.workflowUuid &&
154 <span onClick={() => openWorkflow(process.containerRequest.properties.workflowUuid)}>
155 <DetailsAttribute classLabel={classes.label} classValue={classNames(classes.value, classes.link)}
156 label='Workflow' value={process.containerRequest.properties.workflowName} />
160 <span onClick={() => navigateToOutput(process.containerRequest.outputUuid!)}>
161 <DetailsAttribute classLabel={classes.link} label='Outputs' />
163 <span onClick={() => openProcessInputDialog(process.containerRequest.uuid)}>
164 <DetailsAttribute classLabel={classes.link} label='Inputs' />