From 51accd1b67a35689fa39aedeb603c04b8651c66d Mon Sep 17 00:00:00 2001 From: William Hill Date: Sun, 3 May 2026 10:26:27 -0400 Subject: [PATCH] refactor: simplify AI transparency page components and grouping helper - Extract SurfaceInputsField, SurfaceTrainingDataField, SurfaceNoteCallout, CategorySurfaceSection - Use LucideIcon for category meta; NL section title: Natural-language features - Build group buckets from AI_SURFACE_CATEGORY_ORDER via Object.fromEntries Co-authored-by: Cursor --- .../app/ai-transparency/page.tsx | 134 +++++++++++------- .../content/ai-transparency.ts | 9 +- 2 files changed, 87 insertions(+), 56 deletions(-) diff --git a/codebenders-dashboard/app/ai-transparency/page.tsx b/codebenders-dashboard/app/ai-transparency/page.tsx index 17a8177..1ad998c 100644 --- a/codebenders-dashboard/app/ai-transparency/page.tsx +++ b/codebenders-dashboard/app/ai-transparency/page.tsx @@ -1,7 +1,15 @@ import type { Metadata } from "next" import type { ReactNode } from "react" import Link from "next/link" -import { ArrowLeft, Bot, Cloud, Database, ServerCog, Sparkles } from "lucide-react" +import { + ArrowLeft, + Bot, + Cloud, + Database, + ServerCog, + Sparkles, + type LucideIcon, +} from "lucide-react" import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { @@ -19,7 +27,7 @@ export const metadata: Metadata = { const CATEGORY_META: Record< AISurface["category"], - { label: string; sectionTitle: string; icon: typeof Bot; tint: string } + { label: string; sectionTitle: string; icon: LucideIcon; tint: string } > = { ml_model: { label: "ML model", @@ -29,7 +37,7 @@ const CATEGORY_META: Record< }, natural_language: { label: "Natural language", - sectionTitle: "Natural languages", + sectionTitle: "Natural-language features", icon: Sparkles, tint: "text-violet-600", }, @@ -79,6 +87,50 @@ function ProvenanceBadge({ surface }: { surface: AISurface }) { ) } +function SurfaceInputsField({ surfaceId, lines }: { surfaceId: string; lines: string[] }) { + return ( + + {lines.map((line, index) => ( +
  • {line}
  • + ))} + + } + /> + ) +} + +function SurfaceTrainingDataField({ surface }: { surface: AISurface }) { + const td = surface.trainingData + if (!td) return null + return ( + + {td.source} +
    + + Cohort: {td.cohort} + {td.rowCount ? ` • ${td.rowCount}` : ""} + + + } + /> + ) +} + +function SurfaceNoteCallout({ children }: { children: ReactNode }) { + return ( +
    + Note +

    {children}

    +
    + ) +} + function SurfaceCard({ surface }: { surface: AISurface }) { const cat = CATEGORY_META[surface.category] const Icon = cat.icon @@ -103,42 +155,12 @@ function SurfaceCard({ surface }: { surface: AISurface }) { - - {surface.inputs.map((line, index) => ( -
  • {line}
  • - ))} - - } - /> - {surface.trainingData && ( - - {surface.trainingData.source} -
    - - Cohort: {surface.trainingData.cohort} - {surface.trainingData.rowCount ? ` • ${surface.trainingData.rowCount}` : ""} - - - } - /> - )} + + - {surface.notes && ( -
    - - Note - -

    {surface.notes}

    -
    - )} + {surface.notes ? {surface.notes} : null}
    ) @@ -155,6 +177,31 @@ function Field({ label, value }: { label: string; value: ReactNode }) { ) } +function CategorySurfaceSection({ + category, + surfaces, +}: { + category: AISurface["category"] + surfaces: AISurface[] +}) { + const meta = CATEGORY_META[category] + const Icon = meta.icon + return ( +
    +
    + +

    {meta.sectionTitle}

    + ({surfaces.length}) +
    +
    + {surfaces.map((s) => ( + + ))} +
    +
    + ) +} + export default function AITransparencyPage() { const grouped = groupAISurfacesByCategory(AI_SURFACES) @@ -216,21 +263,8 @@ export default function AITransparencyPage() { {AI_SURFACE_CATEGORY_ORDER.map((category) => { const items = grouped[category] if (items.length === 0) return null - const cat = CATEGORY_META[category] - const Icon = cat.icon return ( -
    -
    - -

    {cat.sectionTitle}

    - ({items.length}) -
    -
    - {items.map((s) => ( - - ))} -
    -
    + ) })} diff --git a/codebenders-dashboard/content/ai-transparency.ts b/codebenders-dashboard/content/ai-transparency.ts index 9929730..d713626 100644 --- a/codebenders-dashboard/content/ai-transparency.ts +++ b/codebenders-dashboard/content/ai-transparency.ts @@ -47,12 +47,9 @@ export const AI_SURFACE_CATEGORY_ORDER: AISurface["category"][] = [ export function groupAISurfacesByCategory( surfaces: readonly AISurface[] ): Record { - const grouped: Record = { - ml_model: [], - natural_language: [], - explainability: [], - data_api: [], - } + const grouped = Object.fromEntries( + AI_SURFACE_CATEGORY_ORDER.map((category) => [category, [] as AISurface[]]) + ) as Record for (const surface of surfaces) { grouped[surface.category].push(surface) }