Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.6 kB ยท 77 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778"use client";
import { useQuery } from "@tanstack/react-query";
import { useFeature } from "@/hooks/use-feature";import { useTRPC } from "@/lib/trpc/client";
export function useCommandMenuData({ open }: { open: boolean }) { const trpc = useTRPC(); const incidentsEnabled = useFeature("incident-management");
// `enabled: open` keeps the always-mounted palette from fetching on every // dashboard load; data stays cached once fetched. const { data: monitors } = useQuery( trpc.monitor.list.queryOptions(undefined, { enabled: open }), ); const { data: statusPages } = useQuery( trpc.page.list.queryOptions(undefined, { enabled: open }), ); const { data: workspaces } = useQuery( trpc.workspace.list.queryOptions(undefined, { enabled: open }), ); const { data: workspace } = useQuery( trpc.workspace.get.queryOptions(undefined, { enabled: open }), ); // Inputs match the overview/create-sheet queries so create mutations // invalidate this cache entry too. const { data: statusReports } = useQuery( trpc.statusReport.list.queryOptions({}, { enabled: open }), ); const { data: maintenances } = useQuery( trpc.maintenance.list.queryOptions(undefined, { enabled: open }), ); // Server rejects the query without the feature โ never fire it unflagged. // Server order is already open โ mitigated โ newest declared. const { data: incidents } = useQuery( trpc.incident.list.queryOptions(undefined, { enabled: open && incidentsEnabled, }), );
const otherWorkspaces = workspaces?.filter((w) => w.slug !== workspace?.slug) ?? [];
// Unresolved reports first; within each partition keep server order (desc). const sortedStatusReports = statusReports ? [ ...statusReports.filter((r) => r.status !== "resolved"), ...statusReports.filter((r) => r.status === "resolved"), ] : undefined;
// Upcoming/active maintenances first, then past (server order desc). // Orphans without a page are skipped โ no route to navigate to. const now = Date.now(); const withPage = maintenances?.filter((m) => m.pageId !== null); const sortedMaintenances = withPage ? [ ...withPage.filter((m) => m.to.getTime() >= now), ...withPage.filter((m) => m.to.getTime() < now), ] : undefined;
const pageTitleById = new Map(statusPages?.map((p) => [p.id, p.title]) ?? []);
return { incidentsEnabled, incidents: incidentsEnabled ? incidents : undefined, monitors, statusPages, statusReports, sortedStatusReports, sortedMaintenances, otherWorkspaces, pageTitleById, };}