Skip to content

feat(voyager): Related Entities sidebar tab + focused sub-graph#93

Merged
allmonday merged 1 commit into
masterfrom
feat/005-related-entities-tab
Jun 30, 2026
Merged

feat(voyager): Related Entities sidebar tab + focused sub-graph#93
allmonday merged 1 commit into
masterfrom
feat/005-related-entities-tab

Conversation

@allmonday

Copy link
Copy Markdown
Collaborator

Summary

  • 新增 ER 图侧边栏的 Related Entities tab:在双击打开的侧边栏里渲染一张只读的迷你 ER 子图(所选实体 + 直接邻居 + 关联边),用独立的 d3-graphviz 实例渲染后端返回的 DOT —— 与主图同构。
  • 子图复用主图的渲染配置(show module cluster / show methods / edge length),随主图配置或所选实体的变化自动重新渲染(spec FR-015);子图本身不暴露任何配置项
  • 顺手修复了侧边栏响应性(spec FR-011/012/013):
    • 侧边栏已打开时,画布上单击其他 entity 即可让侧边栏跟随更新(之前只有双击才更新)。
    • 画布空白处纯点击关闭侧边栏;拖拽(平移视图)不关闭(5px 阈值,复用现有 mousedown/mouseup 位移判定)。
    • 切换实体时保留当前激活的 tab(FR-012),加 protective comment 防回归。

Changes

Backend (src/nexusx/voyager/)

  • er_diagram_dot.pyErDiagramDotBuilder.filter_to_neighborhood(schema_name):在 analysis() 之后把 nodes/links 收窄到一层邻域;保留自引用与平行边。
  • voyager_context.pyget_er_diagram_subgraph(payload):响应结构与 get_er_diagram_data 完全一致;未知 schema 短路为空。
  • create_voyager.pyErDiagramSubgraphPayload + POST /er-diagram-subgraph

Frontend (src/nexusx/voyager/web/)

  • component/related-entities-display.js(新)— RelatedEntitiesDisplay Vue 组件:独立 d3-graphviz 实例;四态(加载 / 正常 / 孤立节点+文案 / 错误);只读 + pan/zoom;watch schemaName 与 filter 配置触发响应式 refetch。
  • component/schema-code-display.js — 第三个 <q-tab name="related">(由 showRelatedEntities prop 门控,仅 ER-diagram 模式显示)+ panel 挂载新组件;FR-012 protective comment。
  • store.jsrelatedEntities 状态 + fetchRelatedEntities / clearRelatedEntities actions + buildErDiagramSubgraphPayload helper;clearRelatedEntities 接入 resetDetailPanels
  • vue-main.js — 注册 RelatedEntitiesDisplay;给 GraphUIisSidebarOpen getter。
  • graph-ui.js — FR-011(单击 + 侧边栏开 → 触发 onSchemaClick)+ FR-013(mousedown 位移追踪 + drag 阈值)。
  • index.html — 给 schema-code-display:show-related-entities

Spec / Design artifacts

specs/005-related-entities-tab/:spec → plan → research → data-model → contracts/{api,ui} → quickstart → tasks(+ checklists/requirements.md)。

Test plan

  • 后端单元测试 tests/test_voyager_subgraph.py(11 tests,覆盖 quickstart A1–A5 + FR-009 边方向 + FR-010 平行边)
  • 全量回归:uv run pytest -q1123 passed, 6 skipped(基线 1118 + 新增 11 = 1129;1123+6=1129 ✓)
  • uv run ruff check clean
  • 端到端冒烟(demo enterprise_voyager):POST /er-diagram-subgraph for Organization → 5 nodes(Organization + Workspace/Department/Office/Vendor)+ 8 links,全部触碰 anchor;未知 schema → 空 dot;show_moduleedge_minlen 变化时 DOT 改变(配置跟随成立)。
  • 请人工验证(浏览器交互,我无法点击):
    • 双击 entity → 侧边栏出现 "Related Entities" tab
    • 单击其他 entity(侧边栏开时)→ 侧边栏跟随更新,tab 保留(FR-011/FR-012)
    • 空白处纯点击关闭侧边栏;拖拽平移不关闭(FR-013)
    • 切换主面板 show module cluster / show methods / edge length → 子图跟随重渲染(FR-015)
    • 边类型/方向在子图中视觉可区分(FR-009)

🤖 Generated with Claude Code

Add a read-only "Related Entities" tab to the ER diagram double-click
sidebar. It renders a focused mini ER sub-graph (selected entity + its
direct neighbors + incident edges) using an independent d3-graphviz
instance, reusing the main graph's rendering config (show module cluster /
show methods / edge length) so the sub-graph stays in sync as the user
tweaks the main panel or selects another entity.

Backend:
- ErDiagramDotBuilder.filter_to_neighborhood(schema_name) prunes the
  built nodes/links to the one-level neighborhood after analysis().
- VoyagerContext.get_er_diagram_subgraph mirrors get_er_diagram_data's
  response shape; returns empty dot for unknown schema.
- New POST /er-diagram-subgraph endpoint + ErDiagramSubgraphPayload.

Frontend:
- New RelatedEntitiesDisplay component (read-only, pan/zoom, four states:
  loading / normal / isolated-with-hint / error).
- schema-code-display gains a third tab (gated by showRelatedEntities).
- store gains relatedEntities state + fetch/clear actions; clearRelatedEntities
  is wired into resetDetailPanels.

Also fixes sidebar responsiveness (spec FR-011/012/013):
- Single-click on the canvas now re-points the open sidebar (was: only
  double-click did). Idempotent.
- Background click closes the sidebar; a drag (pan) does not (5px threshold
  via mousedown tracking).
- Tab persistence across entity switches is preserved and guarded with a
  protective comment in resetState.

Tests: tests/test_voyager_subgraph.py adds 11 tests (quickstart A1-A5 +
FR-009 edge direction + FR-010 parallel edges). Full suite 1123 passed,
6 skipped. ruff clean.

Spec: specs/005-related-entities-tab/ (spec / plan / research /
data-model / contracts/{api,ui} / quickstart / tasks).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@allmonday allmonday merged commit e965bff into master Jun 30, 2026
6 checks passed
allmonday added a commit that referenced this pull request Jun 30, 2026
Version bump for PR #93 (feat: Voyager Related Entities sidebar tab +
focused sub-graph) plus the sidebar-follows-selection fixes bundled in
the same PR. Updates CHANGELOG, pyproject.toml, uv.lock.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant