Skip to content

feat(er-diagram): add accessible key and relationship legend (#1401) - #1428

Merged
NewtTheWolf merged 3 commits into
TabularisDB:mainfrom
markankamaransheogarat-sys:feat/er-diagram-legend-1401
Nov 10, 2026
Merged

NewtTheWolf merged 3 commits into
TabularisDB:mainfrom
markankamaransheogarat-sys:feat/er-diagram-legend-1401

Conversation

@markankamaransheogarat-sys

@markankamaransheogarat-sys markankamaransheogarat-sys commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Resolves #1401.

Adds a compact, collapsible legend component to the Schema ER Diagram explaining primary key (Key), foreign key (Link), and relationship connector representations.

Key Changes

• SchemaDiagramLegend Component (packages/web-ui/src/components/ui/SchemaDiagramLegend.tsx):

  • Accessible collapsible legend explaining actual rendered key markers (Primary Key, Foreign Key) and relationship connector edges.
  • Keyboard accessible: aria-expanded, aria-controls, visible focus outlines, and closes on Escape.
  • Themed styling matching existing UI tokens (bg-elevated, border-strong, text-semantic-pk, text-semantic-fk, bg-accent-primary).
  • Positioned non-intrusively in the ER diagram controls bar.
    • Integration (packages/web-ui/src/components/ui/SchemaDiagram.tsx):
  • Integrated into the ER diagram canvas toolbar without interfering with existing layout toggles, export actions, or zoom/pan viewport navigation.
    • Localization:
  • Added new localized strings (legend, primaryKey, primaryKeyDesc, foreignKey, foreignKeyDesc, relationship, relationshipDesc) across all 13 supported locales (de, en, es, fr, it, ja, ko, pt-BR, ru, tl, vi, zh, zh-TW).
    • Tests:
  • Added unit test suite packages/web-ui/tests/components/ui/SchemaDiagramLegend.test.tsx verifying default collapsed state, expansion/collapse toggling, ARIA attributes, item labels and descriptions, and Escape key dismissal.

Verification

• pnpm typecheck (clean, 0 errors)
• vitest run packages/web-ui/tests/components/ui/SchemaDiagramLegend.test.tsx (3/3 pass)
• vitest run packages/web-ui/tests/utils/schemaDiagram.test.ts (27/27 pass)
• vitest run packages/web-ui/tests/pages/SchemaDiagramPage.test.tsx (3/3 pass)
• eslint & prettier --check (clean, 0 errors)
• check-theme-tokens.mjs (OK)


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


{/* Toolbar per i controlli */}
<div className="absolute top-4 left-4 z-10 flex gap-2">
<SchemaDiagramLegend />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WARNING: Expanded legend distorts the toolbar layout

The toolbar container (absolute top-4 left-4 z-10 flex gap-2) uses the default items-stretch. When the legend expands (~150px+ tall), every sibling button (Layout toggle, Export, Show all) stretches to the same height, and the legend also shifts the existing controls to the right. The PR claims it does not interfere with existing toolbar layout. Consider items-start on the toolbar container, or render the expanded panel as an absolutely-positioned popover anchored under the trigger button.

const containerRef = useRef<HTMLDivElement>(null);

// Keyboard support: Close on Escape when focus is inside
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WARNING: Hand-rolled global Escape listener instead of the repo's useEscapeKey

This registers a bubbling window keydown listener that closes the legend on Escape regardless of where focus is (the comment even says "when focus is inside", which is not what happens), and it bypasses the modal stack in hooks/useEscapeKey.ts. If a modal/context menu is open over the diagram, Escape will also collapse the legend, and the listener does not preventDefault. Use useEscapeKey(isOpen, () => setIsOpen(false)) (or scope the handler to containerRef via onKeyDown). Note containerRef is currently assigned but never read.

"exportDbml": "I-export bilang DBML",
"export": "I-export"
"export": "I-export",
"legend": "Alamat",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WARNING: Incorrect Tagalog translation for "Legend"

"Alamat" means "address", not a map/diagram legend, so users would see a misleading label on the trigger button. Use an appropriate term such as "Gabay" or "Lehenda".

"foreignKey": "外鍵",
"foreignKeyDesc": "引用另一個表中的主鍵或唯一鍵",
"relationship": "關聯",
"relationshipDesc": "連接子表與父表的外键引用"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SUGGESTION: Simplified Chinese character in Traditional Chinese locale

外键 is Simplified; the zh-TW form is 外鍵 (used correctly in foreignKey on the line above).

Suggested change
"relationshipDesc": "連接子表與父表的外键引用"
"relationshipDesc": "連接子表與父表的外鍵引用"

@kilo-code-bot

kilo-code-bot Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

All four earlier findings are fixed in the latest commit:

  • The toolbar container now uses items-start, and the legend content is an absolutely positioned popover, so expanding it no longer stretches the sibling buttons.
  • The legend now uses the shared useEscapeKey modal stack instead of its own window listener, and the unused containerRef is removed.
  • The Tagalog legend string is now "Gabay".
  • The zh-TW relationshipDesc now uses the Traditional 外鍵.
Files Reviewed (4 files)
  • packages/web-ui/src/components/ui/SchemaDiagram.tsx
  • packages/web-ui/src/components/ui/SchemaDiagramLegend.tsx
  • packages/web-ui/src/i18n/locales/tl.json
  • packages/web-ui/src/i18n/locales/zh-TW.json
Previous Review Summary (commit 3cabb1a)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 3cabb1a)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 3
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/web-ui/src/components/ui/SchemaDiagram.tsx 432 Toolbar uses default items-stretch; expanding the legend stretches the Layout/Export/Show-all buttons vertically and pushes them right. Use items-start or an absolutely-positioned popover.
packages/web-ui/src/components/ui/SchemaDiagramLegend.tsx 16 Hand-rolled global window Escape listener bypasses the repo's useEscapeKey modal stack (closes the legend even when a modal/menu is on top); containerRef is unused.
packages/web-ui/src/i18n/locales/tl.json 2222 "Alamat" means "address", not "legend"; incorrect Tagalog translation.

SUGGESTION

File Line Issue
packages/web-ui/src/i18n/locales/zh-TW.json 2251 Simplified character 外键 in zh-TW; should be 外鍵.
Files Reviewed (16 files)
  • packages/web-ui/src/components/ui/SchemaDiagram.tsx - 1 issue
  • packages/web-ui/src/components/ui/SchemaDiagramLegend.tsx - 1 issue
  • packages/web-ui/src/i18n/locales/tl.json - 1 issue
  • packages/web-ui/src/i18n/locales/zh-TW.json - 1 issue
  • packages/web-ui/src/i18n/locales/de.json
  • packages/web-ui/src/i18n/locales/en.json
  • packages/web-ui/src/i18n/locales/es.json
  • packages/web-ui/src/i18n/locales/fr.json
  • packages/web-ui/src/i18n/locales/it.json
  • packages/web-ui/src/i18n/locales/ja.json
  • packages/web-ui/src/i18n/locales/ko.json
  • packages/web-ui/src/i18n/locales/pt-BR.json
  • packages/web-ui/src/i18n/locales/ru.json
  • packages/web-ui/src/i18n/locales/vi.json
  • packages/web-ui/src/i18n/locales/zh.json
  • packages/web-ui/tests/components/ui/SchemaDiagramLegend.test.tsx

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5.5 · Input: 244 · Output: 1.3K · Cached: 178.6K

Review guidance: REVIEW.md from base branch main

debba
debba previously approved these changes Nov 9, 2026

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for explaining the actual PK/FK markers and relationships in a compact legend, and for including keyboard/Escape coverage. All three targeted tests and typecheck pass.

One small follow-up: replace the fixed schema-diagram-legend-content id with useId(). Multiple mounted diagrams currently produce the same id, so aria-controls can point at another diagram's panel.

These are follow-up nits, so I am approving this. I will leave the PR open for your manual checks before any merge.

@NewtTheWolf NewtTheWolf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I updated the branch against main and replaced the fixed legend-content ID with useId. A new two-legend regression checks that each trigger controls its own content.

The four legend tests and all 8,793 frontend tests pass, with lint and typecheck green. The earlier accessibility nit is resolved. Approved on dba7010, subject to the current CI checks.

@NewtTheWolf
NewtTheWolf merged commit a4cb02a into TabularisDB:main Nov 10, 2026
11 checks passed
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.

[Feat]: ER diagram: add an accessible key and relationship legend

3 participants