Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: deep link feature preview modal (#37191)

Alaister Youngdac0ee6575d0
diff --git a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
index c71a9beda01..e3607429f43 100644
--- a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
+++ b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
@@ -1,7 +1,17 @@
import { noop } from 'lodash'
-import { PropsWithChildren, createContext, useContext, useEffect, useState } from 'react'
+import { useQueryState } from 'nuqs'
+import {
+ PropsWithChildren,
+ createContext,
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useState,
+} from 'react'
import { FeatureFlagContext, LOCAL_STORAGE_KEYS } from 'common'
+import { useFlag, useIsRealtimeSettingsFFEnabled } from 'hooks/ui/useFlag'
import { EMPTY_OBJ } from 'lib/void'
import { FEATURE_PREVIEWS } from './FeaturePreview.constants'
@@ -89,3 +99,75 @@ export const useIsBranching2Enabled = () => {
const { flags } = useFeaturePreviewContext()
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_BRANCHING_2_0]
}
+
+export const useFeaturePreviewModal = () => {
+ const [featurePreviewModal, setFeaturePreviewModal] = useQueryState('featurePreviewModal')
+ const isRealtimeSettingsEnabled = useIsRealtimeSettingsFFEnabled()
+ const gitlessBranchingEnabled = useFlag('gitlessBranching')
+
+ const selectedFeatureKeyFromQuery = featurePreviewModal?.trim() ?? null
+ const showFeaturePreviewModal = selectedFeatureKeyFromQuery !== null
+
+ // [Joshen] Use this if we want to feature flag previews
+ const isFeaturePreviewReleasedToPublic = useCallback(
+ (feature: (typeof FEATURE_PREVIEWS)[number]) => {
+ switch (feature.key) {
+ case 'supabase-ui-realtime-settings':
+ return isRealtimeSettingsEnabled
+ case 'supabase-ui-branching-2-0':
+ return gitlessBranchingEnabled
+ default:
+ return true
+ }
+ },
+ [isRealtimeSettingsEnabled, gitlessBranchingEnabled]
+ )
+
+ const selectedFeatureKey = !selectedFeatureKeyFromQuery
+ ? FEATURE_PREVIEWS.filter((feature) => isFeaturePreviewReleasedToPublic(feature))[0].key
+ : selectedFeatureKeyFromQuery
+
+ const selectFeaturePreview = useCallback(
+ (featureKey: string) => {
+ setFeaturePreviewModal(featureKey)
+ },
+ [setFeaturePreviewModal]
+ )
+
+ const openFeaturePreviewModal = useCallback(() => {
+ selectFeaturePreview(selectedFeatureKey)
+ }, [selectFeaturePreview, selectedFeatureKey])
+
+ const closeFeaturePreviewModal = useCallback(() => {
+ setFeaturePreviewModal(null)
+ }, [setFeaturePreviewModal])
+
+ const toggleFeaturePreviewModal = useCallback(() => {
+ if (showFeaturePreviewModal) {
+ closeFeaturePreviewModal()
+ } else {
+ openFeaturePreviewModal()
+ }
+ }, [showFeaturePreviewModal, openFeaturePreviewModal, closeFeaturePreviewModal])
+
+ return useMemo(
+ () => ({
+ showFeaturePreviewModal,
+ selectedFeatureKey,
+ selectFeaturePreview,
+ openFeaturePreviewModal,
+ closeFeaturePreviewModal,
+ toggleFeaturePreviewModal,
+ isFeaturePreviewReleasedToPublic,
+ }),
+ [
+ showFeaturePreviewModal,
+ selectedFeatureKey,
+ selectFeaturePreview,
+ openFeaturePreviewModal,
+ closeFeaturePreviewModal,
+ toggleFeaturePreviewModal,
+ isFeaturePreviewReleasedToPublic,
+ ]
+ )
+}
diff --git a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
index 906853d35f1..ce6dce60408 100644
--- a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
+++ b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
@@ -5,17 +5,15 @@ import { ReactNode } from 'react'
import { LOCAL_STORAGE_KEYS, useParams } from 'common'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
-import { useIsRealtimeSettingsFFEnabled, useFlag } from 'hooks/ui/useFlag'
import { IS_PLATFORM } from 'lib/constants'
-import { useAppStateSnapshot } from 'state/app-state'
import { Badge, Button, Modal, ScrollArea, cn } from 'ui'
import { APISidePanelPreview } from './APISidePanelPreview'
+import { Branching2Preview } from './Branching2Preview'
import { CLSPreview } from './CLSPreview'
import { FEATURE_PREVIEWS } from './FeaturePreview.constants'
-import { useFeaturePreviewContext } from './FeaturePreviewContext'
+import { useFeaturePreviewContext, useFeaturePreviewModal } from './FeaturePreviewContext'
import { InlineEditorPreview } from './InlineEditorPreview'
import { RealtimeSettingsPreview } from './RealtimeSettingsPreview'
-import { Branching2Preview } from './Branching2Preview'
const FEATURE_PREVIEW_KEY_TO_CONTENT: {
[key: string]: ReactNode
@@ -29,32 +27,20 @@ const FEATURE_PREVIEW_KEY_TO_CONTENT: {
const FeaturePreviewModal = () => {
const { ref } = useParams()
- const snap = useAppStateSnapshot()
+ const {
+ showFeaturePreviewModal,
+ selectedFeatureKey,
+ selectFeaturePreview,
+ closeFeaturePreviewModal,
+ isFeaturePreviewReleasedToPublic,
+ } = useFeaturePreviewModal()
const org = useSelectedOrganization()
const featurePreviewContext = useFeaturePreviewContext()
const { mutate: sendEvent } = useSendEventMutation()
- const isRealtimeSettingsEnabled = useIsRealtimeSettingsFFEnabled()
- const gitlessBranchingEnabled = useFlag('gitlessBranching')
-
- // [Joshen] Use this if we want to feature flag previews
- function isReleasedToPublic(feature: (typeof FEATURE_PREVIEWS)[number]) {
- switch (feature.key) {
- case 'supabase-ui-realtime-settings':
- return isRealtimeSettingsEnabled
- case 'supabase-ui-branching-2-0':
- return gitlessBranchingEnabled
- default:
- return true
- }
- }
-
- const selectedFeatureKey =
- snap.selectedFeaturePreview === ''
- ? FEATURE_PREVIEWS.filter((feature) => isReleasedToPublic(feature))[0].key
- : snap.selectedFeaturePreview
const { flags, onUpdateFlag } = featurePreviewContext
- const selectedFeature = FEATURE_PREVIEWS.find((preview) => preview.key === selectedFeatureKey)
+ const selectedFeature =
+ FEATURE_PREVIEWS.find((preview) => preview.key === selectedFeatureKey) ?? FEATURE_PREVIEWS[0]
const isSelectedFeatureEnabled = flags[selectedFeatureKey]
const allFeaturePreviews = IS_PLATFORM
@@ -62,18 +48,14 @@ const FeaturePreviewModal = () => {
: FEATURE_PREVIEWS.filter((x) => !x.isPlatformOnly)
const toggleFeature = () => {
- onUpdateFlag(selectedFeatureKey, !isSelectedFeatureEnabled)
+ onUpdateFlag(selectedFeature.key, !isSelectedFeatureEnabled)
sendEvent({
action: isSelectedFeatureEnabled ? 'feature_preview_disabled' : 'feature_preview_enabled',
- properties: { feature: selectedFeatureKey },
+ properties: { feature: selectedFeature.key },
groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
})
}
- function handleCloseFeaturePreviewModal() {
- snap.setShowFeaturePreviewModal(false)
- }
-
return (
<Modal
hideFooter
@@ -81,25 +63,25 @@ const FeaturePreviewModal = () => {
size="xlarge"
className="!max-w-4xl"
header="Dashboard feature previews"
- visible={snap.showFeaturePreviewModal}
- onCancel={handleCloseFeaturePreviewModal}
+ visible={showFeaturePreviewModal}
+ onCancel={closeFeaturePreviewModal}
>
{FEATURE_PREVIEWS.length > 0 ? (
<div className="flex">
<div>
<ScrollArea className="h-[550px] w-[280px] border-r">
{allFeaturePreviews
- .filter((feature) => isReleasedToPublic(feature))
+ .filter((feature) => isFeaturePreviewReleasedToPublic(feature))
.map((feature) => {
const isEnabled = flags[feature.key] ?? false
return (
<div
key={feature.key}
- onClick={() => snap.setSelectedFeaturePreview(feature.key)}
+ onClick={() => selectFeaturePreview(feature.key)}
className={cn(
'flex items-center space-x-3 p-4 border-b cursor-pointer bg transition',
- selectedFeatureKey === feature.key ? 'bg-surface-300' : 'bg-surface-100'
+ selectedFeature.key === feature.key ? 'bg-surface-300' : 'bg-surface-100'
)}
>
{isEnabled ? (
@@ -134,7 +116,7 @@ const FeaturePreviewModal = () => {
</Button>
</div>
</div>
- {FEATURE_PREVIEW_KEY_TO_CONTENT[selectedFeatureKey]}
+ {FEATURE_PREVIEW_KEY_TO_CONTENT[selectedFeature.key]}
</div>
</div>
) : (
diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyEditorModal/index.tsx b/apps/studio/components/interfaces/Auth/Policies/PolicyEditorModal/index.tsx
index cbb8fea06b1..01849b8ae84 100644
--- a/apps/studio/components/interfaces/Auth/Policies/PolicyEditorModal/index.tsx
+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyEditorModal/index.tsx
@@ -2,7 +2,7 @@ import { isEmpty, noop } from 'lodash'
import { useEffect, useState } from 'react'
import { toast } from 'sonner'
-import { useAppStateSnapshot } from 'state/app-state'
+import { useFeaturePreviewModal } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { Modal } from 'ui'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import { POLICY_MODAL_VIEWS } from '../Policies.constants'
@@ -47,7 +47,7 @@ const PolicyEditorModal = ({
onUpdatePolicy,
onSaveSuccess = noop,
}: PolicyEditorModalProps) => {
- const snap = useAppStateSnapshot()
+ const { toggleFeaturePreviewModal } = useFeaturePreviewModal()
const newPolicyTemplate: PolicyFormField = {
schema,
@@ -95,7 +95,7 @@ const PolicyEditorModal = ({
const onSelectBackFromTemplates = () => setView(previousView)
const onToggleFeaturePreviewModal = () => {
- snap.setShowFeaturePreviewModal(!snap.showFeaturePreviewModal)
+ toggleFeaturePreviewModal()
onSelectCancel()
}
diff --git a/apps/studio/components/interfaces/LocalDropdown.tsx b/apps/studio/components/interfaces/LocalDropdown.tsx
index ae3e07bce65..d227a9ff4df 100644
--- a/apps/studio/components/interfaces/LocalDropdown.tsx
+++ b/apps/studio/components/interfaces/LocalDropdown.tsx
@@ -2,7 +2,6 @@ import { ProfileImage } from 'components/ui/ProfileImage'
import { Command, FlaskConical } from 'lucide-react'
import { useTheme } from 'next-themes'
-import { useAppStateSnapshot } from 'state/app-state'
import {
Button,
DropdownMenu,
@@ -18,11 +17,12 @@ import {
Theme,
} from 'ui'
import { useSetCommandMenuOpen } from 'ui-patterns'
+import { useFeaturePreviewModal } from './App/FeaturePreview/FeaturePreviewContext'
export const LocalDropdown = () => {
const { theme, setTheme } = useTheme()
- const snap = useAppStateSnapshot()
const setCommandMenuOpen = useSetCommandMenuOpen()
+ const { openFeaturePreviewModal } = useFeaturePreviewModal()
return (
<DropdownMenu>
@@ -37,8 +37,8 @@ export const LocalDropdown = () => {
<DropdownMenuContent side="bottom" align="end" className="w-44">
<DropdownMenuItem
className="flex gap-2"
- onClick={() => snap.setShowFeaturePreviewModal(true)}
- onSelect={() => snap.setShowFeaturePreviewModal(true)}
+ onClick={openFeaturePreviewModal}
+ onSelect={openFeaturePreviewModal}
>
<FlaskConical size={14} strokeWidth={1.5} className="text-foreground-lighter" />
Feature previews
diff --git a/apps/studio/components/interfaces/UserDropdown.tsx b/apps/studio/components/interfaces/UserDropdown.tsx
index d3efda8c593..f9dc116ecfd 100644
--- a/apps/studio/components/interfaces/UserDropdown.tsx
+++ b/apps/studio/components/interfaces/UserDropdown.tsx
@@ -23,6 +23,7 @@ import {
singleThemes,
} from 'ui'
import { useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'
+import { useFeaturePreviewModal } from './App/FeaturePreview/FeaturePreviewContext'
export function UserDropdown() {
const router = useRouter()
@@ -31,6 +32,7 @@ export function UserDropdown() {
const { theme, setTheme } = useTheme()
const appStateSnapshot = useAppStateSnapshot()
const setCommandMenuOpen = useSetCommandMenuOpen()
+ const { openFeaturePreviewModal } = useFeaturePreviewModal()
return (
<DropdownMenu>
@@ -87,8 +89,8 @@ export function UserDropdown() {
</DropdownMenuItem>
<DropdownMenuItem
className="flex gap-2"
- onClick={() => appStateSnapshot.setShowFeaturePreviewModal(true)}
- onSelect={() => appStateSnapshot.setShowFeaturePreviewModal(true)}
+ onClick={openFeaturePreviewModal}
+ onSelect={openFeaturePreviewModal}
>
<FlaskConical size={14} strokeWidth={1.5} className="text-foreground-lighter" />
Feature previews
diff --git a/apps/studio/pages/project/[ref]/database/column-privileges.tsx b/apps/studio/pages/project/[ref]/database/column-privileges.tsx
index 3a632285c63..abbd13827b3 100644
--- a/apps/studio/pages/project/[ref]/database/column-privileges.tsx
+++ b/apps/studio/pages/project/[ref]/database/column-privileges.tsx
@@ -4,7 +4,10 @@ import Link from 'next/link'
import { useCallback, useMemo, useState } from 'react'
import { toast } from 'sonner'
-import { useIsColumnLevelPrivilegesEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
+import {
+ useFeaturePreviewModal,
+ useIsColumnLevelPrivilegesEnabled,
+} from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import {
getDefaultColumnCheckedStates,
getDefaultTableCheckedStates,
@@ -28,7 +31,6 @@ import { useTablesQuery } from 'data/tables/tables-query'
import { useLocalStorage } from 'hooks/misc/useLocalStorage'
import { useQuerySchemaState } from 'hooks/misc/useSchemaQueryState'
import { PROTECTED_SCHEMAS } from 'lib/constants/schemas'
-import { useAppStateSnapshot } from 'state/app-state'
import type { NextPageWithLayout } from 'types'
import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button } from 'ui'
@@ -37,7 +39,7 @@ const EDITABLE_ROLES = ['authenticated', 'anon', 'service_role']
const PrivilegesPage: NextPageWithLayout = () => {
const { ref, table: paramTable } = useParams()
const { project } = useProjectContext()
- const snap = useAppStateSnapshot()
+ const { openFeaturePreviewModal } = useFeaturePreviewModal()
const isEnabled = useIsColumnLevelPrivilegesEnabled()
const { selectedSchema, setSelectedSchema } = useQuerySchemaState()
@@ -345,7 +347,7 @@ const PrivilegesPage: NextPageWithLayout = () => {
You may access this feature by enabling it under dashboard feature previews.
</AlertDescription_Shadcn_>
<div className="mt-4">
- <Button type="default" onClick={() => snap.setShowFeaturePreviewModal(true)}>
+ <Button type="default" onClick={openFeaturePreviewModal}>
View feature previews
</Button>
</div>
diff --git a/apps/studio/state/app-state.ts b/apps/studio/state/app-state.ts
index 56a6ca3b6f1..9303cc4ed12 100644
--- a/apps/studio/state/app-state.ts
+++ b/apps/studio/state/app-state.ts
@@ -52,8 +52,6 @@ const getInitialState = () => {
docsLanguage: 'js',
showProjectApiDocs: false,
showCreateBranchModal: false,
- showFeaturePreviewModal: false,
- selectedFeaturePreview: '',
showAiSettingsModal: false,
showConnectDialog: false,
ongoingQueriesPanelOpen: false,
@@ -82,8 +80,6 @@ const getInitialState = () => {
docsLanguage: 'js',
showProjectApiDocs: false,
showCreateBranchModal: false,
- showFeaturePreviewModal: false,
- selectedFeaturePreview: '',
showAiSettingsModal: false,
showConnectDialog: false,
ongoingQueriesPanelOpen: false,
@@ -137,16 +133,6 @@ export const appState = proxy({
appState.showCreateBranchModal = value
},
- showFeaturePreviewModal: false,
- setShowFeaturePreviewModal: (value: boolean) => {
- appState.showFeaturePreviewModal = value
- },
-
- selectedFeaturePreview: '',
- setSelectedFeaturePreview: (value: string) => {
- appState.selectedFeaturePreview = value
- },
-
showAiSettingsModal: false,
setShowAiSettingsModal: (value: boolean) => {
appState.showAiSettingsModal = value