Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add severity badge on alert modal #14

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/alerts/alert-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -45,7 +46,10 @@ export function AlertModal(props: Props) {
<SheetContent>
<div className="flex flex-col h-screen">
<SheetHeader className="shrink-0">
<SheetTitle>{alert?.labels.alertname}</SheetTitle>
<SheetTitle className="flex gap-2 items-center">
{alert && <AlertSeverity alert={alert} />}
{alert?.labels.alertname}
</SheetTitle>
<SheetDescription>{summary}</SheetDescription>
</SheetHeader>

Expand Down
41 changes: 2 additions & 39 deletions src/components/alerts/alert-row.tsx
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -25,7 +25,7 @@ export function AlertRow(props: Props) {
const { alert } = props

return (
<div className="flex gap-2 items-center px-6 h-[45px] border-b group cursor-pointer">
<div className="flex gap-2 xl:gap-4 items-center px-6 h-[45px] border-b group cursor-pointer">
<AlertSeverity alert={alert} />
<AlertTitle alert={alert} />
<AlertSummary alert={alert} />
Expand All @@ -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 (
<div className="shrink-0 w-12 font-mono">
<span className={cn("text-white text-xs px-2 py-1 rounded-sm", color)}>{text}</span>
</div>
)
}

function AlertTitle({ alert }: { alert: Alert }) {
const { alertname } = alert.labels

Expand All @@ -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 }
Expand Down
41 changes: 41 additions & 0 deletions src/components/alerts/alert-severity.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div
title={severity}
className={cn("text-center text-white text-xs px-1 py-1 rounded-sm shrink-0 font-mono w-12", color)}
>
{text}
</div>
)
}
2 changes: 1 addition & 1 deletion src/components/alerts/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function AlertsTemplate(props: Props) {
</div>
<div className="text-muted-foreground">/</div>
<div>
{viewName ?? view}
{viewName ? viewName : view}
</div>
<div>
{
Expand Down
Loading