From 74dd9d28f72b04a01172b3ad95a017a8c351597c Mon Sep 17 00:00:00 2001
From: Johanna Szepanski <johanna.szepanski@softhouse.se>
Date: Fri, 16 Aug 2024 10:16:37 +0200
Subject: [PATCH] added new statuses disabledAlert and disabledWarning

---
 src/components/IOC/IOCTable/IOCTable.spec.js  | 12 +--
 src/components/common/Status/Status.js        | 14 +---
 src/components/common/Status/StatusBadge.js   |  8 +-
 src/components/common/Status/StatusData.js    | 30 ++++++-
 src/components/common/Status/StatusIcon.js    | 11 +--
 src/mocks/fixtures/IOCAlerts.json             | 80 +++++++++++--------
 src/mocks/fixtures/IOCStatus.json             | 34 ++++----
 src/mocks/fixtures/PagedIOCResponse.json      | 16 ++--
 .../views/IOC/IocDetailsView.stories.js       |  4 +-
 9 files changed, 119 insertions(+), 90 deletions(-)

diff --git a/src/components/IOC/IOCTable/IOCTable.spec.js b/src/components/IOC/IOCTable/IOCTable.spec.js
index 0a735eed..57f9ceda 100644
--- a/src/components/IOC/IOCTable/IOCTable.spec.js
+++ b/src/components/IOC/IOCTable/IOCTable.spec.js
@@ -6,10 +6,10 @@ const textColumns = ["IOC name", "Description", "Host", "Network"];
 const columns = ["Status"].concat(textColumns);
 const firstRowData = [
   "Active with alert(s) 1 warnings1 errors !",
-  "CCCE:MOCK1",
-  "Some description",
-  "vacs-accv-vm-ioc",
-  "ChannelAccess-FEB"
+  "CCCE:MOCK4",
+  "---",
+  "ccce-test-ioc-02",
+  "CSLab-GeneralLab"
 ];
 
 describe("IOCTable", () => {
@@ -31,9 +31,9 @@ describe("IOCTable", () => {
         .should("have.length", textColumns.length - 1);
     });
 
-    it("Displays correct content in first row", () => {
+    it("Displays correct content in third row", () => {
       cy.findAllByRole("row")
-        .eq(1) // first row is headers, so get next index
+        .eq(4) // first row is headers, so get next index
         .each(($el, index) => {
           if (index === 0) {
             const iconTitle = firstRowData[index];
diff --git a/src/components/common/Status/Status.js b/src/components/common/Status/Status.js
index 0a9e8dbb..66b4c65c 100644
--- a/src/components/common/Status/Status.js
+++ b/src/components/common/Status/Status.js
@@ -7,7 +7,7 @@ import { PlayCircleFilled, PauseCircleFilled } from "@mui/icons-material";
 import { StatusPopoverContent } from "./StatusPopoverContent";
 import { StatusBadge } from "./StatusBadge";
 import { StatusIcon } from "./StatusIcon";
-import { STATUS, statusConfig, getStatus } from "./StatusData";
+import { statusesWithAlerts, statusConfig, getStatus } from "./StatusData";
 
 const propsTypes = {
   state: object,
@@ -15,16 +15,6 @@ const propsTypes = {
   hideAlerts: bool
 };
 
-const checkDisplayBadge = (status, hideAlerts) => {
-  return (
-    !hideAlerts &&
-    (status === STATUS.alert ||
-      status === STATUS.warning ||
-      status === STATUS.inactiveAlert ||
-      status === STATUS.inactiveWarning)
-  );
-};
-
 export function Status({ state, alert, hideAlerts = false }) {
   const [status, setStatus] = useState(null);
   const theme = useTheme();
@@ -53,7 +43,7 @@ export function Status({ state, alert, hideAlerts = false }) {
               onMouseLeave={handlePopoverClose}
               style={{ color: theme.palette.status.icons }}
             >
-              {checkDisplayBadge(status, hideAlerts) ? (
+              {!hideAlerts && statusesWithAlerts.includes(status) ? (
                 <StatusBadge
                   status={status}
                   theme={theme}
diff --git a/src/components/common/Status/StatusBadge.js b/src/components/common/Status/StatusBadge.js
index c00f97a0..ba4f700d 100644
--- a/src/components/common/Status/StatusBadge.js
+++ b/src/components/common/Status/StatusBadge.js
@@ -20,13 +20,17 @@ const commonStyles = {
 export const StatusBadge = ({ status, theme, children }) => (
   <Stack sx={{ position: "relative" }}>
     {children}
-    {status === STATUS.warning || status === STATUS.inactiveWarning ? (
+    {status === STATUS.warning ||
+    status === STATUS.inactiveWarning ||
+    status === STATUS.disabledWarning ? (
       <WarningAmberIcon
         sx={{ fill: theme.palette.warning.main, ...commonStyles }}
       />
     ) : (
       <>
-        {status === STATUS.alert || status === STATUS.inactiveAlert ? (
+        {status === STATUS.alert ||
+        status === STATUS.inactiveAlert ||
+        status === STATUS.disabledAlert ? (
           <ErrorOutlineIcon
             sx={{ fill: theme.palette.error.main, ...commonStyles }}
           />
diff --git a/src/components/common/Status/StatusData.js b/src/components/common/Status/StatusData.js
index e922d850..6820391d 100644
--- a/src/components/common/Status/StatusData.js
+++ b/src/components/common/Status/StatusData.js
@@ -8,6 +8,8 @@ import {
 export const STATUS = {
   active: "active",
   disabled: "disabled",
+  disabledAlert: "disabled alert",
+  disabledWarning: "disabled warning",
   alert: "alert",
   warning: "warning",
   inactive: "inactive",
@@ -21,6 +23,15 @@ export const SEVERITY = {
   warning: "warning"
 };
 
+export const statusesWithAlerts = [
+  STATUS.alert,
+  STATUS.warning,
+  STATUS.disabledAlert,
+  STATUS.disabledWarning,
+  STATUS.inactiveAlert,
+  STATUS.inactiveWarning
+];
+
 export const statusConfig = {
   [STATUS.active]: {
     title: "Active",
@@ -30,6 +41,14 @@ export const statusConfig = {
     title: "Disabled",
     icon: StopCircle
   },
+  [STATUS.disabledAlert]: {
+    title: "Disabled with alert(s)",
+    icon: StopCircle
+  },
+  [STATUS.disabledWarning]: {
+    title: "Disabled with warnings(s)",
+    icon: StopCircle
+  },
   [STATUS.alert]: {
     title: "Active with alert(s)",
     icon: Brightness1
@@ -58,6 +77,7 @@ export const statusConfig = {
 
 export const getStatus = (state, alert) => {
   let { isActive } = state;
+  const isDeployed = !state.alertSeverity;
   const alertSeverity = alert?.alertSeverity?.toLowerCase();
 
   if (
@@ -66,9 +86,17 @@ export const getStatus = (state, alert) => {
   ) {
     // Active status / running
     return STATUS.active;
-  } else if (isActive !== false && !isActive) {
+  } else if (
+    !isActive &&
+    isDeployed &&
+    (!alertSeverity || alertSeverity === SEVERITY.info)
+  ) {
     // stopped/paused
     return STATUS.disabled;
+  } else if (!isActive && isDeployed && alertSeverity === SEVERITY.alert) {
+    return STATUS.disabledAlert;
+  } else if (!isActive && isDeployed && alertSeverity === SEVERITY.warning) {
+    return STATUS.disabledWarning;
   } else if (
     isActive &&
     alertSeverity !== undefined &&
diff --git a/src/components/common/Status/StatusIcon.js b/src/components/common/Status/StatusIcon.js
index 17019274..055c9789 100644
--- a/src/components/common/Status/StatusIcon.js
+++ b/src/components/common/Status/StatusIcon.js
@@ -1,19 +1,14 @@
 import { object, string } from "prop-types";
-import { STATUS, statusConfig } from "./StatusData";
+import { statusConfig, statusesWithAlerts } from "./StatusData";
 import { LabeledIcon } from "@ess-ics/ce-ui-common";
 
 const propTypes = {
   alerts: object,
   status: string
 };
-
+statusesWithAlerts.includes(status);
 const getLabel = (alerts, status) => {
-  if (
-    status === STATUS.alert ||
-    status === STATUS.warning ||
-    status === STATUS.inactiveAlert ||
-    status === STATUS.inactiveWarning
-  ) {
+  if (statusesWithAlerts.includes(status)) {
     const warnings = alerts.filter((alert) => alert.type === "WARNING");
     const errors = alerts.filter((alert) => alert.type === "ERROR");
     const hasWarnings = Boolean(warnings.length);
diff --git a/src/mocks/fixtures/IOCAlerts.json b/src/mocks/fixtures/IOCAlerts.json
index fe65d8da..6d10ddc7 100644
--- a/src/mocks/fixtures/IOCAlerts.json
+++ b/src/mocks/fixtures/IOCAlerts.json
@@ -1,11 +1,32 @@
 [
   {
     "iocId": 14,
+    "alertSeverity": null,
+    "alerts": []
+  },
+  {
+    "iocId": 15,
+    "alertSeverity": null,
+    "alerts": []
+  },
+  {
+    "iocId": 18,
+    "alertSeverity": "INFO",
+    "alerts": [
+      {
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
+      }
+    ]
+  },
+  {
+    "iocId": 39,
     "alertSeverity": "ERROR",
     "alerts": [
       {
         "type": "ERROR",
-        "message": "IOC's latest deployment failed, IOC may be in inconsistent state",
+        "message": "IOC is active with error message",
         "link": null
       },
       {
@@ -16,34 +37,40 @@
     ]
   },
   {
-    "iocId": 15,
-    "alertSeverity": null,
-    "alerts": []
+    "iocId": 21,
+    "alertSeverity": "WARNING",
+    "alerts": [
+      {
+        "type": "WARNING",
+        "message": "This is a warning message",
+        "link": null
+      }
+    ]
   },
   {
-    "iocId": 18,
-    "alertSeverity": "INFO",
+    "iocId": 40,
+    "alertSeverity": "ERROR",
     "alerts": [
       {
-        "type": "INFO",
-        "message": "IOC is not deployed",
+        "type": "ERROR",
+        "message": "IOC is inactive with error message",
         "link": null
       }
     ]
   },
   {
-    "iocId": 39,
+    "iocId": 49,
     "alertSeverity": "WARNING",
     "alerts": [
       {
         "type": "WARNING",
-        "message": "IOC is active with warning message",
+        "message": "IOC is inactive with warning message",
         "link": null
       }
     ]
   },
   {
-    "iocId": 21,
+    "iocId": 41,
     "alertSeverity": "ERROR",
     "alerts": [
       {
@@ -53,42 +80,27 @@
       },
       {
         "type": "ERROR",
-        "message": "IOC's latest deployment failed, IOC may be in inconsistent state",
-        "link": null
-      },
-      {
-        "type": "WARNING",
-        "message": "This is a warning message",
+        "message": "IOC is not deployed with error message",
         "link": null
       }
     ]
   },
   {
-    "iocId": 49,
+    "iocId": 42,
     "alertSeverity": "WARNING",
     "alerts": [
+      {
+        "type": "INFO",
+        "message": "IOC is not deployed",
+        "link": null
+      },
       {
         "type": "WARNING",
-        "message": "This is a warning message",
+        "message": "IOC is not deployed with warning message",
         "link": null
       }
     ]
   },
-  {
-    "iocId": 40,
-    "alertSeverity": null,
-    "alerts": []
-  },
-  {
-    "iocId": 41,
-    "alertSeverity": null,
-    "alerts": []
-  },
-  {
-    "iocId": 42,
-    "alertSeverity": null,
-    "alerts": []
-  },
   {
     "iocId": 43,
     "alertSeverity": null,
diff --git a/src/mocks/fixtures/IOCStatus.json b/src/mocks/fixtures/IOCStatus.json
index 960a1136..27635409 100644
--- a/src/mocks/fixtures/IOCStatus.json
+++ b/src/mocks/fixtures/IOCStatus.json
@@ -5,10 +5,6 @@
   },
   {
     "iocId": 15,
-    "isActive": null
-  },
-  {
-    "iocId": 18,
     "alertSeverity": "INFO",
     "alerts": [
       {
@@ -19,12 +15,28 @@
     ],
     "isActive": false
   },
+  {
+    "iocId": 18,
+    "isActive": null
+  },
   {
     "iocId": 39,
     "isActive": true
   },
   {
     "iocId": 21,
+    "isActive": true
+  },
+  {
+    "iocId": 40,
+    "isActive": null
+  },
+  {
+    "iocId": 49,
+    "isActive": null
+  },
+  {
+    "iocId": 41,
     "alertSeverity": "INFO",
     "alerts": [
       {
@@ -36,7 +48,7 @@
     "isActive": false
   },
   {
-    "iocId": 49,
+    "iocId": 42,
     "alertSeverity": "INFO",
     "alerts": [
       {
@@ -47,18 +59,6 @@
     ],
     "isActive": false
   },
-  {
-    "iocId": 40,
-    "isActive": true
-  },
-  {
-    "iocId": 41,
-    "isActive": true
-  },
-  {
-    "iocId": 42,
-    "isActive": true
-  },
   {
     "iocId": 43,
     "isActive": null
diff --git a/src/mocks/fixtures/PagedIOCResponse.json b/src/mocks/fixtures/PagedIOCResponse.json
index 5c4f6d0a..69816d77 100644
--- a/src/mocks/fixtures/PagedIOCResponse.json
+++ b/src/mocks/fixtures/PagedIOCResponse.json
@@ -80,14 +80,6 @@
         "sourceVersionShort": null
       }
     },
-    {
-      "id": 49,
-      "namingName": "CCCE:MOCK6",
-      "createdBy": "mock user 6",
-      "gitProjectId": 12972,
-      "deployedWithOldPlaybook": true,
-      "activeDeployment": null
-    },
     {
       "id": 40,
       "namingName": "CCCE:MOCK-TEST",
@@ -96,6 +88,14 @@
       "deployedWithOldPlaybook": true,
       "activeDeployment": null
     },
+    {
+      "id": 49,
+      "namingName": "CCCE:MOCK6",
+      "createdBy": "mock user 6",
+      "gitProjectId": 12972,
+      "deployedWithOldPlaybook": true,
+      "activeDeployment": null
+    },
     {
       "id": 41,
       "namingName": "CCCE:MOCK7",
diff --git a/src/stories/views/IOC/IocDetailsView.stories.js b/src/stories/views/IOC/IocDetailsView.stories.js
index 6a827107..b206af67 100644
--- a/src/stories/views/IOC/IocDetailsView.stories.js
+++ b/src/stories/views/IOC/IocDetailsView.stories.js
@@ -29,11 +29,11 @@ NotDeployed.args = {
 export const Deployed = (args) => <Template {...args} />;
 Deployed.args = {
   ...config,
-  id: 39
+  id: 14
 };
 
 export const DeployedErrors = (args) => <Template {...args} />;
 DeployedErrors.args = {
   ...config,
-  id: 14
+  id: 39
 };
-- 
GitLab