Repository navigation
feat(sql-editor): add manual save feature preview - #47745
Conversation
|
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. |
|
Caution Review failedAn error occurred during the review process. Please try again later. 📝 WalkthroughWalkthroughThis PR adds a feature-flagged SQL editor manual-save mode, with preview registration, autosave/save UI, save-mode coordination, and discard confirmation for SQL tab closes. ChangesSQL Editor Manual Save
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 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 |
2af263a to
2bcb398
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
apps/studio/components/layouts/Tabs/Tabs.tsx (1)
115-160: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low valueBulk-close shows a single-snippet confirmation but discards every dirty tab.
getCloseConfirmationreturns only the first matching tab's copy ("You have unsaved changes in this SQL snippet…"), yet confirming here runstabs.closeTabs(tabsToClose)and discards all of them. When multiple SQL tabs have unsaved edits, the singular wording can mislead the user about how much is being discarded. Consider making the confirmation copy count-aware for the bulk paths.🤖 Prompt for 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. In `@apps/studio/components/layouts/Tabs/Tabs.tsx` around lines 115 - 160, The bulk-close flows in Tabs.tsx use a single-tab confirmation message even when closeWithConfirmation is called with multiple dirty tabs, so update the copy to reflect the full set being discarded. Adjust the confirmation logic used by getCloseConfirmation and the bulk handlers handleCloseOthers and handleCloseRight so it can detect tabsToClose length and generate count-aware wording for multiple SQL snippets. Keep the existing behavior of tabs.closeTabs and router.push, but make the message clear that confirming will discard all affected unsaved tabs, not just one.apps/studio/state/sql-editor/sql-editor-save-coordinator.tsx (1)
81-81: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrefer
use()overuseContextin new React 19 code.- const tabsStore = useContext(TabsStateContext) + const tabsStore = use(TabsStateContext)(update the import from
reactaccordingly). Advisory only.As per coding guidelines: "Flag
forwardRefanduseContextin new code — userefas a regular prop anduse()instead."🤖 Prompt for 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. In `@apps/studio/state/sql-editor/sql-editor-save-coordinator.tsx` at line 81, Replace the React context read in sql-editor-save-coordinator by using React 19’s use() instead of useContext, and update the react import to include use while removing useContext. Locate the TabsStateContext access in the save coordinator component and keep the behavior the same by reading the context value through use(TabsStateContext) rather than useContext(TabsStateContext).Source: Coding guidelines
🤖 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/UtilityPanel/AutosaveStatus.tsx`:
- Around line 37-57: The AutosaveStatus component shows the disable autosave
action even when manual save is not actually available, because it relies on
isManualSaveEnabled which is also false for self-hosted or when the ConfigCat
flag is off. Update AutosaveStatus so the Button and its Tooltip are only
rendered when the feature is truly exposed, using IS_PLATFORM or the raw
useFlag('sqlEditorManualSave') value rather than isManualSaveEnabled, and keep
the tracking/selectFeaturePreview behavior unchanged for the valid opt-in case.
- Around line 42-52: The icon-only PowerOff button in AutosaveStatus lacks an
accessible name, so add an aria-label to the Button alongside the existing
tooltip behavior. Update the button in AutosaveStatus to include a descriptive
label matching its action (similar to the icon-only buttons in
UtilityActions.tsx), while keeping the current onClick tracking and feature
preview selection unchanged.
---
Nitpick comments:
In `@apps/studio/components/layouts/Tabs/Tabs.tsx`:
- Around line 115-160: The bulk-close flows in Tabs.tsx use a single-tab
confirmation message even when closeWithConfirmation is called with multiple
dirty tabs, so update the copy to reflect the full set being discarded. Adjust
the confirmation logic used by getCloseConfirmation and the bulk handlers
handleCloseOthers and handleCloseRight so it can detect tabsToClose length and
generate count-aware wording for multiple SQL snippets. Keep the existing
behavior of tabs.closeTabs and router.push, but make the message clear that
confirming will discard all affected unsaved tabs, not just one.
In `@apps/studio/state/sql-editor/sql-editor-save-coordinator.tsx`:
- Line 81: Replace the React context read in sql-editor-save-coordinator by
using React 19’s use() instead of useContext, and update the react import to
include use while removing useContext. Locate the TabsStateContext access in the
save coordinator component and keep the behavior the same by reading the context
value through use(TabsStateContext) rather than useContext(TabsStateContext).
🪄 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: 8b73fd95-d152-44a5-9942-185dfd508ac9
📒 Files selected for processing (15)
apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsxapps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsxapps/studio/components/interfaces/App/FeaturePreview/SqlEditorManualSavePreview.tsxapps/studio/components/interfaces/App/FeaturePreview/useFeaturePreviews.tsapps/studio/components/interfaces/SQLEditor/UtilityPanel/AutosaveStatus.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/SaveButton.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsxapps/studio/components/layouts/Tabs/Tabs.tsxapps/studio/state/sql-editor/sql-editor-lifecycle.tsapps/studio/state/sql-editor/sql-editor-save-coordinator.tsxapps/studio/state/sql-editor/sql-editor-state.tsapps/studio/state/tabs.test.tsapps/studio/state/tabs.tsxpackages/common/constants/local-storage.tspackages/common/telemetry-constants.ts
🎭 Playwright Test ResultsDetails
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
2bcb398 to
b6be409
Compare
Adds an opt-in "SQL Editor manual save" feature preview that switches the SQL Editor from autosaving every edit to saving only on demand, and hardens the tab-close flow so unsaved edits are handled correctly. Feature preview - New `sqlEditorManualSave` flag + `UI_PREVIEW_SQL_EDITOR_MANUAL_SAVE` local-storage toggle, wired into the Feature Preview modal with an explanatory preview panel. - `useIsSqlEditorManualSaveEnabled` gates the behavior on both the flag and the user's preview opt-in. Editor toolbar - Add a Save button (with Cmd+S) next to Run and an autosave status indicator that surfaces dirty/saving/saved state and a shortcut to disable autosave, emitting a `sql_editor_autosave_disable_clicked` telemetry event. Discard on close - Closing a snippet tab with unsaved edits now prompts for confirmation and, on confirm, actually discards the local edits and evicts the cached server copy so the snippet reopens clean. This now applies to every close path (close, close others, close to the right, close all), not just single close. Decouple tab layout from SQL specifics - Give the tabs store a generic, per-type close-handler registry (`registerTabCloseHandler` / `getCloseConfirmation` / `closeTabs`). The SQL editor registers its discard + confirmation behavior from the save coordinator, so the Tabs layout no longer imports snippet state, React Query keys, or unsaved-changes semantics. Low-level `removeTab`/`removeTabs` (used for rename/move re-keying and stale cleanup) intentionally do not trigger discard. - Add `statusOnDiscard` lifecycle transition and `clearSnippetContent` store action to model discarding. Tests - Cover the close-handler registry: fires on single/multi close, skips re-keying/cleanup removals, respects tab type, selects confirmation copy, and unregisters cleanly.
b6be409 to
e342973
Compare
Add a VS Code-style unsaved-changes indicator to SQL editor tabs: a dot shows at rest when the snippet has unsaved edits and swaps to the close button on hover. The tabs layout stays agnostic of snippets. The per-tab-type registry (previously close-only) is generalized to TabTypeHandler, which can now also provide a StatusIndicator component; the SQL editor registers one from the save coordinator. A registration-version signal lets tabs pick up a handler registered in an effect after first paint. The dot renders only in manual-save mode when the snippet is dirty (auto mode persists on its own, so a dot would just flicker), and uses the `bg-warning` design-system token.
What
Adds an opt-in SQL Editor manual save feature preview that switches the SQL Editor from autosaving every edit to saving only on demand, and hardens the tab-close flow so unsaved edits are handled correctly.
Changes
Feature preview
sqlEditorManualSaveflag +UI_PREVIEW_SQL_EDITOR_MANUAL_SAVElocal-storage toggle, wired into the Feature Preview modal with an explanatory panel.useIsSqlEditorManualSaveEnabledgates behavior on both the flag and the user's preview opt-in.Editor toolbar
Cmd+S) next to Run, plus an autosave status indicator showing dirty/saving/saved state and a shortcut to disable autosave (emits asql_editor_autosave_disable_clickedtelemetry event).Discard on close
Decouple tab layout from SQL specifics
registerTabCloseHandler/getCloseConfirmation/closeTabs). The SQL editor registers its discard + confirmation behavior from the save coordinator.removeTab/removeTabs(rename/move re-keying, stale cleanup) intentionally do not trigger discard.statusOnDiscardlifecycle transition andclearSnippetContentstore action.Testing
pnpm --filter=studio typecheck— clean.Summary by CodeRabbit
Cmd+S, plus a modal option to disable manual-save/preview.