The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Persist connect sheet user preference (#46213)
Joshen Lim7f2339481826
diff --git a/apps/studio/components/interfaces/ConnectSheet/ConnectSheet.tsx b/apps/studio/components/interfaces/ConnectSheet/ConnectSheet.tsxindex 2db9e13fd30..01e5a58f318 100644--- a/apps/studio/components/interfaces/ConnectSheet/ConnectSheet.tsx+++ b/apps/studio/components/interfaces/ConnectSheet/ConnectSheet.tsx@@ -1,6 +1,6 @@import { PermissionAction } from '@supabase/shared-types/out/constants'import { useParams } from 'common'-import { parseAsBoolean, parseAsString, useQueryState } from 'nuqs'+import { parseAsBoolean, useQueryState } from 'nuqs'import { useEffect, useMemo, useRef } from 'react'import { cn, Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from 'ui'@@ -9,6 +9,7 @@ import { CONNECT_MODES } from './Connect.types'import { ConnectConfigSection, ModeSelector } from './ConnectConfigSection'import { ConnectStepsSection } from './ConnectStepsSection'import { useAvailableConnectModes } from './useAvailableConnectModes'+import { useConnectSheetParams } from './useConnectSheetParams'import { useConnectSheetShortcut } from './useConnectSheetShortcut'import { useConnectState } from './useConnectState'import { getKeys, useAPIKeysQuery } from '@/data/api-keys/api-keys-query'@@ -35,28 +36,32 @@ function mapConnectTabToMode(tab: string | null): ConnectMode | null {}export const ConnectSheet = () => {+ const track = useTrack()+ const prevShowConnect = useRef(false)const { ref: projectRef } = useParams()useConnectSheetShortcut()const availableModeIds = useAvailableConnectModes()+ const { connectSheetSource, setConnectSheetSource } = useAppStateSnapshot()+ const { state, activeFields, resolvedSteps, schema, getFieldOptions, setMode, updateField } =+ useConnectState()const [showConnect, setShowConnect] = useQueryState('showConnect',parseAsBoolean.withDefault(false))- const [connectTab, setConnectTab] = useQueryState('connectTab', parseAsString)- const [queryFramework, setQueryFramework] = useQueryState('framework', parseAsString)- const [queryUsing, setQueryUsing] = useQueryState('using', parseAsString)- const [queryMethod, setQueryMethod] = useQueryState('method', parseAsString)- const [queryType, setQueryType] = useQueryState('type', parseAsString)- const [queryMcpClient, setQueryMcpClient] = useQueryState('mcpClient', parseAsString)- const { connectSheetSource, setConnectSheetSource } = useAppStateSnapshot()- const track = useTrack()- const prevShowConnect = useRef(false)-- const { state, activeFields, resolvedSteps, schema, getFieldOptions, setMode, updateField } =- useConnectState()+ // URL params have no defaults: a `null` value signals "not in URL" so we can+ // fall back to the user's last-used selections from localStorage.+ const { params, storedPrefs, setConnectParams, setQueryParams } = useConnectSheetParams()+ const {+ connectTab,+ framework: queryFramework,+ using: queryUsing,+ method: queryMethod,+ type: queryType,+ mcpClient: queryMcpClient,+ } = paramsuseEffect(() => {const justOpened = showConnect && !prevShowConnect.current@@ -67,24 +72,53 @@ export const ConnectSheet = () => {track('connect_sheet_opened', { source: connectSheetSource })setConnectSheetSource('header_button')- const mappedMode = mapConnectTabToMode(connectTab)+ const effectiveTab = connectTab ?? storedPrefs.connectTab+ const effectiveFramework = queryFramework ?? storedPrefs.framework+ const effectiveUsing = queryUsing ?? storedPrefs.using+ const effectiveMethod = queryMethod ?? storedPrefs.method+ const effectiveType = queryType ?? storedPrefs.type+ const effectiveMcpClient = queryMcpClient ?? storedPrefs.mcpClient++ const mappedMode = mapConnectTabToMode(effectiveTab ?? null)if (mappedMode && availableModeIds.includes(mappedMode)) {setMode(mappedMode)}+ // Hydrate URL from storedPrefs so the URL reflects the restored state.+ // Only write params relevant to the active mode (matches how+ // handleModeChange/handleFieldChange manage URL params).+ const urlUpdates: Parameters<typeof setConnectParams>[0] = {}+ if (connectTab === null && effectiveTab) urlUpdates.connectTab = effectiveTabif (mappedMode === 'framework') {- if (queryFramework) {- updateField('framework', queryFramework)- if (queryUsing) updateField('frameworkVariant', queryUsing)+ if (effectiveFramework) {+ updateField('framework', effectiveFramework)+ if (queryFramework === null) urlUpdates.framework = effectiveFramework+ if (effectiveUsing) {+ updateField('frameworkVariant', effectiveUsing)+ if (queryUsing === null) urlUpdates.using = effectiveUsing+ }}} else if (mappedMode === 'orm') {- if (queryFramework) updateField('orm', queryFramework)+ if (effectiveFramework) {+ updateField('orm', effectiveFramework)+ if (queryFramework === null) urlUpdates.framework = effectiveFramework+ }} else if (mappedMode === 'direct') {- if (queryMethod) updateField('connectionMethod', queryMethod)- if (queryType) updateField('connectionType', queryType)+ if (effectiveMethod) {+ updateField('connectionMethod', effectiveMethod)+ if (queryMethod === null) urlUpdates.method = effectiveMethod+ }+ if (effectiveType) {+ updateField('connectionType', effectiveType)+ if (queryType === null) urlUpdates.type = effectiveType+ }} else if (mappedMode === 'mcp') {- if (queryMcpClient) updateField('mcpClient', queryMcpClient)+ if (effectiveMcpClient) {+ updateField('mcpClient', effectiveMcpClient)+ if (queryMcpClient === null) urlUpdates.mcpClient = effectiveMcpClient+ }}+ if (Object.keys(urlUpdates).length > 0) setQueryParams(urlUpdates)}, [showConnect,connectSheetSource,@@ -94,20 +128,24 @@ export const ConnectSheet = () => {queryMethod,queryType,queryMcpClient,+ storedPrefs,availableModeIds,track,setConnectSheetSource,setMode,updateField,+ setQueryParams,])const clearAllQueryParams = () => {- setConnectTab(null)- setQueryFramework(null)- setQueryUsing(null)- setQueryMethod(null)- setQueryType(null)- setQueryMcpClient(null)+ setQueryParams({+ connectTab: null,+ framework: null,+ using: null,+ method: null,+ type: null,+ mcpClient: null,+ })}const handleOpenChange = (sheetOpen: boolean) => {@@ -141,31 +179,31 @@ export const ConnectSheet = () => {const handleModeChange = (mode: ConnectMode) => {setMode(mode)- setConnectTab(mode)- setQueryFramework(null)- setQueryUsing(null)- setQueryMethod(null)- setQueryType(null)- setQueryMcpClient(null)+ setConnectParams({+ connectTab: mode,+ framework: null,+ using: null,+ method: null,+ type: null,+ mcpClient: null,+ })}const handleFieldChange = (fieldId: string, value: string | boolean | string[]) => {updateField(fieldId, value)const str = String(value)if (fieldId === 'framework') {- setQueryFramework(str)- setQueryUsing(null)+ setConnectParams({ framework: str, using: null })} else if (fieldId === 'frameworkVariant') {- setQueryUsing(str)+ setConnectParams({ using: str })} else if (fieldId === 'orm') {- setQueryFramework(str)+ setConnectParams({ framework: str })} else if (fieldId === 'connectionMethod') {- setQueryMethod(str)- setQueryType(null)+ setConnectParams({ method: str, type: null })} else if (fieldId === 'connectionType') {- setQueryType(str)+ setConnectParams({ type: str })} else if (fieldId === 'mcpClient') {- setQueryMcpClient(str)+ setConnectParams({ mcpClient: str })}}diff --git a/apps/studio/components/interfaces/ConnectSheet/useConnectSheetParams.ts b/apps/studio/components/interfaces/ConnectSheet/useConnectSheetParams.tsnew file mode 100644index 00000000000..01f3f23bca2--- /dev/null+++ b/apps/studio/components/interfaces/ConnectSheet/useConnectSheetParams.ts@@ -0,0 +1,58 @@+import { LOCAL_STORAGE_KEYS } from 'common'+import { parseAsString, useQueryStates } from 'nuqs'+import { useCallback } from 'react'++import { useLocalStorage } from '@/hooks/misc/useLocalStorage'++export type ConnectSheetPrefs = {+ connectTab?: string+ framework?: string+ using?: string+ method?: string+ type?: string+ mcpClient?: string+}++const DEFAULT_CONNECT_SHEET_PREFS: ConnectSheetPrefs = {}++type ConnectParamKey = keyof ConnectSheetPrefs+type ConnectParamUpdates = Partial<Record<ConnectParamKey, string | null>>++/**+ * Owns the URL params + localStorage that drive the Connect sheet's initial+ * state. `setConnectParams` mirrors writes to both. `setQueryParams` writes+ * the URL only — used to clear URL on close and to hydrate URL from storage+ * on open (where storage is already the source of truth).+ */+export function useConnectSheetParams() {+ const [params, setQueryParams] = useQueryStates({+ connectTab: parseAsString,+ framework: parseAsString,+ using: parseAsString,+ method: parseAsString,+ type: parseAsString,+ mcpClient: parseAsString,+ })++ const [storedPrefs, setStoredPrefs] = useLocalStorage<ConnectSheetPrefs>(+ LOCAL_STORAGE_KEYS.CONNECT_SHEET_PREFS,+ DEFAULT_CONNECT_SHEET_PREFS+ )++ const setConnectParams = useCallback(+ (updates: ConnectParamUpdates) => {+ setQueryParams(updates)+ setStoredPrefs((prev) => {+ const next: ConnectSheetPrefs = { ...prev }+ for (const key of Object.keys(updates) as ConnectParamKey[]) {+ // null in URL maps to undefined in storage so the preference is truly forgotten+ next[key] = updates[key] ?? undefined+ }+ return next+ })+ },+ [setQueryParams, setStoredPrefs]+ )++ return { params, storedPrefs, setConnectParams, setQueryParams }+}diff --git a/packages/common/constants/local-storage.ts b/packages/common/constants/local-storage.tsindex 2701f03f994..fb6cc904bf1 100644--- a/packages/common/constants/local-storage.ts+++ b/packages/common/constants/local-storage.ts@@ -80,6 +80,9 @@ export const LOCAL_STORAGE_KEYS = {// api keys view switcher for new and legacy api keysAPI_KEYS_VIEW: (ref: string) => `supabase-api-keys-view-${ref}`,+ // Connect sheet: remember last-used tab/framework/method etc. across opens+ CONNECT_SHEET_PREFS: 'supabase-connect-sheet-prefs',+// Shortcut preferencesSHORTCUT_STORAGE_KEY: 'supabase-shortcut-preferences',