import type { EventType } from "@dci/core"; import type { Metadata } from "next"; import { LiveFeed2 } from "@/components/intelligence/live/live-feed-2"; import { liveApiQuery, liveHref, MINOR_THRESHOLD, parseLiveQuery } from "@/components/intelligence/live/query"; import { ApiNote } from "@/components/intelligence/shared"; import { Page, PageHeader } from "@/components/ui/card"; import { FilterChips, type Chip } from "@/components/ui/filter-chips"; import { Metric } from "@/components/ui/metric"; import { OfflineNotice } from "@/components/ui/states"; import { api } from "@/lib/api"; import { countryName, fmtInt } from "@/lib/format"; import { CONFIDENCE_SHORT, ENTITY_TYPE_LABEL, EVENT_LABEL, SIGNIFICANCE_LABEL, SOURCE_KIND_LABEL } from "@/lib/labels"; import { routes } from "@/lib/routes"; import { LiveFilters } from "./live-filters"; export const revalidate = 30; export const metadata: Metadata = { title: "Live changes", description: "Every detected change in the global data center index — new facilities, capacity and status changes, project announcements, power and corporate events — deduplicated per announcement, with source, significance and confidence.", alternates: { canonical: "/live" }, }; const PER_PAGE = 50; export default async function LivePage({ searchParams }: { searchParams: Promise> }) { const sp = await searchParams; const query = parseLiveQuery(sp); const apiQuery = liveApiQuery(query); const [res, dash] = await Promise.all([api.events({ ...apiQuery, per_page: PER_PAGE }), api.dashboard()]); const stats = dash.ok ? dash.data.stats : null; const hidingMinor = !query.all && !query.significance && !query.min_significance; const chips: Chip[] = []; for (const t of query.type?.split(",") ?? []) chips.push({ key: `t:${t}`, label: "Type", value: EVENT_LABEL[t as EventType] ?? t, removeHref: liveHref({ ...query, type: query.type!.split(",").filter((x) => x !== t).join(",") || undefined }) }); if (query.entity_type) chips.push({ key: "et", label: "Entity", value: ENTITY_TYPE_LABEL[query.entity_type] ?? query.entity_type, removeHref: liveHref({ ...query, entity_type: undefined }) }); if (query.entity_id) chips.push({ key: "eid", label: "Entity id", value: query.entity_id, removeHref: liveHref({ ...query, entity_id: undefined }) }); if (query.country) chips.push({ key: "c", label: "Country", value: countryName(query.country), removeHref: liveHref({ ...query, country: undefined }) }); if (query.metro) chips.push({ key: "m", label: "Market", value: query.metro, removeHref: liveHref({ ...query, metro: undefined }) }); if (query.operator) chips.push({ key: "o", label: "Operator", value: query.operator, removeHref: liveHref({ ...query, operator: undefined }) }); if (query.project) chips.push({ key: "p", label: "Project", value: query.project, removeHref: liveHref({ ...query, project: undefined }) }); for (const c of query.confidence?.split(",") ?? []) chips.push({ key: `cf:${c}`, label: "Confidence", value: CONFIDENCE_SHORT[c as keyof typeof CONFIDENCE_SHORT] ?? c, removeHref: liveHref({ ...query, confidence: query.confidence!.split(",").filter((x) => x !== c).join(",") || undefined }) }); if (query.significance) chips.push({ key: "s", label: "Significance", value: SIGNIFICANCE_LABEL[query.significance], removeHref: liveHref({ ...query, significance: undefined }) }); if (query.min_significance) chips.push({ key: "ms", label: "Significance", value: `≥ ${query.min_significance}`, removeHref: liveHref({ ...query, min_significance: undefined }) }); for (const k of query.source_kind?.split(",") ?? []) chips.push({ key: `sk:${k}`, label: "Source", value: SOURCE_KIND_LABEL[k as keyof typeof SOURCE_KIND_LABEL] ?? k, removeHref: liveHref({ ...query, source_kind: query.source_kind!.split(",").filter((x) => x !== k).join(",") || undefined }) }); if (query.ai) chips.push({ key: "ai", label: "AI / HPC", value: "only", removeHref: liveHref({ ...query, ai: undefined }) }); if (query.dedupe === false) chips.push({ key: "dd", label: "View", value: "every document", removeHref: liveHref({ ...query, dedupe: undefined }) }); if (query.all) chips.push({ key: "all", label: "Significance", value: "all changes", removeHref: liveHref({ ...query, all: undefined }) }); return ( Live } title="Change feed" description={`Every change detected by the connectors, with its source, significance and confidence. ${hidingMinor ? `Minor changes (significance below ${MINOR_THRESHOLD}) are hidden by default.` : "Showing every significance band."} ${query.dedupe === false ? "Every document is listed." : "Documents describing the same announcement are collapsed into one row."} Refreshes every minute.`} aside={
} /> {!res.ok && }
); }