1
0
Fork 0
polaris-task-force/src/components/admin/tech-tree/NoteNode.tsx
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

82 lines
3.1 KiB
TypeScript

"use client";
import type { Node, NodeProps } from "@xyflow/react";
import React from "react";
import type { TreeNote } from "./types";
export type NoteNodeData = {
note: TreeNote;
/** Editor-only controls are handled by the canvas; the card stays read-only. */
connectable?: boolean;
};
export type NoteNodeModel = Node<NoteNodeData, "noteCard">;
/**
* Amber annotation card. Fixed chrome on purpose: a note must never be
* 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
* become a prerequisite endpoint.
*/
export function NoteNodeCard({ data, selected }: NodeProps<NoteNodeModel>) {
const { note } = data;
return (
<div
data-testid={`tech-note-${note.id}`}
className="relative h-full w-full"
>
<div
className={`flex h-full w-full flex-col overflow-hidden rounded-none border bg-black/70 backdrop-blur-sm transition-colors ${
selected
? "border-amber-300/80 shadow-[0_0_18px_rgba(251,191,36,0.18)]"
: "border-amber-400/40 hover:border-amber-300/70"
}`}
style={{ borderTopWidth: 2 }}
>
{/* Classification strip */}
<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">
<span className="truncate leading-none font-mono text-[8px] tracking-widest text-amber-200/80 uppercase">
NOTE // ANNOTATION
</span>
<span
className={`shrink-0 leading-none font-mono text-[8px] tracking-widest uppercase ${
note.showOnFrontend ? "text-emerald-300" : "text-white/35"
}`}
>
{note.showOnFrontend ? "PUBLISHED" : "INTERNAL"}
</span>
</div>
{/* 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
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="line-clamp-2 shrink-0 text-[13px] leading-tight font-semibold text-amber-50">
{note.title}
</div>
{note.body.trim() ? (
<p className="mt-1 min-h-0 flex-1 overflow-hidden text-[10px] leading-snug whitespace-pre-wrap text-white/60">
{note.body}
</p>
) : (
<p className="mt-1 shrink-0 leading-none font-mono text-[8px] tracking-widest text-white/25 uppercase">
No details
</p>
)}
</div>
{/* Footer readout */}
<div className="flex h-6 shrink-0 items-center justify-between border-t border-amber-400/25 bg-black/60 px-3.5">
<span className="leading-none font-mono text-[8px] tracking-widest text-amber-200/60 uppercase">
Annotation
</span>
<span className="leading-none font-mono text-[8px] tracking-widest text-white/35 uppercase">
NOT RESEARCHABLE
</span>
</div>
</div>
</div>
);
}