Skip to content

feat(memory-graph): add onNodeSelect callback for selection changes#1350

Open
abhay-codes07 wants to merge 1 commit into
supermemoryai:mainfrom
abhay-codes07:feat/graph-on-node-select
Open

feat(memory-graph): add onNodeSelect callback for selection changes#1350
abhay-codes07 wants to merge 1 commit into
supermemoryai:mainfrom
abhay-codes07:feat/graph-on-node-select

Conversation

@abhay-codes07

Copy link
Copy Markdown
Contributor

Motivation

selectedNode lives entirely inside MemoryGraph. A host that embeds the graph currently has no way to observe which node is selected except through onSlideshowNodeChange (slideshow mode only) or onOpenDocument (fires only on the explicit open-document action). So common integrations are awkward: showing details in the host's own side panel, syncing the selection into the URL, or firing analytics when a user selects a node.

Change

Add an optional, backward-compatible onNodeSelect?: (nodeId: string | null) => void prop:

<MemoryGraph
  documents={documents}
  onNodeSelect={(nodeId) => {
    // nodeId is null when the selection is cleared
    setActivePanelNode(nodeId)
  }}
/>

It fires whenever the selection changes, regardless of source (click, keyboard navigation, slideshow, or clearing), with null when nothing is selected.

Implementation notes:

  • Emitted from an effect keyed only on the selection state; the callback is read through a ref, so a changing callback identity does not re-fire it and does not force the effect to re-run. This mirrors the existing onSlideshowNodeChangeRef pattern already used in this component.
  • The selection stays fully uncontrolled — this is an observation hook, not a controlled prop.
  • The initial mount is skipped, so a host does not receive a spurious null before any interaction.

Verification

tsc --noEmit clean, vite build succeeds, and the full package suite (198 tests) passes. I did not add a unit test that drives a live selection because the full MemoryGraph mount needs a real canvas/container size that happy-dom does not provide (the existing onSlideshowNodeChange / onOpenDocument callback props are untested for the same reason). Happy to wire this differently if you would prefer it emitted inline at the click/keyboard call sites instead of from the selection effect.

Selection lived entirely inside MemoryGraph, so a host embedding the graph had
no way to observe which node is selected outside of slideshow mode
(onSlideshowNodeChange) or the open-document action (onOpenDocument). That makes
common integrations awkward: driving a side panel, syncing selection to the URL,
or firing analytics on select.

Add an optional onNodeSelect(nodeId) prop that fires whenever the selection
changes, regardless of source (click, keyboard navigation, slideshow, or
clearing), with null when nothing is selected. It is emitted from an effect
keyed on the selection state and reads the callback through a ref, so a changing
callback identity does not re-fire it and the selection stays uncontrolled. The
initial mount is skipped so a host does not receive a spurious null before any
interaction. Purely additive and backward compatible.
Copilot AI review requested due to automatic review settings July 24, 2026 06:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants