Skip to content

refactor: de-duplicate SVG building, tree rows, and anchored popovers#12

Merged
BorisTyshkevich merged 1 commit into
mainfrom
refactor/dedup-svg-treerow-popover
Jun 22, 2026
Merged

refactor: de-duplicate SVG building, tree rows, and anchored popovers#12
BorisTyshkevich merged 1 commit into
mainfrom
refactor/dedup-svg-treerow-popover

Conversation

@BorisTyshkevich

Copy link
Copy Markdown
Collaborator

What

Behavior-preserving de-duplication of the four highest-value repeat patterns in src/. No UX change; net −28 src/ lines and a smaller bundle (90,784 vs 92,514 bytes).

Area Before After
SVG building raw createElementNS + repeated setAttribute in icons.js (3 factories) and results.js chart new s() in dom.js — an SVG-namespace sibling of h() sharing one prop/children applier
Schema rows three near-identical chevron/icon/label/meta blocks treeRow() helper in schema.js
Popovers openSavePopover + openUserMenu duplicated the full open/close/anchor/Esc/outside-click lifecycle anchoredPopover() factory in app.js
state ids 's'+now+rnd() ×3 and the tab-relink loop ×2 makeId() + tabsForSaved()

s() sets class via setAttribute (works for SVG, unchanged for HTML).

Tests

npm test green at the per-file gate — dom.js, icons.js, results.js, schema.js all at 100%. Added s() coverage to dom.test.js. The icon/results/schema/app suites assert produced output and behavior, so a behavior-preserving refactor keeps them green unchanged.

Verification

Built and deployed to otel; signed-in e2e in-browser confirmed all refactored paths render identically:

  • schema tree: database → tables (with row-count meta) → columns (type meta, empty chevron) ✓
  • bar chart: bars with <title> tooltips (n0: 0n7: 49), axis + x-labels ✓
  • Save popover: opens with inferred prefill + focus, outside-click closes ✓
  • user menu: opens with email + Log out, Esc closes ✓
  • all icons render ✓

🤖 Generated with Claude Code

https://claude.ai/code/session_01QennTvGKAtJZrv9EpQagef

Behavior-preserving cleanup (no UX change), net -28 src lines, smaller bundle.

- dom.js: add s() — an SVG-namespace sibling of h() sharing one prop/children
  applier; class is set via setAttribute so it works for SVG too.
- icons.js: collapse svg/svgFilled/iconEl onto s(); drop the repeated
  createElementNS + setAttribute blocks.
- results.js: build the bar chart (svg/line/text/rect/title) with s() instead
  of local createElementNS builders.
- schema.js: factor the shared chevron/icon/label/meta row into treeRow();
  use it for the db, table, and column rows.
- app.js: extract anchoredPopover() for the shared open/close/anchor/Esc/
  outside-click lifecycle; openSavePopover and openUserMenu delegate to it.
- state.js: makeId(prefix, now) + tabsForSaved(state, id) replace the repeated
  id-minting and tab-relink loops.

Tests: all green at the per-file gate (dom/icons/results/schema at 100%);
added s() coverage to dom.test.js. Verified e2e on otel — schema tree expand,
bar chart, Save popover (prefill+focus, outside-click close), and user menu
(Esc close) all render identically.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QennTvGKAtJZrv9EpQagef
@BorisTyshkevich BorisTyshkevich merged commit b52991e into main Jun 22, 2026
2 checks passed
@BorisTyshkevich BorisTyshkevich deleted the refactor/dedup-svg-treerow-popover branch June 22, 2026 16:43
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