content-explorer/ui/lib/browser-row.ts
tegwick f8c94d3272
All checks were successful
synthetic / suite (push) Successful in 56s
Finish the computing-basics pilot and the local OnCo reference slice.
The single-operator pilot keeps static projection. Local OnCo use requires a CC BY-NC origin notice, and the slice stays out of public CI.

Assistant: grok
Assistant-Session: 01a15378-f601-7fe2-a143-8e1500a1d59c
2026-10-19 13:04:55 +02:00

88 lines
2.6 KiB
TypeScript

/*
* Field set adapted from OnCo BrowserRow (id, name, tldr, route, facets, cols, sortKeys).
* https://github.com/judegomila/OnCo @ b594d7433bf4e408b44215e25e5304696d6f840e
* Copyright (c) 2026 OnCo. MIT License. See ui/NOTICE.
*
* Domain visuals (molecule, target, schematic, cancer icon, section icon) are not part of this type.
* The mapper is a pure function from a canonical record plus the manifest facet list.
*/
export type TextCell = { kind: "text"; text: string };
export type LinkCell = { kind: "link"; label: string; href: string };
export type ChipsCell = { kind: "chips"; values: string[] };
export type CellValue = TextCell | LinkCell | ChipsCell;
export type BrowserRow = {
id: string;
name: string;
tldr: string;
route: string;
facets: Record<string, string[]>;
cols: Record<string, CellValue>;
sortKeys: Record<string, string>;
};
export type ColumnDef = { key: string; label: string };
export type MapperEntity = {
id: string;
title: string;
tldr: string;
tags?: string[];
kindLabel: string;
route: string;
kindHref: string;
};
const LABELS: Record<string, string> = {
name: "Name",
tldr: "Summary",
tags: "Tags",
kind: "Kind",
};
export const HOME_COLUMNS = ["name", "kind", "tldr"];
export function columnDefs(keys: readonly string[]): ColumnDef[] {
return keys.map((key) => ({ key, label: LABELS[key] ?? key }));
}
export function mapBrowserRow(entity: MapperEntity, facetKeys: readonly string[]): BrowserRow {
const tags = [...(entity.tags ?? [])];
const cols: Record<string, CellValue> = {
name: { kind: "link", label: entity.title, href: entity.route },
tldr: { kind: "text", text: entity.tldr },
tags: { kind: "chips", values: tags },
kind: { kind: "link", label: entity.kindLabel, href: entity.kindHref },
};
const facets: Record<string, string[]> = {};
for (const key of facetKeys) {
if (key === "tags") facets[key] = [...tags];
else if (key === "kind") facets[key] = [entity.kindLabel];
else facets[key] = [];
}
return {
id: entity.id,
name: entity.title,
tldr: entity.tldr,
route: entity.route,
facets,
cols,
sortKeys: {
name: entity.title,
tldr: entity.tldr,
tags: tags.join(", "),
kind: entity.kindLabel,
},
};
}
export function cellSortValue(row: BrowserRow, key: string): string {
const keyed = row.sortKeys[key];
if (keyed !== undefined) return keyed;
const cell = row.cols[key];
if (!cell) return "";
if (cell.kind === "text") return cell.text;
if (cell.kind === "link") return cell.label;
return cell.values.join(", ");
}