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, Button
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';
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;
84 doHidePanel?: () => void;
88 type ProcessInformationCardProps = ProcessInformationCardDataProps & WithStyles<CssRules, true>;
90 export const ProcessInformationCard = withStyles(styles, { withTheme: true })(
91 ({ classes, process, onContextMenu, theme, openProcessInputDialog, navigateToOutput, openWorkflow, cancelProcess, doHidePanel, panelName }: ProcessInformationCardProps) => {
92 const { container } = process;
93 const startedAt = container ? formatDate(container.startedAt) : 'N/A';
94 const finishedAt = container ? formatDate(container.finishedAt) : 'N/A';
95 return <Card className={classes.card}>
98 content: classes.title,
99 avatar: classes.avatar
101 avatar={<ProcessIcon className={classes.iconHeader} />}
104 {process.container && process.container.state === ContainerState.RUNNING &&
105 <span className={classes.cancelButton} onClick={() => cancelProcess(process.containerRequest.uuid)}>Cancel</span>}
106 <Chip label={getProcessStatus(process)}
107 className={classes.chip}
108 style={{ backgroundColor: getProcessStatusColor(getProcessStatus(process), theme as ArvadosTheme) }} />
109 <Tooltip title="More options" disableFocusListener>
111 aria-label="More options"
112 onClick={event => onContextMenu(event)}>
117 <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
118 <Button onClick={doHidePanel}><CloseIcon /></Button>
123 <Tooltip title={process.containerRequest.name} placement="bottom-start">
124 <Typography noWrap variant='h6' color='inherit'>
125 {process.containerRequest.name}
130 <Tooltip title={getDescription(process)} placement="bottom-start">
131 <Typography noWrap variant='body1' color='inherit'>
132 {getDescription(process)}
135 <CardContent className={classes.content}>
138 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
141 <DetailsAttribute classLabel={classes.label} classValue={classes.value}
143 value={finishedAt} />
144 {process.containerRequest.properties.workflowUuid &&
145 <span onClick={() => openWorkflow(process.containerRequest.properties.workflowUuid)}>
146 <DetailsAttribute classLabel={classes.label} classValue={classNames(classes.value, classes.link)}
147 label='Workflow' value={process.containerRequest.properties.workflowName} />
151 <span onClick={() => navigateToOutput(process.containerRequest.outputUuid!)}>
152 <DetailsAttribute classLabel={classes.link} label='Outputs' />
154 <span onClick={() => openProcessInputDialog(process.containerRequest.uuid)}>
155 <DetailsAttribute classLabel={classes.link} label='Inputs' />
164 const getDescription = (process: Process) =>
165 process.containerRequest.description || '(no-description)';