1
0
Fork 0

chore(tech-tree): restyle note nodes as distinct memo cards

A note was still a rectangle with a strip and a footer, so it read as another technology with an amber accent. Give it its own silhouette instead: warm paper fill, chunky dashed border, a vertical NOTE rail in place of the classification strip, a folded top-right corner, no corner brackets and no readout footer, with the published/internal state moved into the body.

The differences that matter at fit-view zoom are the fill and the dashed edge, since the text is illegible there and colour is all that separates the two node kinds. Documents the contract in the tech-tree AGENTS.md so it does not get harmonised back to tech-card chrome.
This commit is contained in:
Jason Fraley 2026-11-24 11:09:54 -05:00
parent 7003a321f9
commit 16a5a288d9
2 changed files with 47 additions and 35 deletions

View file

@ -6,7 +6,7 @@
`/admin/tech-tree` — visual tech tree editor over `technologies`, built on `@xyflow/react` v12 following the narrative-flow patterns. Custom admin view (root view) + a "Tech Tree" nav entry injected under the Intelligence group; the Technologies list/edit views are untouched. `/admin/tech-tree` — visual tech tree editor over `technologies`, built on `@xyflow/react` v12 following the narrative-flow patterns. Custom admin view (root view) + a "Tech Tree" nav entry injected under the Intelligence group; the Technologies list/edit views are untouched.
- **Schema**: `tech-categories` collection (`src/collections/intelligence/TechCategories.ts`: `name` unique, `position` number = timeline order, optional hex `color`) + `Technologies.category` relationship (FK `ON DELETE set null`, so deleting a category just unfiles its techs) + `Technologies.treePosition` group (`x`/`y` numbers; manual canvas position from dragging, empty = automatic). Permissions mirror technologies (`tech-categories:*` + `admin:tech-categories:manage`, registered in `src/permissions/index.ts`); `tech-categories` is in `DIVISION_ADMIN_QUALIFICATIONS`, so Intelligence division members get admin-panel access exactly like `technologies`. Migrations: `20260930_230747_add_tech_categories`, `20261001_000320_add_tech_tree_position`. - **Schema**: `tech-categories` collection (`src/collections/intelligence/TechCategories.ts`: `name` unique, `position` number = timeline order, optional hex `color`) + `Technologies.category` relationship (FK `ON DELETE set null`, so deleting a category just unfiles its techs) + `Technologies.treePosition` group (`x`/`y` numbers; manual canvas position from dragging, empty = automatic). Permissions mirror technologies (`tech-categories:*` + `admin:tech-categories:manage`, registered in `src/permissions/index.ts`); `tech-categories` is in `DIVISION_ADMIN_QUALIFICATIONS`, so Intelligence division members get admin-panel access exactly like `technologies`. Migrations: `20260930_230747_add_tech_categories`, `20261001_000320_add_tech_tree_position`.
- **Note nodes**: `tech-tree-notes` (`src/collections/intelligence/TechTreeNotes.ts`, `admin.hidden`, no sidebar page) are amber annotation cards on the canvas, deliberately NOT technologies: no prerequisites, cost rows, approval workflow or research state, so `computeLayout`, edge building and the research rules never see them. Fields: `title` (required), `body` (textarea, line breaks preserved), `showOnFrontend` (checkbox, **false by default**), `treePosition` group. Access reuses the `technologies` permissions (`read`/`create`/`update`/`delete`), so no permission group or admin-page gate was added; notes are created, edited and deleted only from the canvas (`NoteDialog`, "+ New Note" toolbar button) and the delete button is hidden without `technologies:delete`. A new note lands at the viewport centre; untouched notes park in an automatic column one step right of the tree (`notes.ts` `computeNoteLayout`). Note React Flow ids are namespaced `note-<id>` (`noteNodeId`/`parseNoteNodeId`) so they can never collide with technology ids, and note cards have no handles, so they can never become prerequisite endpoints. Note drags, Save positions and Auto-arrange reuse the bulk `/api/tech-tree/positions` write by sending `collection: "tech-tree-notes"` (the route swaps the target table and the token source); never add a PATCH-per-note path. Ticking `showOnFrontend` publishes the note to the member tech tree, which queries `showOnFrontend: { equals: true }` and renders the same amber card read-only; unpublished notes never reach members. Notes are edge-routing obstacles in both canvases. - **Note nodes**: `tech-tree-notes` (`src/collections/intelligence/TechTreeNotes.ts`, `admin.hidden`, no sidebar page) are annotation cards on the canvas, deliberately NOT technologies: no prerequisites, cost rows, approval workflow or research state, so `computeLayout`, edge building and the research rules never see them. **Visual contract**: a note must not look like a technology card. It uses a deliberately different silhouette (`NoteNode.tsx`): warm paper-tinted fill (`#1b1409`), chunky dashed amber border, a vertical `NOTE` rail instead of the tech classification strip, a folded top-right corner, no corner brackets, no readout footer (the status line sits at the bottom of the body) and no connection handles. Keep it that way; do not "harmonise" it back to the tech card chrome. Fields: `title` (required), `body` (textarea, line breaks preserved), `showOnFrontend` (checkbox, **false by default**), `treePosition` group. Access reuses the `technologies` permissions (`read`/`create`/`update`/`delete`), so no permission group or admin-page gate was added; notes are created, edited and deleted only from the canvas (`NoteDialog`, "+ New Note" toolbar button) and the delete button is hidden without `technologies:delete`. A new note lands at the viewport centre; untouched notes park in an automatic column one step right of the tree (`notes.ts` `computeNoteLayout`). Note React Flow ids are namespaced `note-<id>` (`noteNodeId`/`parseNoteNodeId`) so they can never collide with technology ids, and note cards have no handles, so they can never become prerequisite endpoints. Note drags, Save positions and Auto-arrange reuse the bulk `/api/tech-tree/positions` write by sending `collection: "tech-tree-notes"` (the route swaps the target table and the token source); never add a PATCH-per-note path. Ticking `showOnFrontend` publishes the note to the member tech tree, which queries `showOnFrontend: { equals: true }` and renders the same amber card read-only; unpublished notes never reach members. Notes are edge-routing obstacles in both canvases.
- **View wiring**: `payload.config.ts` `admin.components.views.techTree` (path `/tech-tree`, component `src/components/admin/tech-tree/TechTreeView.tsx`) and `admin.components.Nav` → `TechTreeNav.tsx`. Custom root views are public by default, so the view gates itself (logged-in + `technologies:read` OR Intelligence qualification). The nav replica injects the entry into the group containing `technologies` and reuses public exports (`NavWrapper`/`NavHamburger`/`DefaultNavClient` from `@payloadcms/next/client`, `groupNavItems` from `@payloadcms/ui/shared`); registered admin components must be **default exports** (importMap convention in this repo). - **View wiring**: `payload.config.ts` `admin.components.views.techTree` (path `/tech-tree`, component `src/components/admin/tech-tree/TechTreeView.tsx`) and `admin.components.Nav` → `TechTreeNav.tsx`. Custom root views are public by default, so the view gates itself (logged-in + `technologies:read` OR Intelligence qualification). The nav replica injects the entry into the group containing `technologies` and reuses public exports (`NavWrapper`/`NavHamburger`/`DefaultNavClient` from `@payloadcms/next/client`, `groupNavItems` from `@payloadcms/ui/shared`); registered admin components must be **default exports** (importMap convention in this repo).
- **Layout** (`layout.ts`, pure): a **propagating left-to-right tree**. A technology WITH prerequisites is placed one column to the right of its parents, at their average row, so linking A -> B drops B immediately beside A and B's dependents continue further right; nothing is teleported to a distant column when its depth changes. Technologies in a category stay pinned to that category's column (the category contract); uncategorized roots fill a catalog grid whose slots come from each tech's rank among ALL uncategorized technologies (`MAX_ROWS_PER_COLUMN` = 10 rows, spilling into more columns) so promoting a tech into the tree leaves an empty slot rather than re-shuffling the grid; uncategorized dependents follow their parents inside the uncategorized zone. Collisions search rows outward from the desired row (dependents may also grow upward, and their columns are not height-capped, so a link from a full column still lands beside its parent rather than far right). Category bands are the bounding box of their members' final positions. Prerequisites placed to the RIGHT of their dependent surface as amber warnings (toolbar chip + node icon + preview panel section). - **Layout** (`layout.ts`, pure): a **propagating left-to-right tree**. A technology WITH prerequisites is placed one column to the right of its parents, at their average row, so linking A -> B drops B immediately beside A and B's dependents continue further right; nothing is teleported to a distant column when its depth changes. Technologies in a category stay pinned to that category's column (the category contract); uncategorized roots fill a catalog grid whose slots come from each tech's rank among ALL uncategorized technologies (`MAX_ROWS_PER_COLUMN` = 10 rows, spilling into more columns) so promoting a tech into the tree leaves an empty slot rather than re-shuffling the grid; uncategorized dependents follow their parents inside the uncategorized zone. Collisions search rows outward from the desired row (dependents may also grow upward, and their columns are not height-capped, so a link from a full column still lands beside its parent rather than far right). Category bands are the bounding box of their members' final positions. Prerequisites placed to the RIGHT of their dependent surface as amber warnings (toolbar chip + node icon + preview panel section).
- **Edges**: AND prerequisites solid slate, OR prerequisites dashed cyan with an OR label. Connections are editable on the canvas: drag from a node's right handle onto another node (the target card OR its handle) to add it as an AND prerequisite; the drop-on-card case is resolved by an `onConnectEnd` fallback because React Flow only resolves drops onto a handle. Select an edge and press Backspace to remove the prerequisite. Duplicates, self-references, and cycles (direct or transitive) are rejected by the pure `prereqEdits.ts` helpers with an inline error in the toolbar. Lines are also manually routable: selecting an edge reveals a "+" handle at each segment's midpoint (click to add a bend), bends drag to move, and double-clicking a bend removes it (`RoutedEdge.tsx` + `edgeRoutes.ts`). Routes are stored per browser in `localStorage`; making them shared would need a persisted field on the target technology. Edges also route around technologies they are not connected to: `edgeRouting.ts` detours each segment around the node rectangles it would cross (inflated by a clearance margin) and `buildRoutePath` rounds every corner. An unrouted edge keeps its automatic out/across/in shape unless that path would cut through a node, in which case it falls back to a direct line the router can bend around. - **Edges**: AND prerequisites solid slate, OR prerequisites dashed cyan with an OR label. Connections are editable on the canvas: drag from a node's right handle onto another node (the target card OR its handle) to add it as an AND prerequisite; the drop-on-card case is resolved by an `onConnectEnd` fallback because React Flow only resolves drops onto a handle. Select an edge and press Backspace to remove the prerequisite. Duplicates, self-references, and cycles (direct or transitive) are rejected by the pure `prereqEdits.ts` helpers with an inline error in the toolbar. Lines are also manually routable: selecting an edge reveals a "+" handle at each segment's midpoint (click to add a bend), bends drag to move, and double-clicking a bend removes it (`RoutedEdge.tsx` + `edgeRoutes.ts`). Routes are stored per browser in `localStorage`; making them shared would need a persisted field on the target technology. Edges also route around technologies they are not connected to: `edgeRouting.ts` detours each segment around the node rectangles it would cross (inflated by a clearance margin) and `buildRoutePath` rounds every corner. An unrouted edge keeps its automatic out/across/in shape unless that path would cut through a node, in which case it falls back to a direct line the router can bend around.

View file

@ -14,67 +14,79 @@ export type NoteNodeData = {
export type NoteNodeModel = Node<NoteNodeData, "noteCard">; export type NoteNodeModel = Node<NoteNodeData, "noteCard">;
/** /**
* Amber annotation card. Fixed chrome on purpose: a note must never be * Memo card for canvas annotations.
* mistaken for a technology (cyan) or a category band (category accent), in the *
* admin editor or on the member-facing tree. It has no handles, so it can never * Deliberately a different silhouette from a technology card, not just a
* become a prerequisite endpoint. * different accent colour: no classification strip, no readout footer, no
* corner brackets, a dashed amber border, a warm paper-tinted fill and a
* vertical rail label. At fit-view zoom (where the text is illegible) the warm
* tint and dashed edge are what separate it from the near-black tech cards; up
* close the vertical NOTE rail and folded corner do. It has no handles either,
* so it can never become a prerequisite endpoint.
*/ */
export function NoteNodeCard({ data, selected }: NodeProps<NoteNodeModel>) { export function NoteNodeCard({ data, selected }: NodeProps<NoteNodeModel>) {
const { note } = data; const { note } = data;
return ( return (
<div <div data-testid={`tech-note-${note.id}`} className="relative h-full w-full">
data-testid={`tech-note-${note.id}`}
className="relative h-full w-full"
>
<div <div
className={`flex h-full w-full flex-col overflow-hidden rounded-none border bg-black/70 backdrop-blur-sm transition-colors ${ className={`relative flex h-full w-full overflow-hidden border border-dashed bg-[#1b1409]/95 backdrop-blur-sm transition-colors ${
selected selected
? "border-amber-300/80 shadow-[0_0_18px_rgba(251,191,36,0.18)]" ? "border-amber-300 shadow-[0_0_20px_rgba(251,191,36,0.22)]"
: "border-amber-400/40 hover:border-amber-300/70" : "border-amber-400/55 hover:border-amber-300/80"
}`} }`}
style={{ borderTopWidth: 2 }}
> >
{/* Classification strip */} {/* Folded corner: the page-coloured triangle reads as a peeled note,
<div className="flex h-7 shrink-0 items-center justify-between gap-2 border-b border-amber-400/25 bg-amber-400/10 px-3.5"> which no technology card has. */}
<span className="truncate leading-none font-mono text-[8px] tracking-widest text-amber-200/80 uppercase"> <span
NOTE // ANNOTATION aria-hidden
className="pointer-events-none absolute top-0 right-0 size-3.5 bg-[#05070a]"
style={{ clipPath: "polygon(100% 0%, 0% 0%, 100% 100%)" }}
/>
{/* Vertical rail label instead of a horizontal classification strip */}
<div className="flex w-[22px] shrink-0 flex-col items-center justify-between border-r border-dashed border-amber-400/40 bg-amber-400/10 py-2">
<span className="font-mono text-[8px] tracking-[0.25em] text-amber-200/70 uppercase [writing-mode:vertical-rl]">
Note
</span> </span>
<span <span
className={`shrink-0 leading-none font-mono text-[8px] tracking-widest uppercase ${ aria-hidden
note.showOnFrontend ? "text-emerald-300" : "text-white/35" className={`size-1.5 shrink-0 rounded-full ${
note.showOnFrontend
? "bg-emerald-300/80 shadow-[0_0_6px_rgba(110,231,183,0.55)]"
: "bg-amber-300/50"
}`} }`}
> />
{note.showOnFrontend ? "PUBLISHED" : "INTERNAL"}
</span>
</div> </div>
{/* Body: the title keeps a fixed two-line slot and the detail text takes {/* Body: the title keeps a fixed two-line slot and the detail text takes
whatever height is left, so a long title can never clip the body to whatever height is left, so a long title can never clip the body to
nothing (the card height is fixed by the canvas). */} nothing (the card height is fixed by the canvas). */}
<div className="flex min-h-0 flex-1 flex-col overflow-hidden px-3.5 py-2"> <div className="flex min-h-0 min-w-0 flex-1 flex-col px-3 py-2">
<div className="line-clamp-2 shrink-0 text-[13px] leading-tight font-semibold text-amber-50"> <div className="line-clamp-2 shrink-0 text-[13px] leading-tight font-semibold text-amber-50">
{note.title} {note.title}
</div> </div>
{note.body.trim() ? ( {note.body.trim() ? (
<p className="mt-1 min-h-0 flex-1 overflow-hidden text-[10px] leading-snug whitespace-pre-wrap text-white/60"> <p className="mt-1 min-h-0 flex-1 overflow-hidden text-[10px] leading-snug whitespace-pre-wrap text-amber-100/55">
{note.body} {note.body}
</p> </p>
) : ( ) : (
<p className="mt-1 shrink-0 leading-none font-mono text-[8px] tracking-widest text-white/25 uppercase"> <p className="mt-1 shrink-0 leading-none font-mono text-[8px] tracking-widest text-amber-100/25 uppercase">
No details No details
</p> </p>
)} )}
</div> <div className="mt-1 flex shrink-0 items-center gap-1.5">
<span
{/* Footer readout */} className={`font-mono text-[8px] leading-none tracking-widest uppercase ${
<div className="flex h-6 shrink-0 items-center justify-between border-t border-amber-400/25 bg-black/60 px-3.5"> note.showOnFrontend ? "text-emerald-300/80" : "text-amber-200/40"
<span className="leading-none font-mono text-[8px] tracking-widest text-amber-200/60 uppercase"> }`}
Annotation >
</span> {note.showOnFrontend ? "Published" : "Internal"}
<span className="leading-none font-mono text-[8px] tracking-widest text-white/35 uppercase"> </span>
NOT RESEARCHABLE <span className="font-mono text-[8px] leading-none tracking-widest text-amber-200/25 uppercase">
</span> // Annotation
</span>
</div>
</div> </div>
</div> </div>
</div> </div>