Skip to content

Extract renderGrid state/repaint wiring before Panels (#167)#181

Merged
BorisTyshkevich merged 1 commit into
mainfrom
refactor/grid-view-wiring-167
Jul 12, 2026
Merged

Extract renderGrid state/repaint wiring before Panels (#167)#181
BorisTyshkevich merged 1 commit into
mainfrom
refactor/grid-view-wiring-167

Conversation

@BorisTyshkevich

Copy link
Copy Markdown
Collaborator

What & why

Closes #167 — the behavior-preserving preparation step for the Panels track (#166).

The complex grid surface was already shared (renderGrid), but its state wiring ({sort, widths} holder + repaint-on-sort closure) was hand-rolled at three sites, each slightly different. This PR:

  • New module src/ui/grid-render.jsrenderGrid (moved verbatim, stays stateless; onCell is now optional so a consumer without a cell-detail surface degrades safely instead of throwing), colResizeWidth, the column-resize logic behind two shared helpers (resizeHandle, reapplyWidths — the 8-line handle span + reapply guard were previously copy-pasted three times), PLAIN_KEY, GRID_VIS_CAP, and the new renderGridView adapter with the issue's explicit seams (sort/setSort/widths/rerender/onCell/cap): setSort is called exactly once per sort click, rerender after the state update, widths passes through by reference. No dependency back into results.js (prevents the results → panels → renderer → results cycle Extract the renderGrid local-state wiring (sort/widths + repaint) — four hand-rolled copies #167 called out).
  • Three consumers migrated to renderGridView, each preserving its exact state lifetime and repaint scope: main results table (app.state.resultSort + r.colWidths, full renderResults repaint, visCap(r)), script-result rows viewer (entry-persisted state, drawer-body repaint), detached Data pane (snapshot-local state, caller-owned Table/JSON/Chart repaint + Chart.js cleanup, detached-document cell detail). The script grids reuse the shared resize helpers with PLAIN_KEY.
  • Tests — new per-module spec tests/unit/grid-render.test.js (adapter contract per the issue's Tests section + grid/resize mechanics; 100/100/100/100). results.test.js keeps the wiring-level specs and gains coverage for the toolbar Expand button and the script-grid resize-handle click — the extraction exposed them as the file's only uncovered functions, along with two unreachable no-op cancelDrawerDrag initializers (always reassigned before any close can fire), now removed per the repo's no-dead-defensive-code philosophy.

Explicitly out of scope (per the issue): panel/dashboard/saved-query knowledge, gridStateForSchema (deferred until #166 has a consumer), and any sorting/resizing behavior change. visCap stays in results.js (it's result-shaped policy; the adapter takes cap as an input).

Reviewed via an 8-angle finder/verify pass; three confirmed findings (test duplication, unguarded optional onCell, thrice-copied resize wiring) are fixed in this diff.

Checklist

  • npm test passes (2118 tests; grid-render.js at 100/100/100/100, results.js within the gate)
  • Tests added/updated in the same change as the code
  • npm run build succeeds (single-file dist/sql.html)
  • Layers kept honest: DOM render in src/ui/, state seams injected by the caller; no src/core//src/net/ changes
  • No new runtime dependency
  • CHANGELOG.md ([Unreleased]) updated
  • Reconciled affected tracked work: Roadmap to 1.0.0 #68's Phase 6 entry is this issue (checked off on merge); Panels: visualization registry + Panel drawer tab + Library panel field #166's integration contract is satisfied as written

🤖 Generated with Claude Code

https://claude.ai/code/session_01KvqMJNyxUAJQcEm1Tn29Qr

…nder.js (#167)

Move the shared sortable/resizable grid out of results.js into its own
module and centralize the hand-rolled sort-update + repaint wiring:

- src/ui/grid-render.js: renderGrid (stateless, unchanged; onCell now
  optional per the issue's degrade-safely requirement), colResizeWidth,
  the resize primitives behind two small shared helpers (resizeHandle,
  reapplyWidths — the col-resize-h span + reapply guard were copy-pasted
  three times), PLAIN_KEY, GRID_VIS_CAP, and the new renderGridView
  adapter (explicit sort/setSort/widths/rerender seams).
- results.js: the three consumers (renderTable, script rows viewer,
  detached Data pane) migrate to renderGridView, each keeping its exact
  state lifetime and repaint scope; the script grids reuse the shared
  resize helpers. No dependency from grid-render.js back into results.js.
- tests: new per-module spec tests/unit/grid-render.test.js (adapter
  contract + grid mechanics, 100/100/100/100); results.test.js keeps only
  wiring-level resize specs and gains coverage for the toolbar Expand
  button and the script-grid handle click (the extraction surfaced them
  as the file's only uncovered functions, along with two unreachable
  no-op cancelDrawerDrag initializers now removed).

Behavior-preserving preparation for the Panels track: #166's table panel
becomes the fourth consumer without another copy of the wiring.

Closes #167

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KvqMJNyxUAJQcEm1Tn29Qr
@BorisTyshkevich BorisTyshkevich merged commit a09d664 into main Jul 12, 2026
6 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.

Extract the renderGrid local-state wiring (sort/widths + repaint) — four hand-rolled copies

1 participant