1
0
Fork 0
polaris-task-force/src/components/admin/tech-tree/notes.ts
Z8MB1E 48556c3688 feat(tech-tree): add note nodes with optional frontend visibility
Planners can now drop annotation cards on the Tech Tree canvas without inventing fake technologies. Notes live in their own tech-tree-notes collection (title, body, treePosition) and carry no prerequisites, costs, approval workflow or research state, so the layout engine, edge builder and research rules never see them.

showOnFrontend defaults to false, making notes a backend authoring aid; ticking it publishes the amber card read-only to the member tech tree, which queries showOnFrontend = true.

Canvas work: amber NoteNode card with no connection handles, NoteDialog for create/edit/delete, a New Note toolbar button (technologies:create gated), viewport-centre placement, and namespaced note-<id> React Flow ids so note and technology ids can never collide. Note drags, Save positions and Auto-arrange reuse the single-statement bulk /api/tech-tree/positions write by sending collection: "tech-tree-notes"; no PATCH-per-note path was added.

Also fixes the note card body being clipped by the inherited line-height: the classification strip and footer now have fixed heights with leading-none, and the body takes the remaining flex space instead of line-clamp.

Tests: tech-tree-notes.int.spec.ts (defaults, required title, publication filter, in-place edits, note layout and id namespacing) plus note coverage in tech-tree-positions.int.spec.ts. Migration 20261123_073019_add_tech_tree_notes must be run on prod after deploy.
2026-11-23 03:11:36 -05:00

55 lines
1.8 KiB
TypeScript

import { COLUMN_STEP, ROW_STEP, type TreeNote, type TechTreeLayout } from "./types";
/**
* Pure layout helpers for Tech Tree note nodes.
*
* Notes are annotations, not technologies: they never enter `computeLayout`,
* never affect edges, and are not counted as prerequisites or columns. A note
* only owns a canvas position:
* - dragged notes use their manual `treePosition`;
* - untouched notes stack in a dedicated notes column to the right of the
* technology columns, in creation order.
*
* Note node ids are prefixed so a note id can never collide with a technology
* id in the React Flow node list (both are independent auto-increment integers).
*/
export const NOTE_NODE_PREFIX = "note-";
export function noteNodeId(noteId: number): string {
return `${NOTE_NODE_PREFIX}${noteId}`;
}
/** Returns the note id for a note node id, or null for any other node. */
export function parseNoteNodeId(nodeId: string): number | null {
if (!nodeId.startsWith(NOTE_NODE_PREFIX)) return null;
const id = Number(nodeId.slice(NOTE_NODE_PREFIX.length));
return Number.isInteger(id) && id > 0 ? id : null;
}
export type NoteLayoutNode = {
noteId: number;
x: number;
y: number;
};
/**
* Positions for every note. `tree.columns` is the number of technology
* columns in use, so the fallback notes column sits one step to its right
* (column 0 when the tree is empty).
*/
export function computeNoteLayout(
notes: TreeNote[],
tree: Pick<TechTreeLayout, "columns">,
): NoteLayoutNode[] {
const fallbackColumn = Math.max(0, tree.columns);
let nextRow = 0;
return notes.map((note) => {
if (note.treePosition) {
return { noteId: note.id, x: note.treePosition.x, y: note.treePosition.y };
}
const row = nextRow;
nextRow += 1;
return { noteId: note.id, x: fallbackColumn * COLUMN_STEP, y: row * ROW_STEP };
});
}