3c6b525d628f4dd583954b171455b56307d69cfa
[arvados-workbench2.git] / src / views-components / process-runtime-status / process-runtime-status.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import {
7     ExpansionPanel,
8     ExpansionPanelDetails,
9     ExpansionPanelSummary,
10     StyleRulesCallback,
11     Typography,
12     withStyles,
13     WithStyles
14 } from "@material-ui/core";
15 import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
16 import { RuntimeStatus } from "models/runtime-status";
17 import { ArvadosTheme } from 'common/custom-theme';
18 import classNames from 'classnames';
19
20 type CssRules = 'heading'
21     | 'summary'
22     | 'details'
23     | 'detailsText'
24     | 'error'
25     | 'errorColor'
26     | 'warning'
27     | 'warningColor';
28
29 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
30     heading: {
31         fontSize: '1rem',
32     },
33     summary: {
34         paddingLeft: theme.spacing.unit * 1,
35         paddingRight: theme.spacing.unit * 1,
36     },
37     details: {
38         paddingLeft: theme.spacing.unit * 1,
39         paddingRight: theme.spacing.unit * 1,
40     },
41     detailsText: {
42         fontSize: '0.8rem',
43         marginTop: '0px',
44         marginBottom: '0px',
45         whiteSpace: 'pre-line',
46     },
47     errorColor: {
48         color: theme.customs.colors.red900,
49     },
50     error: {
51         backgroundColor: theme.customs.colors.red100,
52
53     },
54     warning: {
55         backgroundColor: theme.customs.colors.yellow100,
56     },
57     warningColor: {
58         color: theme.customs.colors.yellow900,
59     },
60 });
61 export interface ProcessRuntimeStatusDataProps {
62     runtimeStatus: RuntimeStatus | undefined;
63 }
64
65 type ProcessRuntimeStatusProps = ProcessRuntimeStatusDataProps & WithStyles<CssRules>;
66
67 export const ProcessRuntimeStatus = withStyles(styles)(
68     ({ runtimeStatus, classes }: ProcessRuntimeStatusProps) => {
69     return <>
70         { runtimeStatus?.error &&
71         <div data-cy='process-runtime-status-error'><ExpansionPanel className={classes.error} elevation={0}>
72             <ExpansionPanelSummary className={classes.summary} expandIcon={<ExpandMoreIcon />}>
73                 <Typography className={classNames(classes.heading, classes.errorColor)}>
74                     {`Error: ${runtimeStatus.error }`}
75                 </Typography>
76             </ExpansionPanelSummary>
77             <ExpansionPanelDetails className={classes.details}>
78                 <Typography className={classNames(classes.errorColor, classes.detailsText)}>
79                     {runtimeStatus?.errorDetail || 'No additional error details available'}
80                 </Typography>
81             </ExpansionPanelDetails>
82         </ExpansionPanel></div>
83         }
84         { runtimeStatus?.warning &&
85         <div data-cy='process-runtime-status-warning' ><ExpansionPanel className={classes.warning} elevation={0}>
86             <ExpansionPanelSummary className={classes.summary} expandIcon={<ExpandMoreIcon />}>
87                 <Typography className={classNames(classes.heading, classes.warningColor)}>
88                     {`Warning: ${runtimeStatus.warning }`}
89                 </Typography>
90             </ExpansionPanelSummary>
91             <ExpansionPanelDetails className={classes.details}>
92                 <Typography className={classNames(classes.warningColor, classes.detailsText)}>
93                     {runtimeStatus?.warningDetail || 'No additional warning details available'}
94                 </Typography>
95             </ExpansionPanelDetails>
96         </ExpansionPanel></div>
97         }
98     </>
99 });