Repository navigation
refactor(sql-editor): finish EditorController/DiffController port (Step 2) - #48166
Conversation
…troller/DiffController port Extends SQLEditorContext with two semantic, Monaco-agnostic controllers — editor: EditorController and diff: DiffController — backed by the existing editorRef/diffEditorRef in production. Migrates every hook/controller that used to read editorRef.current/diffEditorRef.current directly onto the port: useSqlEditorExecution, usePrettifyQuery, useSqlEditorShortcuts, SQLEditorControllers' readEditorSql, and useSqlEditorAi's acceptAiHandler, drainDiffRequest, handleDiffEditorMount, and the diff-sync effect. The diff-sync effect now wraps its body in useEffectEvent (matching resetDiff/drainDiffRequest right below it): its real trigger is "the diff content changed" (selectedDiffType/sourceSqlDiff), while isDiffOpen, diffController, defaultSqlDiff, and promptState.startLineNumber should be read fresh without retriggering the effect on unrelated changes (e.g. the prompt's start line moving without a new diff). SQLEditorEditorPanel.tsx is intentionally left untouched: it wires the raw refs into the real Monaco/DiffEditor React components, which is genuine production rendering, not decision logic to abstract. This is the seam that lets Step 3's test harness inject a real in-memory editor instead of mocking Monaco. Behavior-preserving.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughThe SQL editor context now exposes ChangesSQL editor controller migration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant AI diff workflow
participant DiffController
participant EditorController
AI diff workflow->>DiffController: setDiff(diff, revealLine)
AI diff workflow->>DiffController: getModifiedValue()
AI diff workflow->>EditorController: replaceAll(modifiedSql)
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › database.spec.ts › Database › Schema Visualizer › table actions work as expected Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
Braintrust eval report
|
Summary
Step 2 of the SQL Editor testability plan.
SQLEditorContextalready wrapped the Monaco refs and exposed a few semantic imperative helpers (getEditorSql,clearHighlights,applyErrorHighlight,refocusEditor, …). This finishes that abstraction so no hook or controller toucheseditorRef.current/diffEditorRef.currentdirectly anymore — they only call the port. The port is what will let Step 3's test harness inject a real in-memory editor adapter instead of mocking Monaco; production wires it to the real Monaco refs, unchanged.editor: EditorController—isReady,getValue,getSelectionStartLine,getSql(today'sgetEditorSql),replaceAll(wraps the repeatedexecuteEdits(...)pattern),focus,revealLineInCenter,highlightErrorLine(today'sapplyErrorHighlight),clearHighlights.diff: DiffController—isMounted,getModifiedValue,setDiff(the diff-sync effect body),attach(today'shandleDiffEditorMount).useSqlEditorExecution,usePrettifyQuery,useSqlEditorShortcuts,SQLEditorControllers'readEditorSql, anduseSqlEditorAi'sacceptAiHandler/drainDiffRequest/handleDiffEditorMount/diff-sync effect.SQLEditorEditorPanel.tsxis intentionally left untouched — it wires the raw refs into the real Monaco/DiffEditor React components for rendering, which isn't decision logic to abstract.Behavior-preserving.
Test plan
pnpm --filter studio typecheckpnpm test:studio -- SQLEditor(265 tests passing)pnpm --filter studio run lint:ratchet