Skip to content
Snippets Groups Projects

CE-2461: Display alerts in badge

Merged Johanna Szepanski requested to merge CE-2461-display-alerts-in-badge into develop
2 files
+ 61
25
Compare changes
  • Side-by-side
  • Inline
Files
2
import React from "react";
import React from "react";
import { Typography, useTheme, Stack } from "@mui/material";
import { Typography, useTheme, Stack, Badge } from "@mui/material";
import {
import {
Brightness1,
Brightness1,
StopCircle,
StopCircle,
Error,
RadioButtonUnchecked,
RadioButtonUnchecked,
ErrorOutline,
HelpOutline,
HelpOutline,
PlayCircleFilled,
PlayCircleFilled,
PauseCircleFilled
PauseCircleFilled
@@ -14,13 +12,25 @@ import Popover from "../../common/Popover";
@@ -14,13 +12,25 @@ import Popover from "../../common/Popover";
import { AlertBanner } from "@ess-ics/ce-ui-common";
import { AlertBanner } from "@ess-ics/ce-ui-common";
import LabeledIcon from "../../common/LabeledIcon/LabeledIcon";
import LabeledIcon from "../../common/LabeledIcon/LabeledIcon";
 
const STATUS = {
 
active: "active",
 
disabled: "disabled",
 
alert: "alert",
 
inactive: "inactive",
 
inactiveAlert: "inactive alert"
 
};
 
 
const SEVERITY = {
 
info: "info"
 
};
 
function AlertMessagesPopoverContents({ title, alerts }) {
function AlertMessagesPopoverContents({ title, alerts }) {
// Filter out INFO level alerts
// Filter out INFO level alerts
// And for now filter out links on alerts due to issues with
// And for now filter out links on alerts due to issues with
// focus behavior of popovers
// focus behavior of popovers
// Also normalize the type to lowercase since AlertBanner expects lowercase
// Also normalize the type to lowercase since AlertBanner expects lowercase
const sanitizedAlerts = (
const sanitizedAlerts = (
alerts?.filter((alert) => alert?.type.toLowerCase() !== "info") || []
alerts?.filter((alert) => alert?.type.toLowerCase() !== SEVERITY.info) || []
).map((alert) => ({
).map((alert) => ({
...alert,
...alert,
type: alert?.type?.toLowerCase(),
type: alert?.type?.toLowerCase(),
@@ -57,25 +67,25 @@ export function IOCStatusIcon({ ioc }) {
@@ -57,25 +67,25 @@ export function IOCStatusIcon({ ioc }) {
const alertSeverity = ioc?.alertSeverity?.toLowerCase();
const alertSeverity = ioc?.alertSeverity?.toLowerCase();
const iconConfig = {
const iconConfig = {
active: {
[STATUS.active]: {
title: "Active",
title: "Active",
icon: Brightness1
icon: Brightness1
},
},
disabled: {
[STATUS.disabled]: {
title: "Disabled",
title: "Disabled",
icon: StopCircle
icon: StopCircle
},
},
alert: {
[STATUS.alert]: {
title: "Alert",
title: "Alert",
icon: Error
icon: Brightness1
},
},
inactive: {
[STATUS.inactive]: {
title: "Inactive",
title: "Inactive",
icon: RadioButtonUnchecked
icon: RadioButtonUnchecked
},
},
"inactive alert": {
[STATUS.inactiveAlert]: {
title: "Alert",
title: "Alert",
icon: ErrorOutline
icon: RadioButtonUnchecked
},
},
null: {
null: {
title: "Unknown",
title: "Unknown",
@@ -89,44 +99,61 @@ export function IOCStatusIcon({ ioc }) {
@@ -89,44 +99,61 @@ export function IOCStatusIcon({ ioc }) {
active = undefined;
active = undefined;
}
}
if (active && (alertSeverity === undefined || alertSeverity === "info")) {
if (
 
active &&
 
(alertSeverity === undefined || alertSeverity === SEVERITY.info)
 
) {
// Active status / running
// Active status / running
status = "active";
status = STATUS.active;
} else if (
} else if (
active === false &&
active === false &&
(alertSeverity === undefined || alertSeverity === "info")
(alertSeverity === undefined || alertSeverity === SEVERITY.info)
) {
) {
// stopped/paused
// stopped/paused
status = "disabled";
status = STATUS.disabled;
} else if (
} else if (
active !== undefined &&
active !== undefined &&
alertSeverity !== undefined &&
alertSeverity !== undefined &&
alertSeverity !== "info"
alertSeverity !== SEVERITY.info
) {
) {
// warning/error
// warning/error
status = "alert";
status = STATUS.alert;
} else if (
} else if (
(active === undefined || activeDeployment === null) &&
(active === undefined || activeDeployment === null) &&
(alertSeverity === undefined || alertSeverity === "info")
(alertSeverity === undefined || alertSeverity === SEVERITY.info)
) {
) {
// Inactive status
// Inactive status
status = "inactive";
status = STATUS.inactive;
} else if (
} else if (
(active === undefined || activeDeployment === null) &&
(active === undefined || activeDeployment === null) &&
alertSeverity !== undefined &&
alertSeverity !== undefined &&
alertSeverity !== "info"
alertSeverity !== SEVERITY.info
) {
) {
// inactive with warning/error
// inactive with warning/error
status = "inactive alert";
status = STATUS.inactiveAlert;
} else {
} else {
// unknown fallback state
// unknown fallback state
status = null;
status = null;
}
}
const iconTitle = iconConfig[status].title;
const iconTitle = iconConfig[status].title;
 
 
const getLabel = () => {
 
if (status === STATUS.alert || status === STATUS.inactiveAlert) {
 
const warnings = alerts.filter((alert) => alert.type === "WARNING");
 
const errors = alerts.filter((alert) => alert.type === "ERROR");
 
const hasWarnings = Boolean(warnings.length);
 
const hasErrors = Boolean(errors.length);
 
return `${iconTitle} ${hasWarnings ? warnings.length + " warnings" : ""}${
 
hasErrors ? errors.length + " errors" : ""
 
}`;
 
}
 
return iconTitle;
 
};
 
const statusIcon = (
const statusIcon = (
<LabeledIcon
<LabeledIcon
label={iconTitle}
label={getLabel()}
Icon={iconConfig[status].icon}
Icon={iconConfig[status].icon}
labelPosition="none"
labelPosition="none"
/>
/>
@@ -149,7 +176,16 @@ export function IOCStatusIcon({ ioc }) {
@@ -149,7 +176,16 @@ export function IOCStatusIcon({ ioc }) {
onMouseLeave={handlePopoverClose}
onMouseLeave={handlePopoverClose}
style={{ color: theme.palette.status.icons }}
style={{ color: theme.palette.status.icons }}
>
>
{statusIcon}
{status === STATUS.alert || status === STATUS.inactiveAlert ? (
 
<Badge
 
badgeContent={"!"}
 
color="error"
 
>
 
{statusIcon}
 
</Badge>
 
) : (
 
statusIcon
 
)}
</div>
</div>
)}
)}
popoverContents={
popoverContents={
Loading