refactor: de-duplicate SVG building, tree rows, and anchored popovers#12
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Behavior-preserving de-duplication of the four highest-value repeat patterns in
src/. No UX change; net −28src/lines and a smaller bundle (90,784 vs 92,514 bytes).createElementNS+ repeatedsetAttributeinicons.js(3 factories) andresults.jscharts()indom.js— an SVG-namespace sibling ofh()sharing one prop/children appliertreeRow()helper inschema.jsopenSavePopover+openUserMenuduplicated the full open/close/anchor/Esc/outside-click lifecycleanchoredPopover()factory inapp.js's'+now+rnd()×3 and the tab-relink loop ×2makeId()+tabsForSaved()s()setsclassviasetAttribute(works for SVG, unchanged for HTML).Tests
npm testgreen at the per-file gate —dom.js,icons.js,results.js,schema.jsall at 100%. Addeds()coverage todom.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:
<title>tooltips (n0: 0…n7: 49), axis + x-labels ✓🤖 Generated with Claude Code
https://claude.ai/code/session_01QennTvGKAtJZrv9EpQagef