Skip to content
Snippets Groups Projects
Commit 3312c4f6 authored by Johanna Szepanski's avatar Johanna Szepanski
Browse files

CE-2461: Display alerts in badge

parent cebd6839
No related branches found
No related tags found
2 merge requests!497CE-2790: Prepare for 4.0.0,!457CE-2461: Display alerts in badge
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={
......
...@@ -6,7 +6,7 @@ const { AfterAsync } = composeStories(stories); ...@@ -6,7 +6,7 @@ const { AfterAsync } = composeStories(stories);
const textColumns = ["IOC name", "Description", "Host", "Network"]; const textColumns = ["IOC name", "Description", "Host", "Network"];
const columns = ["Status"].concat(textColumns); const columns = ["Status"].concat(textColumns);
const firstRowData = [ const firstRowData = [
"Alert", "Alert 1 warnings1 errors !",
"VacS-RFQ:SC-IOC-130", "VacS-RFQ:SC-IOC-130",
"Some description", "Some description",
"vacs-accv-vm-ioc", "vacs-accv-vm-ioc",
...@@ -39,7 +39,7 @@ describe("IOCTable", () => { ...@@ -39,7 +39,7 @@ describe("IOCTable", () => {
.each(($el, index) => { .each(($el, index) => {
if (index === 0) { if (index === 0) {
const iconTitle = firstRowData[index]; const iconTitle = firstRowData[index];
cy.wrap($el).findByRole("img", { name: iconTitle }); cy.wrap($el).findByRole("cell", { name: iconTitle });
} else { } else {
cy.wrap($el) cy.wrap($el)
.find("p") .find("p")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment