import { Accordion, Alert, Badge, Card, Group, Pagination, rem, Stack, Text, Tooltip, } from "@mantine/core"; // import { useQuery } from "react-query"; import { humanizeDurationRelative, humanizeDuration, now, } from "../lib/formatTime"; import { IconAlertTriangle, IconBell, IconHourglass, IconInfoCircle, IconRefresh, IconRepeat, IconTimeline, } from "@tabler/icons-react"; import { useSuspenseAPIQuery } from "../api/api"; import { RulesResult } from "../api/responseTypes/rules"; import badgeClasses from "../Badge.module.css"; import RuleDefinition from "../components/RuleDefinition"; import { badgeIconStyle } from "../styles"; import { NumberParam, useQueryParam, withDefault } from "use-query-params"; import { useSettings } from "../state/settingsSlice"; import { useEffect } from "react"; import CustomInfiniteScroll from "../components/CustomInfiniteScroll"; const healthBadgeClass = (state: string) => { switch (state) { case "ok": return badgeClasses.healthOk; case "err": return badgeClasses.healthErr; case "unknown": return badgeClasses.healthUnknown; default: throw new Error("Unknown rule health state"); } }; export default function RulesPage() { const { data } = useSuspenseAPIQuery({ path: `/rules` }); const { ruleGroupsPerPage } = useSettings(); const [activePage, setActivePage] = useQueryParam( "page", withDefault(NumberParam, 1) ); // If we were e.g. on page 10 and the number of total pages decreases to 5 (due // changing the max number of items per page), go to the largest possible page. const totalPageCount = Math.ceil(data.data.groups.length / ruleGroupsPerPage); const effectiveActivePage = Math.max(1, Math.min(activePage, totalPageCount)); useEffect(() => { if (effectiveActivePage !== activePage) { setActivePage(effectiveActivePage); } }, [effectiveActivePage, activePage, setActivePage]); return ( {data.data.groups.length === 0 && ( }> No rule groups configured. )} {data.data.groups .slice( (effectiveActivePage - 1) * ruleGroupsPerPage, effectiveActivePage * ruleGroupsPerPage ) .map((g, i) => ( {g.name} {g.file} } > last run {humanizeDurationRelative(g.lastEvaluation, now())} } > took {humanizeDuration(parseFloat(g.evaluationTime) * 1000)} } > every {humanizeDuration(parseFloat(g.interval) * 1000)}{" "} {g.rules.length === 0 && ( }> No rules in rule group. )} ( {items.map((r, j) => ( {r.type === "alerting" ? ( ) : ( )} {r.name} } > {humanizeDurationRelative( r.lastEvaluation, now() )} } > {humanizeDuration( parseFloat(r.evaluationTime) * 1000 )} {r.health} {r.lastError && ( } > Error: {r.lastError} )} ))} )} /> ))} ); }