fix(web): show the stored raw SQL query when re-editing a widget - #579
Closed
JeremyFunk wants to merge 1 commit into
Closed
fix(web): show the stored raw SQL query when re-editing a widget#579JeremyFunk wants to merge 1 commit into
JeremyFunk wants to merge 1 commit into
Conversation
The widget editor seeded its raw-SQL draft and its Source toggle from the `widget` prop on the first render only. That prop is not fixed for the life of the editor — the dashboard row can reach it after the first render, or be replaced by a later sync — so an editor that first rendered without the stored data source kept the Query Builder tab and a template query forever, while the preview and the canvas tile drew the stored SQL from the same prop. Both are now re-seeded during render whenever the widget's raw SQL changes, and only while the draft is still the one seeded, so anything typed wins. The dirty baselines follow too, or the unsaved-changes blocker fires on an edit nobody made.
Collaborator
Author
|
Closing — the fix targets an unobserved trigger. The real case is a route-backed funnel widget (product_events_funnel) whose editor falls through to the raw-SQL template; reproducing that separately. |
🍁 Maple PR previewNote Preview resources were removed when this pull request closed. Final commit |
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.
Symptom
Re-opening the editor of a raw-SQL dashboard widget can show an empty SQL editor (or the Query Builder tab) instead of the stored query, while the tile and the editor preview keep rendering that same query correctly.
Root cause
WidgetQueryBuilderPageseeds three pieces of local state from thewidgetprop on the first render only:mode(the Source toggle) —useState(initialMode)rawSqlDraft/rawSqlPreviewDraft—useState(initialRawSqlDraft)initialModeRef/initialRawSqlSnapshotRefinitialRawSqlDraftis auseMemoover[widget], so it recomputes when the widget prop changes, but nothing ever fed it back into state. The prop is not fixed for the life of the editor — the dashboard row can reach the page after the first render, or be replaced by a later sync — so an editor whose first render saw a widget without the stored raw-SQL data source keeps the Query Builder tab and the seeded template for the rest of the visit. Everything else in the page (the preview,applyChanges' target, the canvas tile) reads the widget prop directly, which is why the chart stays correct while the editor does not.Fix
Re-seed the draft and the Source toggle during render (React's "adjust state when a prop changes") when the widget's stored raw SQL changes, and only while the draft is still the one seeded — anything the user typed wins. The dirty baselines follow, so the unsaved-changes blocker does not fire on an edit nobody made.
Verification
apps/web/src/components/dashboard-builder/config/widget-query-builder-page.test.tsxrenders the real editor and covers: widget arrives after the first render, stored SQL changes under an untouched draft, and a widget-prop replacement while the user has typed. Two of the three fail onmainand pass with this change.bun run --cwd apps/web test— 1767 passing; the 4 failures (use-timezone-preference,use-recently-used-times) are pre-existing onmainand come from jsdom having nowindow.localStorage.bun typecheck— 40/40 green.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.