From a60b0a698715733cf3b0df6c00955e32ec0c2e6a Mon Sep 17 00:00:00 2001 From: Matthieu Moquet Date: Fri, 8 Nov 2024 18:33:40 +0100 Subject: [PATCH] fix: add severity badge on alert modal --- src/components/alerts/alert-modal.tsx | 6 +++- src/components/alerts/alert-row.tsx | 41 ++---------------------- src/components/alerts/alert-severity.tsx | 41 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 src/components/alerts/alert-severity.tsx diff --git a/src/components/alerts/alert-modal.tsx b/src/components/alerts/alert-modal.tsx index d27eac9..4982ba6 100644 --- a/src/components/alerts/alert-modal.tsx +++ b/src/components/alerts/alert-modal.tsx @@ -19,6 +19,7 @@ import { import { Alert } from "@/types/alertmanager" import { Check, ClipboardCopy, Square, SquareArrowOutUpRight } from "lucide-react" import { cn } from "@/lib/utils" +import { AlertSeverity } from "./alert-severity" function isURL(string: string): boolean { try { @@ -45,7 +46,10 @@ export function AlertModal(props: Props) {
- {alert?.labels.alertname} + + {alert && } + {alert?.labels.alertname} + {summary} diff --git a/src/components/alerts/alert-row.tsx b/src/components/alerts/alert-row.tsx index 2d160e9..3dab3c1 100644 --- a/src/components/alerts/alert-row.tsx +++ b/src/components/alerts/alert-row.tsx @@ -1,7 +1,7 @@ import { Alert } from "@/types/alertmanager" import { formatDate } from "@/lib/date" import { stringToColor } from "./utils" -import { cn } from "@/lib/utils" +import { AlertSeverity } from "./alert-severity" const importantLabels = [ 'host', @@ -25,7 +25,7 @@ export function AlertRow(props: Props) { const { alert } = props return ( -
+
@@ -36,42 +36,6 @@ export function AlertRow(props: Props) { ) } -function AlertSeverity({ alert }: { alert: Alert }) { - const { severity } = alert.labels - - let color = 'bg-black' - let text = '???' - - switch (severity) { - case 'critical': - color = 'bg-red-600' - text = 'CRIT' - break - case 'error': - color = 'bg-red-500' - text = 'ERR' - break - case 'warning': - color = 'bg-orange-300' - text = 'WARN' - break - case 'info': - color = 'bg-blue-400' - text = 'INFO' - break - case 'none': - color = 'bg-slate-500' - text = 'NONE' - break - } - - return ( -
- {text} -
- ) -} - function AlertTitle({ alert }: { alert: Alert }) { const { alertname } = alert.labels @@ -92,7 +56,6 @@ function AlertSummary({ alert }: { alert: Alert }) { ) } - function AlertLabels({ alert }: { alert: Alert }) { const labels = Object.entries(alert.labels).map(([key, value]) => { return { key: key, value: value } diff --git a/src/components/alerts/alert-severity.tsx b/src/components/alerts/alert-severity.tsx new file mode 100644 index 0000000..a1068f6 --- /dev/null +++ b/src/components/alerts/alert-severity.tsx @@ -0,0 +1,41 @@ +import { cn } from "@/lib/utils" +import { Alert } from "@/types/alertmanager" + +export function AlertSeverity({ alert }: { alert: Alert }) { + const { severity } = alert.labels + + let color = 'bg-black' + let text = '???' + + switch (severity) { + case 'critical': + color = 'bg-red-600' + text = 'CRIT' + break + case 'error': + color = 'bg-red-500' + text = 'ERR' + break + case 'warning': + color = 'bg-orange-300' + text = 'WARN' + break + case 'info': + color = 'bg-blue-400' + text = 'INFO' + break + case 'none': + color = 'bg-slate-500' + text = 'NONE' + break + } + + return ( +
+ {text} +
+ ) +}