1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
17 } from '@material-ui/core';
18 import { ArvadosTheme } from 'common/custom-theme';
19 import { CloseIcon, MoreVerticalIcon, ProcessIcon, StartIcon, StopIcon } from 'components/icon/icon';
20 import { Process, isProcessRunnable, isProcessResumable, isProcessCancelable } from 'store/processes/process';
21 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
22 import { ProcessDetailsAttributes } from './process-details-attributes';
23 import { ProcessStatus } from 'views-components/data-explorer/renderers';
24 import classNames from 'classnames';
26 type CssRules = 'card' | 'content' | 'title' | 'header' | 'cancelButton' | 'avatar' | 'iconHeader' | 'actionButton';
28 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
33 paddingTop: theme.spacing.unit,
34 paddingBottom: theme.spacing.unit,
38 color: theme.customs.colors.greyL,
41 alignSelf: 'flex-start',
42 paddingTop: theme.spacing.unit * 0.5
45 padding: theme.spacing.unit * 1.0,
46 paddingTop: theme.spacing.unit * 0.5,
48 paddingBottom: theme.spacing.unit * 1,
53 paddingTop: theme.spacing.unit * 0.5,
54 color: theme.customs.colors.green700,
57 padding: "0px 5px 0 0",
62 color: theme.palette.common.white,
63 backgroundColor: theme.customs.colors.red900,
65 backgroundColor: theme.customs.colors.red900,
73 export interface ProcessDetailsCardDataProps {
75 cancelProcess: (uuid: string) => void;
76 startProcess: (uuid: string) => void;
77 resumeOnHoldWorkflow: (uuid: string) => void;
78 onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
81 type ProcessDetailsCardProps = ProcessDetailsCardDataProps & WithStyles<CssRules> & MPVPanelProps;
83 export const ProcessDetailsCard = withStyles(styles)(
84 ({ cancelProcess, startProcess, resumeOnHoldWorkflow, onContextMenu, classes, process, doHidePanel, panelName }: ProcessDetailsCardProps) => {
85 let runAction: ((uuid: string) => void) | undefined = undefined;
86 if (isProcessRunnable(process)) {
87 runAction = startProcess;
88 } else if (isProcessResumable(process)) {
89 runAction = resumeOnHoldWorkflow;
92 return <Card className={classes.card}>
94 className={classes.header}
96 content: classes.title,
97 avatar: classes.avatar,
99 avatar={<ProcessIcon className={classes.iconHeader} />}
101 <Tooltip title={process.containerRequest.name} placement="bottom-start">
102 <Typography noWrap variant='h6'>
103 {process.containerRequest.name}
108 <Tooltip title={getDescription(process)} placement="bottom-start">
109 <Typography noWrap variant='body1' color='inherit'>
110 {getDescription(process)}
115 {runAction !== undefined &&
117 data-cy="process-run-button"
121 className={classes.actionButton}
122 onClick={() => runAction && runAction(process.containerRequest.uuid)}>
126 {isProcessCancelable(process) &&
128 data-cy="process-cancel-button"
132 className={classNames(classes.actionButton, classes.cancelButton)}
133 onClick={() => cancelProcess(process.containerRequest.uuid)}>
137 <ProcessStatus uuid={process.containerRequest.uuid} />
138 <Tooltip title="More options" disableFocusListener>
140 aria-label="More options"
141 onClick={event => onContextMenu(event)}>
146 <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
147 <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
151 <CardContent className={classes.content}>
152 <ProcessDetailsAttributes request={process.containerRequest} twoCol hideProcessPanelRedundantFields />
158 const getDescription = (process: Process) =>
159 process.containerRequest.description || '(no-description)';