20000: Cypress use specific selectors
[arvados.git] / src / views / process-panel / process-details-card.tsx
index 5cca904a0d53382672f1ef5183e27a182aff6069..b8990b2f56630da55e5e338023eab2e82a8c5046 100644 (file)
@@ -13,16 +13,19 @@ import {
     CardContent,
     Tooltip,
     Typography,
-    Chip,
+    Button,
 } from '@material-ui/core';
 import { ArvadosTheme } from 'common/custom-theme';
-import { CloseIcon, MoreOptionsIcon, ProcessIcon } from 'components/icon/icon';
-import { Process, getProcessStatus, getProcessStatusColor } from 'store/processes/process';
+import { CloseIcon, MoreOptionsIcon, ProcessIcon, StartIcon, StopIcon } from 'components/icon/icon';
+import { Process } from 'store/processes/process';
 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
 import { ProcessDetailsAttributes } from './process-details-attributes';
+import { ProcessStatus } from 'views-components/data-explorer/renderers';
 import { ContainerState } from 'models/container';
+import { ContainerRequestState } from 'models/container-request';
+import classNames from 'classnames';
 
-type CssRules = 'card' | 'content' | 'title' | 'header' | 'cancelButton' | 'chip' | 'avatar' | 'iconHeader';
+type CssRules = 'card' | 'content' | 'title' | 'header' | 'cancelButton' | 'avatar' | 'iconHeader' | 'actionButton';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     card: {
@@ -34,48 +37,64 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     },
     iconHeader: {
         fontSize: '1.875rem',
-        color: theme.customs.colors.green700,
+        color: theme.customs.colors.greyL,
     },
     avatar: {
         alignSelf: 'flex-start',
         paddingTop: theme.spacing.unit * 0.5
     },
     content: {
+        padding: theme.spacing.unit * 1.0,
+        paddingTop: theme.spacing.unit * 0.5,
         '&:last-child': {
-            paddingBottom: theme.spacing.unit * 2,
+            paddingBottom: theme.spacing.unit * 1,
         }
     },
     title: {
         overflow: 'hidden',
-        paddingTop: theme.spacing.unit * 0.5
+        paddingTop: theme.spacing.unit * 0.5,
+        color: theme.customs.colors.green700,
+    },
+    actionButton: {
+        padding: "0px 5px 0 0",
+        marginRight: "5px",
+        fontSize: '0.78rem',
     },
     cancelButton: {
-        paddingRight: theme.spacing.unit * 2,
-        fontSize: '14px',
         color: theme.customs.colors.red900,
-        "&:hover": {
-            cursor: 'pointer'
-        }
-    },
-    chip: {
-        height: theme.spacing.unit * 3,
-        width: theme.spacing.unit * 12,
-        color: theme.palette.common.white,
-        fontSize: '0.875rem',
-        borderRadius: theme.spacing.unit * 0.625,
+        borderColor: theme.customs.colors.red900,
+        '&:hover': {
+            borderColor: theme.customs.colors.red900,
+        },
+        '& svg': {
+            fontSize: '22px',
+        },
     },
 });
 
 export interface ProcessDetailsCardDataProps {
     process: Process;
     cancelProcess: (uuid: string) => void;
+    startProcess: (uuid: string) => void;
+    resumeOnHoldWorkflow: (uuid: string) => void;
     onContextMenu: (event: React.MouseEvent<HTMLElement>) => void;
 }
 
-type ProcessDetailsCardProps = ProcessDetailsCardDataProps & WithStyles<CssRules, true> & MPVPanelProps;
+type ProcessDetailsCardProps = ProcessDetailsCardDataProps & WithStyles<CssRules> & MPVPanelProps;
+
+export const ProcessDetailsCard = withStyles(styles)(
+    ({ cancelProcess, startProcess, resumeOnHoldWorkflow, onContextMenu, classes, process, doHidePanel, panelName }: ProcessDetailsCardProps) => {
+        let runAction: ((uuid: string) => void) | undefined = undefined;
+        if (process.containerRequest.state === ContainerRequestState.UNCOMMITTED) {
+            runAction = startProcess;
+        } else if (process.containerRequest.state === ContainerRequestState.COMMITTED &&
+                    process.containerRequest.priority === 0 &&
+                    // Don't show run button when container is present & running or cancelled
+                    !(process.container && (process.container.state === ContainerState.RUNNING ||
+                                            process.container.state === ContainerState.CANCELLED))) {
+            runAction = resumeOnHoldWorkflow;
+        }
 
-export const ProcessDetailsCard = withStyles(styles, {withTheme: true})(
-    ({ theme, cancelProcess, onContextMenu, classes, process, doHidePanel, panelName }: ProcessDetailsCardProps) => {
         return <Card className={classes.card}>
             <CardHeader
                 className={classes.header}
@@ -86,7 +105,7 @@ export const ProcessDetailsCard = withStyles(styles, {withTheme: true})(
                 avatar={<ProcessIcon className={classes.iconHeader} />}
                 title={
                     <Tooltip title={process.containerRequest.name} placement="bottom-start">
-                        <Typography noWrap variant='h6' color='inherit'>
+                        <Typography noWrap variant='h6'>
                             {process.containerRequest.name}
                         </Typography>
                     </Tooltip>
@@ -99,11 +118,34 @@ export const ProcessDetailsCard = withStyles(styles, {withTheme: true})(
                     </Tooltip>}
                 action={
                     <div>
-                        {process.container && process.container.state === ContainerState.RUNNING &&
-                            <span className={classes.cancelButton} onClick={() => cancelProcess(process.containerRequest.uuid)}>Cancel</span>}
-                        <Chip label={getProcessStatus(process)}
-                            className={classes.chip}
-                            style={{ backgroundColor: getProcessStatusColor(getProcessStatus(process), theme as ArvadosTheme) }} />
+                        {runAction !== undefined &&
+                            <Button
+                                data-cy="process-run-button"
+                                variant="contained"
+                                size="small"
+                                color="primary"
+                                className={classes.actionButton}
+                                onClick={() => runAction && runAction(process.containerRequest.uuid)}>
+                                <StartIcon />
+                                Run
+                            </Button>}
+                        {process.container &&
+                            (process.container.state === ContainerState.QUEUED ||
+                            process.container.state === ContainerState.LOCKED ||
+                            process.container.state === ContainerState.RUNNING) &&
+                            process.containerRequest.priority !== null &&
+                            process.containerRequest.priority > 0 &&
+                            <Button
+                                data-cy="process-cancel-button"
+                                variant="outlined"
+                                size="small"
+                                color="primary"
+                                className={classNames(classes.actionButton, classes.cancelButton)}
+                                onClick={() => cancelProcess(process.containerRequest.uuid)}>
+                                <StopIcon />
+                                Cancel
+                            </Button>}
+                        <ProcessStatus uuid={process.containerRequest.uuid} />
                         <Tooltip title="More options" disableFocusListener>
                             <IconButton
                                 aria-label="More options"
@@ -118,7 +160,7 @@ export const ProcessDetailsCard = withStyles(styles, {withTheme: true})(
                     </div>
                 } />
             <CardContent className={classes.content}>
-                <ProcessDetailsAttributes request={process.containerRequest} twoCol />
+                <ProcessDetailsAttributes request={process.containerRequest} twoCol hideProcessPanelRedundantFields />
             </CardContent>
         </Card>;
     }