1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as 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 { 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 * as classNames from 'classnames';
17 import { ContainerState } from '~/models/container';
19 type CssRules = 'card' | 'iconHeader' | 'label' | 'value' | 'chip' | 'link' | 'content' | 'title' | 'avatar' | 'cancelButton';
21 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
27 color: theme.customs.colors.green700,
30 alignSelf: 'flex-start',
31 paddingTop: theme.spacing.unit * 0.5
35 justifyContent: 'flex-end',
37 marginRight: theme.spacing.unit * 3,
38 paddingRight: theme.spacing.unit
41 textTransform: 'none',
46 color: theme.palette.primary.main,
52 height: theme.spacing.unit * 3,
53 width: theme.spacing.unit * 12,
54 color: theme.palette.common.white,
56 borderRadius: theme.spacing.unit * 0.625,
60 paddingBottom: theme.spacing.unit * 2,
65 paddingTop: theme.spacing.unit * 0.5
68 paddingRight: theme.spacing.unit * 2,
70 color: theme.customs.colors.red900,
77 export interface ProcessInformationCardDataProps {
79 onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
80 openProcessInputDialog: (uuid: string) => void;
81 navigateToOutput: (uuid: string) => void;
82 openWorkflow: (uuid: string) => void;
83 cancelProcess: (uuid: string) => void;
86 type ProcessInformationCardProps = ProcessInformationCardDataProps & WithStyles<CssRules, true>;
88 export const ProcessInformationCard = withStyles(styles, { withTheme: true })(
89 ({ classes, process, onContextMenu, theme, openProcessInputDialog, navigateToOutput, openWorkflow, cancelProcess }: ProcessInformationCardProps) => {
90 const { container } = process;
91 const startedAt = container ? formatDate(container.startedAt) : 'N/A';
92 const finishedAt = container ? formatDate(container.finishedAt) : 'N/A';
93 return <Card className={classes.card}>
96 content: classes.title,
97 avatar: classes.avatar
99 avatar={<ProcessIcon className={classes.iconHeader} />}
102 {process.container && process.container.state === ContainerState.RUNNING &&
103 <span className={classes.cancelButton} onClick={() => cancelProcess(process.containerRequest.uuid)}>Cancel</span>}
104 <Chip label={getProcessStatus(process)}
105 className={classes.chip}
106 style={{ backgroundColor: getProcessStatusColor(getProcessStatus(process), theme as ArvadosTheme) }} />
107 <Tooltip title="More options" disableFocusListener>
109 aria-label="More options"
110 onClick={event => onContextMenu(event)}>
117 <Tooltip title={process.containerRequest.name} placement="bottom-start">
118 <Typography noWrap variant='h6' color='inherit'>
119 {process.containerRequest.name}
124 <Tooltip title={getDescription(process)} placement="bottom-start">
125 <Typography noWrap variant='body1' color='inherit'>
126 {getDescription(process)}
129 <CardContent className={classes.content}>
132 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
135 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
137 value={finishedAt} />
138 {process.containerRequest.properties.workflowUuid &&
139 <span onClick={() => openWorkflow(process.containerRequest.properties.workflowUuid)}>
140 <DetailsAttribute classLabel={classes.label} classValue={classNames(classes.value, classes.link)}
141 label='Workflow' value={process.containerRequest.properties.workflowName} />
145 <span onClick={() => navigateToOutput(process.containerRequest.outputUuid!)}>
146 <DetailsAttribute classLabel={classes.link} label='Outputs' />
148 <span onClick={() => openProcessInputDialog(process.containerRequest.uuid)}>
149 <DetailsAttribute classLabel={classes.link} label='Inputs' />
158 const getDescription = (process: Process) =>
159 process.containerRequest.description || '(no-description)';