/** * Central registry for list-page view types — labels, render kinds, and hub chrome rules. * * **Add a new view once here** (plus a body in `components/data-views/`). Hubs declare * `supportedViewTypes` on `ListPageTemplate`; table components branch with * `getDataListViewRenderKind` + `ListPageConnectedViewBody` (never a dashboard fallback). * * @see `docs/data-views-pattern.md` — "View registry and connected bodies" * @see `.cursor/rules/exxat-hub-supported-views.mdc` — default hubs use **`TABLE_ONLY_HUB_SUPPORTED_VIEWS`**; opt into **`FULL_HUB_SUPPORTED_VIEWS`** when product asks */ import { DATA_LIST_VIEW_TILES, type DataListViewType, dataListViewAddShortcut, dataListViewIcon, dataListViewLabel, } from "./data-list-view" import { getDataListViewRenderKind, type DataListViewRenderKind, } from "./data-list-view-surface" export interface DataListViewDefinition { value: DataListViewType label: string icon: string renderKind: DataListViewRenderKind /** `ListPageTemplate` metrics slot above the views toolbar. */ hubMetricsStrip: boolean } const DEFINITIONS: DataListViewDefinition[] = DATA_LIST_VIEW_TILES.map(tile => { const renderKind = getDataListViewRenderKind(tile.value) const hubMetricsStrip = renderKind !== "calendar-with-toolbar" && renderKind !== "dashboard-with-toolbar" return { value: tile.value, label: tile.label, icon: tile.icon, renderKind, hubMetricsStrip, } }) const BY_VALUE = new Map( DEFINITIONS.map(d => [d.value, d]), ) export const DATA_LIST_VIEW_REGISTRY: readonly DataListViewDefinition[] = DEFINITIONS /** * Default view allowlist when a hub ships **table only** (no Add view until product asks). * Omit `supportedViewTypes` on `ListPageTemplate` + `HubTable` to use this default. */ export const TABLE_ONLY_HUB_SUPPORTED_VIEWS = ["table"] as const satisfies readonly DataListViewType[] /** * Default view allowlist for **primary list hubs** (Placements / Team / Students-style pages). * Opt in when the product needs table + list + board + dashboard — implement renderers for each. */ export const PRIMARY_HUB_SUPPORTED_VIEWS = [ "table", "list", "board", "dashboard", ] as const satisfies readonly DataListViewType[] /** * Default allowlist for **list-page hubs** in this design system (Library / Column types / * Tokens, etc.). Matches the All questions hub: table, list, board, dashboard, folder, * panel, and tree-panel. Pair with renderers for each kind on `HubTable` + `ListPageTemplate`. */ export const FULL_HUB_SUPPORTED_VIEWS = [ "table", "list", "board", "dashboard", "folder", "panel", "tree-panel", ] as const satisfies readonly DataListViewType[] /** Every registered view type (includes folder, panel, calendar, tree-panel). */ export const ALL_DATA_LIST_VIEW_TYPES = DATA_LIST_VIEW_REGISTRY.map(d => d.value) export function dataListViewDefinition(view: DataListViewType): DataListViewDefinition { const def = BY_VALUE.get(view) if (!def) { throw new Error(`Unknown DataListViewType: ${view}`) } return def } /** `ListPageTemplate` hub KPI strip — false for calendar and dashboard (inline KPIs). */ export function showsListPageHubMetricsStrip(view: DataListViewType): boolean { return dataListViewDefinition(view).hubMetricsStrip } /** Tiles for Add view + Properties when a hub only supports a subset of views. */ export function dataListViewTilesForHub(supported: readonly DataListViewType[]) { const allowed = new Set(supported) return DATA_LIST_VIEW_REGISTRY.filter(d => allowed.has(d.value)).map(d => ({ type: d.value, label: d.label, icon: d.icon, })) } /** `SelectionTileGrid` options for Properties when a hub supports a subset of views. */ export function dataListViewSelectionTilesForHub(supported: readonly DataListViewType[]) { return dataListViewTilesForHub(supported).map(t => ({ value: t.type, label: t.label, icon: t.icon, })) } /** View types that expose Table Properties (all registered `DataListViewType` values). */ export const DATA_LIST_SURFACE_VIEW_TYPES: ReadonlySet = new Set( DATA_LIST_VIEW_REGISTRY.map(d => d.value), ) export function isDataListSurfaceViewType(viewType: string): viewType is DataListViewType { return DATA_LIST_SURFACE_VIEW_TYPES.has(viewType as DataListViewType) } export function isDataListViewTypeSupported( view: DataListViewType, supported: readonly DataListViewType[], ): boolean { return supported.includes(view) } export { dataListViewAddShortcut, dataListViewIcon, dataListViewLabel, getDataListViewRenderKind, type DataListViewRenderKind, }