import { Alert, Badge, Card, Group, Table, Text, Tooltip, useComputedColorScheme, } from "@mantine/core"; // import { useQuery } from "react-query"; import { formatDuration, formatRelative, humanizeDuration, now, } from "../lib/time-format"; import { IconAlertTriangle, IconBell, IconClockPause, IconClockPlay, IconDatabaseImport, IconHourglass, IconRefresh, IconRepeat, } from "@tabler/icons-react"; import CodeMirror, { EditorView } from "@uiw/react-codemirror"; import { useSuspenseAPIQuery } from "../api/api"; import { RulesMap } from "../api/response-types/rules"; import { syntaxHighlighting } from "@codemirror/language"; import { baseTheme, darkPromqlHighlighter, lightTheme, promqlHighlighter, } from "../codemirror/theme"; import { PromQLExtension } from "@prometheus-io/codemirror-promql"; import classes from "../codebox.module.css"; const healthBadgeClass = (state: string) => { switch (state) { case "ok": return classes.healthOk; case "err": return classes.healthErr; case "unknown": return classes.healthUnknown; default: return "orange"; } }; const promqlExtension = new PromQLExtension(); export default function Rules() { const { data } = useSuspenseAPIQuery(`/rules`); const theme = useComputedColorScheme(); return ( <> {data.data.groups.map((g) => ( {g.name} {g.file} } > {formatRelative(g.lastEvaluation, now())} } > {humanizeDuration(parseFloat(g.evaluationTime) * 1000)} } > {humanizeDuration(parseFloat(g.interval) * 1000)} {g.rules.map((r) => ( {r.type === "alerting" ? ( ) : ( )} {r.name} {r.health} } > {formatRelative(r.lastEvaluation, now())} } > {humanizeDuration( parseFloat(r.evaluationTime) * 1000 )} {r.lastError && ( } > Error: {r.lastError} )} {r.type === "alerting" && ( {r.duration && ( } > for: {formatDuration(r.duration * 1000)} )} {r.keepFiringFor && ( } > keep_firing_for: {formatDuration(r.duration * 1000)} )} )} {r.labels && Object.keys(r.labels).length > 0 && ( {Object.entries(r.labels).map(([k, v]) => ( {k}: {v} ))} )} {/* {Object.keys(r.annotations).length > 0 && ( {Object.entries(r.annotations).map(([k, v]) => ( {k}: {v} ))} )} */} ))}
))} ); }