import type { Metadata } from 'next'; import Link from 'next/link'; import { AdminError, AdminHeader, SectionTitle, Tile } from '@/components/admin/ui'; import { Pagination } from '@/components/ui/pagination'; import { adminApi, safeAdmin } from '@/lib/admin-api'; import { fmtAgo, fmtDateTime, fmtInt, num } from '@/lib/format'; export const metadata: Metadata = { title: 'Data quality' }; const CHECKS: { key: keyof Awaited>['checks']; label: string; hint: string }[] = [ { key: 'missing_norad', label: 'Missing NORAD', hint: 'satellites without a catalog number' }, { key: 'missing_cospar', label: 'Missing COSPAR', hint: 'no international designator (analyst / unassigned objects)' }, { key: 'active_without_operator', label: 'Active without operator', hint: 'active payloads/stations with no resolved operator' }, { key: 'active_without_country', label: 'Active without country', hint: 'active objects whose owner code has no country' }, { key: 'stale_active', label: 'Stale active', hint: 'active with GP but latest epoch > 30 d' }, { key: 'broken_launch_links', label: 'Broken launch links', hint: 'COSPAR present but no launch row' }, { key: 'active_without_elements', label: 'Active without elements', hint: 'active but never seen in the GP feed' }, ]; export default async function AdminDataQualityPage({ searchParams }: { searchParams: Promise<{ page?: string; flag?: string }> }) { const sp = await searchParams; const page = Math.max(1, Number(sp.page) || 1); const flag = sp.flag || null; const res = await safeAdmin(adminApi.dataQuality(page, flag, 50)); if (res.error !== null) { return ( <> ); } const d = res.data; const now = Date.now(); const href = (p: number, f: string | null = flag) => `/admin/data-quality?${new URLSearchParams({ ...(f ? { flag: f } : {}), ...(p > 1 ? { page: String(p) } : {}) }).toString()}`; return ( <> Checks (live counts)
{CHECKS.map((c) => { const v = num(d.checks[c.key]) ?? 0; return 0 && (c.key === 'stale_active' || c.key === 'broken_launch_links' || c.key === 'missing_norad') ? 'warn' : undefined} />; })}
Open flags by type {d.summary.length === 0 ? (

No open quality flags

) : (
All ({fmtInt(d.summary.reduce((a, s) => a + (num(s.open) ?? 0), 0))}) {d.summary.map((s) => ( {s.flag} · {fmtInt(s.open)} ))}
)} Flagged satellites {d.data.length === 0 ? (

No flagged rows{flag ? ` for ${flag}` : ''}

) : ( <>
{d.data.map((f) => ( ))}
Satellite Flag Detail Raised
{f.slug ? ( {f.name ?? f.slug} ) : ( {f.entity_type} {f.entity_id} )} {f.norad_id !== null && NORAD {f.norad_id}} {f.flag} {f.detail ?? '—'} {fmtAgo(f.created_at, now)}
href(p)} /> )} ); }