spb/datacenterindex
Public
HTML 53.9%
TypeScript 44.5%
JavaScript 0.6%
SQL 0.5%
1import type { FacilitySummary } from "@dci/core";2import { FacilityTable, type FacilityTableProps } from "@/components/facility-table";3import { Pagination } from "@/components/ui/pagination";45/**6 * Facilities block of operator / country / metro pages: table + `?fPage=` pager (50 per page, sorted by MW server-side).7 * `hrefFor` must preserve the other query params of the page.8 */9export function PagedFacilities({ items, total, page, perPage = 50, hrefFor, columns, emptyTitle, emptyDescription }: { items: FacilitySummary[]; total: number; page: number; perPage?: number; hrefFor: (page: number) => string; columns?: FacilityTableProps["columns"]; emptyTitle?: string; emptyDescription?: string }) {10 return (11 <div>12 <FacilityTable items={items} columns={columns} emptyTitle={emptyTitle ?? "No facilities indexed yet"} emptyDescription={emptyDescription ?? "Facilities will appear as connectors observe them."} />13 <Pagination page={page} perPage={perPage} total={total} hrefFor={hrefFor} label="facilities" className="mt-3" />14 </div>15 );16}1718/** Parse `?fPage=` (1-based, integer). */19export function parseFPage(v: string | string[] | undefined): number {20 const s = Array.isArray(v) ? v[0] : v;21 const n = Number(s);22 return Number.isFinite(n) && n > 1 ? Math.floor(n) : 1;23}2425/** Build `<base>?fPage=N#facilities`, keeping other params. */26export function fPageHref(base: string, params: Record<string, string | string[] | undefined>, page: number, anchor = "facilities"): string {27 const sp = new URLSearchParams();28 for (const [k, v] of Object.entries(params)) {29 if (k === "fPage" || v === undefined) continue;30 sp.set(k, Array.isArray(v) ? v[0] ?? "" : v);31 }32 if (page > 1) sp.set("fPage", String(page));33 const qs = sp.toString();34 return `${base}${qs ? `?${qs}` : ""}${anchor ? `#${anchor}` : ""}`;35}36