From 6892017360094e97eb42da9b2fe6db18f2e5b84d Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Thu, 15 Oct 2026 08:20:57 +0000 Subject: [PATCH 1/2] feat(graph): edit and merge entities and topics from the graph explorer An entity's or topic's panel opens the same editor as its own page, and an entity's panel has Merge (a find box) and Maybe the same. The node menu has Edit and Merge into another, which merges the node into the one clicked next: entities and speakers of one namespace, entities of two namespaces linked as the same thing. Each happens at once with Undo on its notice. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EzVhJCpwskyo5NhHEtS822 --- CHANGELOG.md | 4 + ci/clicks/journeys.mjs | 31 +++++ docs/graph.md | 8 ++ .../__tests__/graph-curate.test.ts | 60 ++++++++++ .../components/entities/curate.tsx | 36 ++++++ .../components/graph/explorer-ui.tsx | 31 ++++- .../components/graph/graph-page.tsx | 74 +++++++++++- nextjs-frontend/components/graph/join.ts | 111 ++++++++++++++++++ nextjs-frontend/components/graph/panel.tsx | 89 ++++++++++++-- .../components/topics/topic-drawer.tsx | 12 +- 10 files changed, 439 insertions(+), 17 deletions(-) create mode 100644 nextjs-frontend/__tests__/graph-curate.test.ts create mode 100644 nextjs-frontend/components/graph/join.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 604b328f1..f17b05ff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version side panel has **Merge**, a find box where Enter merges the entity picked into it, and **Maybe the same**, its likely doubles with **Merge** and **Not the same**. Renaming an entity to another's name offers to merge them. Merges, type changes and hiding say what happened with **Undo** ([Entities](docs/processing.md#entities-and-the-graph-explorer)). +- **Edit and merge from the graph.** In the graph explorer, an entity's or topic's panel has **Edit**, which opens the + same editor as its own page, and an entity's has **Merge** and **Maybe the same**. The node menu has **Edit…** and + **Merge into another…**, which merges the node into the one clicked next (entities and speakers of one namespace; + entities of two namespaces are linked as the same thing), each with **Undo** ([The graph](docs/graph.md)). ## 0.9.0 October 15, 2026 {id="0.9.0"} diff --git a/ci/clicks/journeys.mjs b/ci/clicks/journeys.mjs index 304f62509..40b1ae1b2 100644 --- a/ci/clicks/journeys.mjs +++ b/ci/clicks/journeys.mjs @@ -661,6 +661,37 @@ export const JOURNEYS = [ await page.getByText("Merge undone").first().waitFor(); }, }, + { + id: "graph-merge", + ns: "interviews", + module: "Graph", + feature: "Merge an entity into another from the graph, then undo it", + note: "Find the node, Merge in its panel, type the other's name and Enter; the notice has Undo, so nothing asks to confirm.", + from: "/", + async run(ctx) { + const { page, meter } = ctx; + await go(ctx, "Graph"); + const find = page.getByRole("combobox", { name: "Find in graph" }); + await page.getByRole("region", { name: "Graph" }).waitFor(); + await page.waitForTimeout(1000); + // On a phone the filters, the find box among them, sit behind a button + if (!(await find.isVisible())) await meter.click(page.getByRole("button", { name: "Filters" }), "Filters"); + await meter.type(find, "rasp", "part of the name"); + await page.getByRole("option", { name: /Raspberry Pi/ }).first().waitFor(); + await meter.press("Enter", "Enter to pick it"); + const filters = page.getByRole("dialog", { name: "Graph filters" }); + if (await filters.isVisible().catch(() => false)) + await meter.click(filters.getByRole("button", { name: "Close" }), "close the filters (they stay open over the node)"); + await page.getByRole("heading", { name: "Raspberry Pi" }).first().waitFor(); + await meter.click(page.getByRole("button", { name: "Merge", exact: true }).first(), "Merge in its panel"); + await meter.type(page.getByRole("combobox", { name: "Entity to merge into Raspberry Pi" }), "lens", "the other's name"); + await page.getByRole("option", { name: /^Lens/ }).first().waitFor(); + await meter.press("Enter", "Enter to merge it"); + await page.getByText("Merged Lens into Raspberry Pi").first().waitFor(); + await meter.click(page.getByRole("button", { name: "Undo" }), "Undo on the notice"); + await page.getByText("Merge undone").first().waitFor(); + }, + }, { // Last: it points Lens at a cloud model, which the stand-in model behind the journeys above isn't id: "cloud-model", diff --git a/docs/graph.md b/docs/graph.md index 40cd8a0db..f8d6747c3 100644 --- a/docs/graph.md +++ b/docs/graph.md @@ -22,6 +22,14 @@ to itself and has one. On a computer the Find in graph box has the focus, so typ - **Node menu**: right-click a node (long-press on touch, or select it and press M) for its parents, children, all ancestors, all descendants and neighbours, paths to another node (pick it next), a BFS, DFS or radial layout from it, adding it to a route, its details and its page, or hiding it. What is found joins the canvas and lights up. +- **Edit and merge** (editors of the node's namespace): an entity's or topic's panel has **Edit**, which opens the + same editor as its own page (name, type, description, other names; a topic's labels, definition, broader and related + topics), and an entity's has **Merge**, a find box where Enter merges the entity picked into it, and **Maybe the + same**, its likely doubles. From the node menu, **Edit…** does the same and **Merge into another…** merges the node + into the one you pick next: entities of one namespace are merged, entities of two namespaces are linked as the same + thing, and speakers of one namespace are merged. Each happens at once with **Undo** on its notice. A node that joins + entities of several namespaces (all shared) offers **Edit in** each namespace. Looking at an earlier version, the + graph is read-only. - **Route**: add stops from the node menu; the route follows the shortest path between each pair of stops, laid out left to right. - **Ask**: the bar at the bottom takes a question in plain words or Cypher (anything starting with `MATCH`). The diff --git a/nextjs-frontend/__tests__/graph-curate.test.ts b/nextjs-frontend/__tests__/graph-curate.test.ts new file mode 100644 index 000000000..001efce09 --- /dev/null +++ b/nextjs-frontend/__tests__/graph-curate.test.ts @@ -0,0 +1,60 @@ +import { joinKind, joinPlan } from "@/components/graph/join"; +import type { GraphNode } from "@/components/graph/model"; +import { editTarget } from "@/components/graph/panel"; + +jest.mock("@/app/openapi-client", () => ({ Entities: {}, Search: {}, Speakers: {}, Topics: {} })); +jest.mock("next-auth/react", () => ({ useSession: () => ({ data: { accessToken: "t" } }) })); + +const node = (id: string, kind: GraphNode["kind"], refs: number[], ns: string[]): GraphNode => ({ + id, + kind, + label: id, + ns, + weight: 1, + refs, + x: 0, + y: 0, +}); + +const acme = node("e1", "entity", [1], ["pods"]); +const acmeInc = node("e2", "entity", [2], ["pods"]); +const acmeCalls = node("e9", "entity", [9], ["calls"]); +const joined = node("e:acme", "entity", [1, 9], ["calls", "pods"]); +const alice = node("s3", "speaker", [3], ["pods"]); +const al = node("s4", "speaker", [4], ["pods"]); +const topic = node("t5", "topic", [5], ["pods"]); + +describe("editing from the graph", () => { + const editorOf = (only: string) => (_role: "editor", ns: string) => ns === only; + + it("opens an entity or topic of one namespace you edit", () => { + expect(editTarget(acme, editorOf("pods"))).toEqual({ kind: "entity", id: 1, ns: "pods" }); + expect(editTarget(topic, editorOf("pods"))).toEqual({ kind: "topic", id: 5, ns: "pods" }); + expect(editTarget(acmeCalls, editorOf("pods"))).toBeNull(); // a viewer there + expect(editTarget(joined, editorOf("pods"))).toBeNull(); // several namespaces: each opens on its own + expect(editTarget(alice, editorOf("pods"))).toBeNull(); // speakers have their own page + }); +}); + +describe("merging on the canvas", () => { + it("joins entities and speakers of one namespace, nothing that spans several", () => { + expect([joinKind(acme), joinKind(alice), joinKind(joined), joinKind(topic), joinKind(null)]).toEqual([ + "entity", + "speaker", + null, + null, + null, + ]); + }); + + it("merges in a namespace, links across namespaces, and says why when it can't", () => { + expect(joinPlan(acmeInc, acme)).toBe("merge"); + expect(joinPlan(acmeCalls, acme)).toBe("link"); + expect(joinPlan(al, alice)).toBe("merge-speaker"); + expect(joinPlan(acme, acme)).toBe("Pick another node to merge into."); + expect(joinPlan(acme, alice)).toBe("An entity merges into another entity."); + expect(joinPlan(alice, topic)).toBe("A speaker merges into another speaker."); + expect(joinPlan(alice, node("s8", "speaker", [8], ["calls"]))).toBe("Speakers are merged within one namespace."); + expect(joinPlan(acme, joined)).toBe("An entity merges into another entity."); + }); +}); diff --git a/nextjs-frontend/components/entities/curate.tsx b/nextjs-frontend/components/entities/curate.tsx index f00a9bb21..e1fb29bd2 100644 --- a/nextjs-frontend/components/entities/curate.tsx +++ b/nextjs-frontend/components/entities/curate.tsx @@ -109,6 +109,42 @@ export function useMergeEntities() { return { merge, pending }; } +/** Say entities of two namespaces are the same thing (they stay two; the graph joins them), with Undo on the toast. */ +export function useLinkEntities() { + const client = useApiClient(); + const toast = useToast(); + const refresh = useEntityRefresh(); + return useCallback( + async (a: EntityPick, b: EntityPick): Promise => { + try { + await data(Entities.linkEntity({ client, path: { eid: a.id }, body: { with: b.id } })); + refresh(); + toast({ + title: `Linked ${a.name} and ${b.name}`, + body: "They’re in different namespaces, so they stay two entities that the graph shows as the same thing.", + tone: "green", + duration: 10000, + action: { + label: "Undo", + onClick: () => + void data(Entities.unlinkEntity({ client, path: { eid: a.id, other: b.id } })) + .then(() => { + refresh(); + toast({ title: "Link undone", tone: "green" }); + }) + .catch((err) => toast({ title: "Couldn’t undo the link", body: why(err), tone: "red" })), + }, + }); + return true; + } catch (err) { + toast({ title: "Couldn’t link them", body: why(err), tone: "red" }); + return false; + } + }, + [client, refresh, toast], + ); +} + type Found = { id: number; name: string; type_label?: string; mentions?: number; builtin?: string | null }; /** Find an entity of a namespace by typing: the most mentioned first, arrow keys move, Enter picks, Escape leaves. */ diff --git a/nextjs-frontend/components/graph/explorer-ui.tsx b/nextjs-frontend/components/graph/explorer-ui.tsx index 7796e6617..609bdceaa 100644 --- a/nextjs-frontend/components/graph/explorer-ui.tsx +++ b/nextjs-frontend/components/graph/explorer-ui.tsx @@ -6,8 +6,10 @@ import { ArrowUpToLine, EyeOff, GitFork, + GitMerge, Loader2, Network, + Pencil, Route, RotateCcw, Share2, @@ -31,7 +33,8 @@ const ICONS: Record = { neighbours: Share2, }; -/** A node's menu (right-click, long press, or M on the keyboard), opened at a point on the canvas. */ +/** A node's menu (right-click, long press, or M on the keyboard), opened at a point on the canvas. Editors also edit + * an entity or topic from it, and start merging an entity into another one picked next. */ export function NodeMenu({ node, at, @@ -39,6 +42,8 @@ export function NodeMenu({ byId, onClose, onSelect, + onEdit, + onMerge, }: { node: GraphNode | null; at: { x: number; y: number } | null; @@ -46,6 +51,10 @@ export function NodeMenu({ byId: Map; onClose: () => void; onSelect: (id: string) => void; + /** Open this node in its editor; absent when it can't be edited here. */ + onEdit?: () => void; + /** Merge this node into the one picked next; absent when it can't be merged. */ + onMerge?: () => void; }) { const start = ex.pathStart ? byId.get(ex.pathStart) : null; const href = node ? nodeHref(node) : null; @@ -98,6 +107,16 @@ export function NodeMenu({ Rings around this + {onEdit && ( + } onSelect={onEdit}> + Edit… + + )} + {onMerge && ( + } onSelect={onMerge}> + Merge into another… + + )} onSelect(node.id)}>Show details {href && ( @@ -122,6 +141,8 @@ export function ExplorerBar({ version, asOf, onNow, + mergeFrom, + onMergeCancel, }: { ex: Explorer; byId: Map; @@ -130,6 +151,9 @@ export function ExplorerBar({ /** the version shown, when it isn't now */ asOf?: string | null; onNow?: () => void; + /** the node being merged into the one picked next */ + mergeFrom?: string | null; + onMergeCancel?: () => void; }) { const options = LAYOUTS.filter((l) => l.key !== "route" || ex.route.length > 1); const label = (id: string) => byId.get(id)?.label ?? id; @@ -191,6 +215,11 @@ export function ExplorerBar({ Paths from {label(ex.pathStart)}: now pick where to )} + {mergeFrom && onMergeCancel && ( + + Merge {label(mergeFrom)} into: now pick the one to keep + + )} {ex.route.length > 0 && (
diff --git a/nextjs-frontend/components/graph/graph-page.tsx b/nextjs-frontend/components/graph/graph-page.tsx index dc4f36a81..d1c49f37c 100644 --- a/nextjs-frontend/components/graph/graph-page.tsx +++ b/nextjs-frontend/components/graph/graph-page.tsx @@ -7,9 +7,11 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { Admin, Entities, Search } from "@/app/openapi-client"; +import { EntityDrawer } from "@/components/entities/entity-drawer"; import { GraphCanvas } from "@/components/graph/canvas"; import { usePositions, useExplorer } from "@/components/graph/explorer"; import { ExplorerBar, NodeMenu } from "@/components/graph/explorer-ui"; +import { useGraphJoin } from "@/components/graph/join"; import { GraphAsk } from "@/components/graph/graph-ask"; import { GraphFilters } from "@/components/graph/filters"; import { @@ -23,10 +25,11 @@ import { type GraphData, type GraphNode, } from "@/components/graph/model"; -import { NodePanel } from "@/components/graph/panel"; +import { editTarget, NodePanel, type EditTarget } from "@/components/graph/panel"; import { GraphTable } from "@/components/graph/table"; import { VersionPicker } from "@/components/graph/version-picker"; import { useSpeakerDirectory } from "@/components/search/data"; +import { TopicDrawer } from "@/components/topics/topic-drawer"; import { Banner } from "@/components/ui/banner"; import { Button } from "@/components/ui/button"; import { Dialog, Drawer } from "@/components/ui/dialog"; @@ -64,7 +67,7 @@ export function GraphPage() { const router = useRouter(); const pathname = usePathname(); const client = useApiClient(); - const { namespaces, namespace: topNs, admin, loaded } = useArchive(); + const { namespaces, namespace: topNs, admin, loaded, can } = useArchive(); const nsNames = namespaces.map((n) => n.name); const focusParam = params.get("focus"); const urlNs = params.get("ns"); @@ -86,6 +89,9 @@ export function GraphPage() { const [selected, setSelected] = useState(null); const [filtersOpen, setFiltersOpen] = useState(false); const [missing, setMissing] = useState(null); + // the entity or topic open in its editor, and the entity being merged into the next one picked + const [editing, setEditing] = useState(null); + const [mergeFrom, setMergeFrom] = useState(null); const wide = useWide(); const tried = useRef(null); @@ -120,6 +126,8 @@ export function GraphPage() { const toast = useToast(); const onError = useCallback((m: string) => toast({ title: "Couldn’t explore that", body: m, tone: "red" }), [toast]); const ex = useExplorer(scope, onError, asOf); + useEffect(() => setMergeFrom(null), [scope, asOf]); + const { joinable, join: joinNodes } = useGraphJoin(); const [menu, setMenu] = useState<{ id: string; at: { x: number; y: number } } | null>(null); const overview = useMemo(() => graph.data ?? { scope, namespaces: [], nodes: [], edges: [] }, [graph.data, scope]); // the overview plus what was found by exploring, less what was hidden @@ -184,7 +192,25 @@ export function GraphPage() { })(); }, [focusParam, graph.data, all.nodes, scope, dir.speakers.length, dir.isLoading]); + // Merging from a node's menu: the node picked next is kept. Entities of two namespaces are linked instead. + const join = async (from: GraphNode, into: GraphNode) => { + setMergeFrom(null); + if (await joinNodes(from, into)) { + ex.hide(from.id); + setSelected(into.id); + set({ focus: focusKey(into) }); + } + }; + const select = (id: string | null) => { + if (mergeFrom && id) { + const a = byId.get(mergeFrom); + const b = byId.get(id); + if (a && b) { + void join(a, b); + return; + } + } // picking a node while a path is being looked for ends the path there const from = ex.pathStart ? byId.get(ex.pathStart) : null; const to = id ? byId.get(id) : null; @@ -249,6 +275,10 @@ export function GraphPage() { ); const empty = graph.data && all.nodes.length === 0; + const menuNode = menu ? (byId.get(menu.id) ?? null) : null; + const menuEdit = menuNode ? editTarget(menuNode, can) : null; + // an earlier version is for looking: edits go to the graph as it is now + const onEdit = asOf ? undefined : setEditing; return (

Graph

@@ -351,6 +381,8 @@ export function GraphPage() { byId={byId} asOf={asOf} onNow={() => set({ as_of: null })} + mergeFrom={mergeFrom} + onMergeCancel={() => setMergeFrom(null)} version={ select(id)} /> setMenu(null)} onSelect={(id) => select(id)} + onEdit={menuEdit && !asOf ? () => setEditing(menuEdit) : undefined} + onMerge={menuNode && joinable(menuNode) && !asOf ? () => setMergeFrom(menuNode.id) : undefined} />
)} @@ -383,7 +417,14 @@ export function GraphPage() { className="hidden min-h-0 overflow-y-auto border-l border-border px-[18px] py-4 xl:block" > {node ? ( - select(null)} /> + select(null)} + onEdit={onEdit} + /> ) : (

Nothing selected

@@ -403,13 +444,36 @@ export function GraphPage() { >
{node && ( - select(null)} /> + select(null)} + onEdit={onEdit} + /> )}
{filters(false)} + {editing?.kind === "entity" && ( + setEditing(null)} + onOpen={(id) => setEditing({ ...editing, id })} + /> + )} + {editing?.kind === "topic" && ( + setEditing({ ...editing, id })} + onClose={() => setEditing(null)} + /> + )}
); } diff --git a/nextjs-frontend/components/graph/join.ts b/nextjs-frontend/components/graph/join.ts new file mode 100644 index 000000000..ec0dc8747 --- /dev/null +++ b/nextjs-frontend/components/graph/join.ts @@ -0,0 +1,111 @@ +"use client"; + +import { useQueryClient } from "@tanstack/react-query"; +import { useCallback } from "react"; + +import { Speakers } from "@/app/openapi-client"; +import { useLinkEntities, useMergeEntities } from "@/components/entities/curate"; +import type { GraphNode } from "@/components/graph/model"; +import { useToast } from "@/components/ui/toast"; +import { ApiError, data, useApiClient } from "@/lib/api/browser"; +import { useArchive } from "@/lib/hooks/session"; + +/** What one node can join: an entity of one namespace joins another entity (merged in its namespace, linked across + * namespaces) and a speaker joins a speaker of its namespace. A global node joining several namespaces joins nothing. */ +export function joinKind(n: Pick | null | undefined): "entity" | "speaker" | null { + if (!n || n.refs.length !== 1 || n.ns.length !== 1) return null; + return n.kind === "entity" || n.kind === "speaker" ? n.kind : null; +} + +/** How `from` joins `into` (`into` is kept), or why it can't. */ +export function joinPlan( + from: Pick, + into: Pick, +): "merge" | "link" | "merge-speaker" | string { + const k = joinKind(from); + if (into.id === from.id) return "Pick another node to merge into."; + if (!k || joinKind(into) !== k) + return k === "speaker" ? "A speaker merges into another speaker." : "An entity merges into another entity."; + if (k === "speaker") return from.ns[0] === into.ns[0] ? "merge-speaker" : "Speakers are merged within one namespace."; + return from.ns[0] === into.ns[0] ? "merge" : "link"; +} + +/** Merging nodes on the graph canvas: entities (with Undo), entities of two namespaces linked, and speakers. */ +export function useGraphJoin() { + const client = useApiClient(); + const qc = useQueryClient(); + const toast = useToast(); + const { can } = useArchive(); + const { merge } = useMergeEntities(); + const link = useLinkEntities(); + const joinable = useCallback( + (n: GraphNode | null | undefined): boolean => Boolean(n && joinKind(n) && can("editor", n.ns[0])), + [can], + ); + const fail = useCallback( + (title: string, err: unknown) => + toast({ title, body: err instanceof ApiError ? err.message : "Please try again.", tone: "red" }), + [toast], + ); + const speakers = useCallback( + async (from: GraphNode, into: GraphNode): Promise => { + const refresh = () => { + for (const k of ["graph", "speakers", "speaker"]) void qc.invalidateQueries({ queryKey: [k] }); + }; + try { + const r = await data( + Speakers.mergeSpeaker({ client, path: { sid: from.refs[0] }, body: { into: into.refs[0] } }), + ); + refresh(); + toast({ + title: `Merged ${from.label} into ${into.label}`, + tone: "green", + duration: 10000, + action: { + label: "Undo", + onClick: () => + void data(Speakers.undoSpeakerMerge({ client, path: { mid: r.merge_id } })) + .then(() => { + refresh(); + toast({ title: "Merge undone", tone: "green" }); + }) + .catch((err) => fail("Couldn’t undo the merge", err)), + }, + }); + return true; + } catch (err) { + fail("Couldn’t merge them", err); + return false; + } + }, + [client, qc, toast, fail], + ); + /** Join `from` into `into`; true when `from` is gone from the graph (merged). */ + const join = useCallback( + async (from: GraphNode, into: GraphNode): Promise => { + const plan = joinPlan(from, into); + if (plan === "merge-speaker" || plan === "merge" || plan === "link") { + if (!joinable(into)) { + toast({ + title: "You can’t change that one", + body: `It needs the editor role in ${into.ns[0]}.`, + tone: "red", + }); + return false; + } + } + const a = { id: from.refs[0], name: from.label }; + const b = { id: into.refs[0], name: into.label }; + if (plan === "merge") return merge(b, [a]); + if (plan === "merge-speaker") return speakers(from, into); + if (plan === "link") { + await link(b, a); + return false; + } + toast({ title: "Those can’t be merged", body: plan, tone: "red" }); + return false; + }, + [joinable, merge, speakers, link, toast], + ); + return { joinable, join }; +} diff --git a/nextjs-frontend/components/graph/panel.tsx b/nextjs-frontend/components/graph/panel.tsx index 9f2cdaa84..5cfc630b3 100644 --- a/nextjs-frontend/components/graph/panel.tsx +++ b/nextjs-frontend/components/graph/panel.tsx @@ -1,12 +1,14 @@ "use client"; import { useQueries, useQuery } from "@tanstack/react-query"; -import { Loader2, Pause, Play, Search as SearchIcon, X } from "lucide-react"; +import { GitMerge, Loader2, Pause, Pencil, Play, Search as SearchIcon, X } from "lucide-react"; import Link from "next/link"; +import { useEffect, useState } from "react"; import { Entities, Search } from "@/app/openapi-client"; import { nameTone } from "@/components/chat/citation"; import { shortTitle } from "@/components/chat/cite"; +import { MaybeSame, MergeInto } from "@/components/entities/curate"; import { connections, nodeHref, @@ -166,23 +168,38 @@ export function nodeBasis(n: Pick): Simila return null; } -/** The node panel: what it is, where it's mentioned (playable), what it's connected to, and what you can do with it. */ +/** An entity or topic to open in its editor (the same drawer as on its own page). */ +export type EditTarget = { kind: "entity" | "topic"; id: number; ns: string }; + +/** What a node opens in an editor: an entity or topic of one namespace whose editor role you have. A global node + * joining entities of several namespaces has one per namespace, so it opens none by itself. */ +export function editTarget(n: GraphNode, can: (role: "editor", ns: string) => boolean): EditTarget | null { + if ((n.kind !== "entity" && n.kind !== "topic") || n.refs.length !== 1 || n.ns.length !== 1) return null; + return can("editor", n.ns[0]) ? { kind: n.kind, id: n.refs[0], ns: n.ns[0] } : null; +} + +/** The node panel: what it is, where it's mentioned (playable), what it's connected to, and what you can do with it: + * editors edit an entity or topic and merge another entity into it here. */ export function NodePanel({ node, nodes, edges, onSelect, onClose, + onEdit, }: { node: GraphNode; nodes: GraphNode[]; edges: GraphEdge[]; onSelect: (id: string) => void; onClose: () => void; + onEdit?: (t: EditTarget) => void; }) { if (STRUCTURE_KINDS.has(node.kind)) - return ; - return ; + return ( + + ); + return ; } /** A recording, collection or namespace found by exploring: what it is, a link to its page, and its links here. */ @@ -192,16 +209,20 @@ function StructurePanel({ edges, onSelect, onClose, + onEdit, }: { node: GraphNode; nodes: GraphNode[]; edges: GraphEdge[]; onSelect: (id: string) => void; onClose: () => void; + onEdit?: (t: EditTarget) => void; }) { + const { can } = useArchive(); const byId = new Map(nodes.map((n) => [n.id, n])); const links = connections(edges, node.id); const href = nodeHref(node); + const edit = onEdit ? editTarget(node, can) : null; return (
@@ -215,11 +236,18 @@ function StructurePanel({ {typeLabel(node)} {node.ns.length > 0 && ` · ${node.ns.join(", ")}`}

- {href && ( -
- + {(href || edit) && ( +
+ {edit && ( + + )} + {href && ( + + )}
)}

@@ -254,15 +282,20 @@ function ThingPanel({ edges, onSelect, onClose, + onEdit, }: { node: GraphNode; nodes: GraphNode[]; edges: GraphEdge[]; onSelect: (id: string) => void; onClose: () => void; + onEdit?: (t: EditTarget) => void; }) { const client = useApiClient(); const { can } = useArchive(); + const [merging, setMerging] = useState(false); + useEffect(() => setMerging(false), [node.id]); + const edit = onEdit ? editTarget(node, can) : null; const player = useInlinePlayer(); const byId = new Map(nodes.map((n) => [n.id, n])); const links = connections(edges, node.id); @@ -284,6 +317,13 @@ function ThingPanel({ ? `/batches/new?speaker=${node.refs[0]}&ns=${encodeURIComponent(node.ns[0] ?? "")}` : `/batches/new?entity=${node.refs.join(",")}&label=${encodeURIComponent(node.label)}`; const runCount = isSpeaker ? (node.recordings ?? 0) : recs; + // a global node joining several namespaces' entities: each opens on its own + const parts = + onEdit && !isSpeaker && node.refs.length > 1 + ? details + .map((d) => d.data) + .filter((d): d is NonNullable => Boolean(d?.namespace) && can("editor", d!.namespace!)) + : []; return (

@@ -326,7 +366,38 @@ function ThingPanel({ `Run on ${runCount}` )} + {edit && ( + <> + + + + )} + {parts.map((d) => ( + + ))}
+ {edit && ( + + )} + {edit && }

{isSpeaker ? "Recordings" : "Mentions"}

{isSpeaker ? : } diff --git a/nextjs-frontend/components/topics/topic-drawer.tsx b/nextjs-frontend/components/topics/topic-drawer.tsx index 098e4d407..4c2fad8e9 100644 --- a/nextjs-frontend/components/topics/topic-drawer.tsx +++ b/nextjs-frontend/components/topics/topic-drawer.tsx @@ -28,13 +28,14 @@ const same = (a: number[], b: number[]) => a.length === b.length && a.every((x, export function TopicDrawer({ id, ns, - all, + all: given, onSelect, onClose, }: { id: number; ns: string; - all: TopicItem[]; + /** The namespace's topics; looked up when not given (in the graph). */ + all?: TopicItem[]; onSelect: (id: number) => void; onClose: () => void; }) { @@ -43,6 +44,12 @@ export function TopicDrawer({ const toast = useToast(); const { can } = useArchive(); const canEdit = can("editor", ns); + const vocab = useQuery({ + queryKey: ["topics", ns], + queryFn: () => data(Topics.listTopics({ client, query: { ns, limit: 1000 } })), + enabled: !given, + }); + const all = given ?? ((vocab.data?.items ?? []) as TopicItem[]); const t = useQuery({ queryKey: ["topic", id], queryFn: () => data(Topics.getTopic({ client, path: { tid: id } })), @@ -70,6 +77,7 @@ export function TopicDrawer({ qc.invalidateQueries({ queryKey: ["topic"] }); qc.invalidateQueries({ queryKey: ["topics"] }); qc.invalidateQueries({ queryKey: ["recording-topics"] }); + qc.invalidateQueries({ queryKey: ["graph"] }); }; const fail = (title: string) => (err: unknown) => toast({ title, body: err instanceof ApiError ? err.message : "Please try again.", tone: "red" }); From 3cb4846f3b368205c823040841318fcb5faa3a06 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Thu, 15 Oct 2026 08:38:35 +0000 Subject: [PATCH 2/2] fix(entities): Enter in the merge find box picks from the list for what was typed Typing and pressing Enter before the debounced search came back merged the first entity of the list still showing. Enter now waits for that search. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EzVhJCpwskyo5NhHEtS822 --- .../__tests__/entities-curate.test.tsx | 20 +++++++++++++++++++ .../components/entities/curate.tsx | 14 ++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/nextjs-frontend/__tests__/entities-curate.test.tsx b/nextjs-frontend/__tests__/entities-curate.test.tsx index 957ea22bc..e7c7e7473 100644 --- a/nextjs-frontend/__tests__/entities-curate.test.tsx +++ b/nextjs-frontend/__tests__/entities-curate.test.tsx @@ -93,6 +93,26 @@ describe("merging into an entity", () => { expect(m(Entities.undoEntityMerge).mock.calls[0][0].path).toEqual({ mid: 44 }); }); + it("waits for the list of what was typed when Enter comes first", async () => { + const all = [ + { id: 2, name: "Matterbridge", type_label: "Term", mentions: 5 }, + { id: 3, name: "Lens", type_label: "Term", mentions: 2 }, + ]; + m(Entities.listEntities).mockImplementation(({ query }: { query: { q?: string } }) => + ok({ total: 2, items: query.q ? all.filter((e) => e.name.toLowerCase().includes(query.q!)) : all }), + ); + m(Entities.mergeEntities).mockReturnValue(ok({ ok: true, merge: 45 })); + show( undefined} />); + const box = screen.getByRole("combobox", { name: "Entity to merge into Raspberry Pi" }); + await waitFor(() => expect(screen.getAllByRole("option")).toHaveLength(2)); + // typed and Enter at once: the unfiltered list (Matterbridge first) is still showing + fireEvent.change(box, { target: { value: "lens" } }); + fireEvent.keyDown(box, { key: "Enter" }); + await waitFor(() => expect(Entities.mergeEntities).toHaveBeenCalled()); + expect(m(Entities.mergeEntities).mock.calls[0][0].body).toEqual({ keep: 1, others: [3] }); + expect(Entities.mergeEntities).toHaveBeenCalledTimes(1); + }); + it("offers the ones that may be the same, to merge or set apart", async () => { m(Entities.listEntitySuggestions).mockReturnValue( ok([ diff --git a/nextjs-frontend/components/entities/curate.tsx b/nextjs-frontend/components/entities/curate.tsx index e1fb29bd2..7bb2fa5e2 100644 --- a/nextjs-frontend/components/entities/curate.tsx +++ b/nextjs-frontend/components/entities/curate.tsx @@ -200,6 +200,14 @@ export function EntityFind({ onPick({ id: e.id, name: e.name }); setQ(""); }; + // Enter before the list caught up with what was typed picks from the list for that text, not the one still showing + const [want, setWant] = useState(false); + const waiting = found.isFetching || debounced !== q.trim(); + useEffect(() => { + if (!want || waiting) return; + setWant(false); + pick(items[active]); + }); return (
@@ -224,7 +232,11 @@ export function EntityFind({ setActive((a) => Math.max(0, a - 1)); } else if (e.key === "Enter") { e.preventDefault(); - pick(items[active]); + if (!waiting) pick(items[active]); + else { + setDebounced(q.trim()); + setWant(true); + } } else if (e.key === "Escape" && onCancel) { e.preventDefault(); e.stopPropagation();