Files
supabase/apps/studio/components/interfaces/App/FeaturePreview/useFeaturePreviews.ts
Charis 0791b04eb8 feat(sql-editor): roll out manual saving by default (#48706)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Feature — progresses the SQL Editor manual saving rollout, and removes a
fully rolled out feature flag.

## What is the current behavior?

Manual saving (snippets save only on an explicit Save / Cmd+S rather
than autosaving every edit) is opt-in. It requires both the
`sqlEditorManualSave` ConfigCat flag and the user turning on the
"Disable snippet auto-saving" feature preview themselves. That flag is
now fully rolled out.

## What is the new behavior?

- `sqlEditorManualSave` is removed, so the feature preview is listed for
everyone. (Delete the flag in ConfigCat after a few months.)
- New `sqlEditorManualSaveForced` flag progresses the rollout. It forces
manual saving on regardless of what the user stored previously,
including an explicit opt-out, via a new `isForced` field on
`FeaturePreview` that `initializeFlags` resolves ahead of the
localStorage lookup — so the feature preview modal reflects the forced
state too, not just the save behavior. Turning the flag off reverts
everyone who never opted in, so it remains a working kill switch.
- Users the rollout switches over get a one-time dialog on their first
SQL Editor route, explaining that snippets no longer autosave. Dismissal
persists in `sql-editor-manual-save-notice-dismissed` (allowlisted, so
it survives sign-out).
- Users who opted into the preview themselves never see the dialog — it
records their dismissal up front instead, since the notice needs to
outlive the feature preview and once the preview is retired there's no
stored opt-in left to recognize them by.
- The preview keeps its switch so users who lose their local storage can
opt in early, but once the rollout reaches them the "Disable feature"
button is disabled with a tooltip explaining why.

### To test

Turn on `sqlEditorManualSaveForced` on via the dev toolbar.

- No `supabase-ui-sql-editor-manual-save` and no dismissal key → dialog
appears on `/project/<ref>/sql`, toolbar shows the Save button. Dismiss,
reload → no dialog.
- `supabase-ui-sql-editor-manual-save` set to `false` (previously opted
out) → still forced onto manual saving, and still gets the dialog.
- `supabase-ui-sql-editor-manual-save` set to `true` → no dialog, and
the dismissal key is written automatically.
- Flag off, no opt-in → autosave, no dialog, and the "Disable autosave"
power-off button still opens the preview modal.
- Preview modal while forced → "Disable feature" is disabled with a
tooltip; another preview (e.g. Column-level privileges) still disables
normally.

## Additional context
2026-08-04 12:16:18 -04:00

153 lines
5.4 KiB
TypeScript

import { LOCAL_STORAGE_KEYS, useFlag } from 'common'
import { useMemo } from 'react'
import { type BannerId } from '@/components/ui/BannerStack/BannerStackProvider'
export type FeaturePreview = {
key: string
name: string
discussionsUrl?: string
isNew: boolean
/** If feature flag is only relevant for the hosted platform */
isPlatformOnly: boolean
/** If feature flag should be enabled by default for users, if not yet toggled before */
isDefaultOptIn: boolean
/** Visibility in the feature preview modal (For feature flagging a feature preview) */
enabled: boolean
/**
* Forces the preview on for this user, whatever they previously chose — for a
* preview that has become the default behavior. Overrides both `isDefaultOptIn`
* and a stored opt-out, and takes away the ability to turn the preview back off.
*/
isForced?: boolean
/** Optional category that the feature preview falls under, defaults to "Others" in the UI otherwise */
category?: 'observability' | 'database'
/**
* Where to send the user after enabling, to try the feature out. Omit if the
* feature has no single destination (e.g. a global layout change).
*/
getRoute?: (ref?: string) => string
bannerId?: BannerId
}
export const useFeaturePreviews = (): FeaturePreview[] => {
const isPlatformWebhooksEnabled = useFlag('platformWebhooks')
const jitDbAccessEnabled = useFlag('jitDbAccess')
const isMarketplaceEnabled = useFlag('marketplaceIntegrations')
const isDatabaseConnectionsEnabled = useFlag('topForPostgres')
const unifiedLogsDefaultOptIn = useFlag('unifiedLogsDefaultOptIn')
const isSqlEditorManualSaveForced = useFlag('sqlEditorManualSaveForced')
return useMemo(() => {
const previews: FeaturePreview[] = [
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_UNIFIED_LOGS,
name: 'Updated Logs interface',
category: 'observability',
discussionsUrl: 'https://github.com/orgs/supabase/discussions/37234',
enabled: true,
isNew: true,
isPlatformOnly: true,
isDefaultOptIn: unifiedLogsDefaultOptIn,
getRoute: (ref?: string) => `/project/${ref}/logs`,
},
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_ADVISOR_RULES,
name: 'Disable Advisor rules',
discussionsUrl: undefined,
enabled: true,
isNew: false,
isPlatformOnly: true,
isDefaultOptIn: false,
getRoute: (ref?: string) => `/project/${ref}/advisors/rules/security`,
},
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_PG_DELTA_DIFF,
name: 'PG Delta Diff',
discussionsUrl: undefined,
isNew: false,
isPlatformOnly: true,
isDefaultOptIn: true,
enabled: true,
},
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_PLATFORM_WEBHOOKS,
name: 'Platform webhooks',
discussionsUrl: undefined,
isNew: false,
isPlatformOnly: true,
isDefaultOptIn: false,
enabled: isPlatformWebhooksEnabled,
getRoute: (ref?: string) => `/project/${ref}/settings/webhooks`,
},
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_JIT_DB_ACCESS,
name: 'Temporary database access',
category: 'database',
discussionsUrl: undefined,
isNew: false,
isPlatformOnly: true,
isDefaultOptIn: false,
enabled: jitDbAccessEnabled,
getRoute: (ref?: string) => `/project/${ref}/database/settings`,
},
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS,
name: 'Column-level privileges',
category: 'database',
discussionsUrl: 'https://github.com/orgs/supabase/discussions/20295',
enabled: true,
isNew: false,
isPlatformOnly: false,
isDefaultOptIn: false,
getRoute: (ref?: string) => `/project/${ref}/database/column-privileges`,
},
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_MARKETPLACE,
name: 'One-Click Integrations',
discussionsUrl: undefined,
enabled: isMarketplaceEnabled,
isNew: true,
isPlatformOnly: false,
isDefaultOptIn: true,
getRoute: (ref?: string) => `/project/${ref}/integrations`,
},
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_SQL_EDITOR_MANUAL_SAVE,
name: 'Disable snippet auto-saving',
discussionsUrl: undefined,
isNew: true,
isPlatformOnly: true,
isDefaultOptIn: false,
enabled: true,
// Manual saving is becoming the default for the SQL Editor. The preview
// stays listed so users who lose their local storage can opt back in
// before the rollout reaches them.
isForced: isSqlEditorManualSaveForced,
},
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_DATABASE_CONNECTIONS,
name: 'Diagnose blocked queries',
category: 'observability',
discussionsUrl: 'https://github.com/orgs/supabase/discussions/48639',
isNew: true,
isPlatformOnly: false,
isDefaultOptIn: false,
enabled: isDatabaseConnectionsEnabled,
getRoute: (ref?: string) => `/project/${ref}/observability/connections`,
bannerId: 'database-connections-banner',
},
]
return previews.sort((a, b) => Number(b.isNew) - Number(a.isNew))
}, [
unifiedLogsDefaultOptIn,
isSqlEditorManualSaveForced,
isPlatformWebhooksEnabled,
jitDbAccessEnabled,
isMarketplaceEnabled,
isDatabaseConnectionsEnabled,
])
}