Repository navigation
refactor(sql-editor): extract AI/diff + shortcuts hooks (decompose 5/6) - #47935
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughThe SQL editor’s AI completion, diff handling, debug prompts, shortcuts, and lifecycle effects move into dedicated hooks. The editor consumes the new hook APIs, and diff-mode test coverage is updated for mount-time request draining. ChangesSQL editor AI integration
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
Extract the Assistant/diff cluster into useSqlEditorAi (SQL completion, the ask-AI prompt flow, accept/discard diff handlers, debug-prompt helpers, and the diff lifecycle effects) and the keyboard/shortcut wiring into useSqlEditorShortcuts. SQLEditorContent now composes these hooks. Behavior-preserving: the extracted function bodies, effect logic, dependency arrays, and JSX are unchanged from the previous monolith. The untrusted->safe SQL promotion (acceptUntrustedSql) continues to happen in the run/explain gesture and warning-modal handlers, as close to the user action as possible. The Phase-1 characterization suite remains green.
441b7ca to
3b4d22b
Compare
🎭 Playwright Test Results (next)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/studio/components/interfaces/SQLEditor/useSqlEditorAi.ts`:
- Around line 77-98: Update handleNewQuery and its caller acceptAiHandler so
new-snippet creation failures propagate or return an explicit unsuccessful
result; do not resolve successfully after missing ref, profile, project, or
caught creation errors. Only record success, reset state, and close the diff
after confirmed creation, including the corresponding flow in the additionally
affected handler.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5af824c1-afcc-41c7-afeb-91835f740a5a
📒 Files selected for processing (4)
apps/studio/components/interfaces/SQLEditor/SQLEditor.tsxapps/studio/components/interfaces/SQLEditor/useSqlEditorAi.tsapps/studio/components/interfaces/SQLEditor/useSqlEditorShortcuts.tsapps/studio/tests/components/SQLEditor/SQLEditor.test.tsx
Braintrust eval report
|
…onal components (decompose 6/6) (#47938) ## What Final step (**6 of 6**) of the `SQLEditor.tsx` decomposition. Splits the two `ResizablePanel` bodies out of the `SQLEditorContent` monolith into presentational sub-components: - **`SQLEditorPane`** — the editor panel: loading state, `DiffEditor` + diff ask-AI widget, `MonacoEditor` + ask-AI widget. Reads the Monaco refs (`editorRef`/`monacoRef`/`diffEditorRef`) from `SQLEditorContext`, and receives the `diff`/`prompt`/`ai` controllers plus reactive state as props. - **`SQLEditorResults`** — the results panel: loading state + `UtilityPanel`. `SQLEditorContent` is now a composition root: shared-ref provider, hook composition, and the run-query warning modal. ## Result `SQLEditor.tsx` goes from the original **1056-line** monolith down to **259 lines** (≈75% reduction). The remaining size over a bare ~140-line root is the run-query warning modal, kept inline **deliberately**: its handlers hold the `acceptUntrustedSql` promotion, which must stay at the explicit user-action boundary in the root rather than moving into a presentational pane. ## Behavior-preserving The moved JSX is byte-identical aside from prop threading. No logic, effects, dependency arrays, or `eslint-disable`s changed. The two **render-time ref reads** — the editor placeholder (`!promptState.isOpen && !editorRef.current?.getValue()`) and the ask-AI widget gate (`editorRef.current && promptState.isOpen && !isDiffOpen`) — are preserved verbatim in `SQLEditorPane`, which re-renders whenever the `prompt`/`diff` props change, keeping those reads fresh (the guardrail from the plan). Verification (all green): - `SQLEditor.test.tsx` characterization suite — 11/11 pass - `tsc --noEmit` — no new errors - eslint — clean (no new ratchet entries) - prettier — clean ## Stack Builds on decompose 5 (#47935). This is the last PR in the series — the decomposition is complete after this merges. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a resizable SQL editor layout with run warnings, query results, and an Explain view. * Introduced centralized SQL editor controllers and expanded AI-assisted prompt/diff workflows. * Added keyboard support for running and Explain analysis. * **Bug Fixes** * Restored editor focus after accepting or discarding AI changes. * Improved handling and validation of SQL Explain actions. * Preserved editor scroll position when switching snippets. * **Refactor** * Streamlined the SQLEditor into a composed layout and improved memoization to reduce unnecessary re-renders. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
What
Decompose step 5 of 6 for
SQLEditor.tsx. Extracts the Assistant / diff cluster and the keyboard-shortcut wiring out of theSQLEditorContentmonolith into two focused, individually-testable hooks:useSqlEditorAi— SQL completion (complete), the ask-AI prompt flow (handlePrompt), accept/discard diff handlers,onDebug/buildDebugPrompthelpers,handleDiffEditorMount, and the fragile diff lifecycle effects (one-shot diff-request drain, diff-editor value sync, ask-AI widget visibility).useSqlEditorShortcuts— the registered shortcuts (focus editor, new snippet, format, explain) plus the accept/discard/escape keydown handling.SQLEditorContentnow composes these hooks alongside the execution/explain hooks landed in decompose 4.Behavior-preserving
This is a pure extraction. The moved function bodies, effect logic, dependency arrays, and JSX are unchanged from the previous monolith (verified via
git diffagainst the pre-decomposition source). In particular:useEffectEventis preserved fordrainDiffRequest/resetDiff.editorMountCountremains single-owner (passed into the AI hook to drive the one-shot drain).acceptUntrustedSql) continues to happen in the run/explain gesture and warning-modal handlers inSQLEditorContent, as close to the explicit user action as possible.The Phase-1 characterization suite (
SQLEditor.test.tsx, 11 tests) remains green.Stack
Part of the SQLEditor decomposition stack (1/6 … 6/6). Builds on decompose 4 (execution + explain hooks, #47923). Next: PR6 splits the JSX into panes + final cleanup.
Summary by CodeRabbit
New Features
Bug Fixes