The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: new getting started section to open correct presets in Connect dialog DESIGN-302 (#39731)
Jordi Enricaa30698cc254
diff --git a/apps/studio/components/interfaces/Connect/Connect.tsx b/apps/studio/components/interfaces/Connect/Connect.tsxindex 3a8cb3a7c52..446c704d376 100644--- a/apps/studio/components/interfaces/Connect/Connect.tsx+++ b/apps/studio/components/interfaces/Connect/Connect.tsx@@ -14,6 +14,7 @@ import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { PROJECT_STATUS } from 'lib/constants'+import { useRouter } from 'next/router'import {Button,DIALOG_PADDING_X,@@ -32,11 +33,12 @@ import {cn,} from 'ui'import { CONNECTION_TYPES, ConnectionType, FRAMEWORKS, MOBILES, ORMS } from './Connect.constants'-import { getContentFilePath } from './Connect.utils'+import { getContentFilePath, inferConnectTabFromParentKey } from './Connect.utils'import { ConnectDropdown } from './ConnectDropdown'import { ConnectTabContent } from './ConnectTabContent'export const Connect = () => {+ const router = useRouter()const { ref: projectRef } = useParams()const { data: selectedProject } = useSelectedProjectQuery()const isActiveHealthy = selectedProject?.status === PROJECT_STATUS.ACTIVE_HEALTHY@@ -83,7 +85,7 @@ export const Connect = () => {}}- const [tab, setTab] = useQueryState('tab', parseAsString.withDefault('direct'))+ const [tab, setTab] = useQueryState('connectTab', parseAsString.withDefault('direct'))const [queryFramework, setQueryFramework] = useQueryState('framework', parseAsString)const [queryUsing, setQueryUsing] = useQueryState('using', parseAsString)const [queryWith, setQueryWith] = useQueryState('with', parseAsString)@@ -264,6 +266,20 @@ export const Connect = () => {}}+ useEffect(() => {+ if (!showConnect) return+ const noConnectTabInUrl = typeof router.query.connectTab === 'undefined'+ const hasQuery = queryFramework || queryUsing || queryWith+ const inferred = inferConnectTabFromParentKey(queryFramework)++ if (noConnectTabInUrl && hasQuery && inferred) {+ setTab(inferred)+ if (inferred === 'frameworks') setConnectionObject(FRAMEWORKS)+ if (inferred === 'mobiles') setConnectionObject(MOBILES)+ if (inferred === 'orms') setConnectionObject(ORMS)+ }+ }, [showConnect, router.query.connectTab, queryFramework, queryUsing, queryWith, setTab])+useEffect(() => {if (!showConnect) return@@ -293,7 +309,16 @@ export const Connect = () => {if (queryWith) {if (grandchild?.key !== queryWith) setQueryWith(grandchild?.key ?? null)}- }, [showConnect, tab, FRAMEWORKS, queryFramework, queryUsing, queryWith])+ }, [+ showConnect,+ tab,+ queryFramework,+ setQueryFramework,+ queryUsing,+ setQueryUsing,+ queryWith,+ setQueryWith,+ ])if (!isActiveHealthy) {return (@@ -333,7 +358,7 @@ export const Connect = () => {</DialogHeader><Tabs_Shadcn_- defaultValue={tab}+ value={tab}onValueChange={(value) => {resetQueryStates()handleConnectionType(value)diff --git a/apps/studio/components/interfaces/Connect/Connect.utils.ts b/apps/studio/components/interfaces/Connect/Connect.utils.tsindex 9c497fb095d..885604d1896 100644--- a/apps/studio/components/interfaces/Connect/Connect.utils.ts+++ b/apps/studio/components/interfaces/Connect/Connect.utils.ts@@ -1,4 +1,4 @@-import { ConnectionType } from './Connect.constants'+import { ConnectionType, FRAMEWORKS, MOBILES, ORMS } from './Connect.constants'export function getProjectRef(url: string): string | null {const regex: RegExp = /https:\/\/([^\.]+)\./@@ -43,3 +43,13 @@ export const getContentFilePath = ({return ''}++export function inferConnectTabFromParentKey(+ parentKey: string | null+): 'frameworks' | 'mobiles' | 'orms' | null {+ if (!parentKey) return null+ if (FRAMEWORKS.find((x: ConnectionType) => x.key === parentKey)) return 'frameworks'+ if (MOBILES.find((x: ConnectionType) => x.key === parentKey)) return 'mobiles'+ if (ORMS.find((x: ConnectionType) => x.key === parentKey)) return 'orms'+ return null+}diff --git a/apps/studio/components/interfaces/HomeNew/GettingStarted/Connect.test.ts b/apps/studio/components/interfaces/HomeNew/GettingStarted/Connect.test.tsnew file mode 100644index 00000000000..9e6a4b54599--- /dev/null+++ b/apps/studio/components/interfaces/HomeNew/GettingStarted/Connect.test.ts@@ -0,0 +1,70 @@+import { describe, it, expect } from 'vitest'+import {+ getContentFilePath,+ inferConnectTabFromParentKey,+} from 'components/interfaces/Connect/Connect.utils'+import { FRAMEWORKS } from 'components/interfaces/Connect/Connect.constants'++describe('Connect.utils helpers', () => {+ it('inferConnectTabFromParentKey returns frameworks for nextjs', () => {+ expect(inferConnectTabFromParentKey('nextjs')).toBe('frameworks')+ })++ it('inferConnectTabFromParentKey returns null for unknown', () => {+ expect(inferConnectTabFromParentKey('unknown-x')).toBeNull()+ })++ it('inferConnectTabFromParentKey returns mobiles for exporeactnative', () => {+ expect(inferConnectTabFromParentKey('exporeactnative')).toBe('mobiles')+ })++ it('inferConnectTabFromParentKey returns orms for prisma', () => {+ expect(inferConnectTabFromParentKey('prisma')).toBe('orms')+ })++ it('inferConnectTabFromParentKey returns null for null parentKey', () => {+ expect(inferConnectTabFromParentKey(null)).toBeNull()+ })++ describe('getContentFilePath', () => {+ it('returns parent/child/grandchild when all exist', () => {+ const path = getContentFilePath({+ connectionObject: FRAMEWORKS,+ selectedParent: 'nextjs',+ selectedChild: 'app',+ selectedGrandchild: 'supabasejs',+ })+ expect(path).toBe('nextjs/app/supabasejs')+ })++ it('returns parent/child when grandchild does not exist', () => {+ const path = getContentFilePath({+ connectionObject: FRAMEWORKS,+ selectedParent: 'remix',+ selectedChild: 'supabasejs',+ selectedGrandchild: 'does-not-exist',+ })+ expect(path).toBe('remix/supabasejs')+ })++ it('returns parent when child does not exist', () => {+ const path = getContentFilePath({+ connectionObject: FRAMEWORKS,+ selectedParent: 'nextjs',+ selectedChild: 'unknown-child',+ selectedGrandchild: 'any',+ })+ expect(path).toBe('nextjs')+ })++ it('returns empty string when parent does not exist', () => {+ const path = getContentFilePath({+ connectionObject: FRAMEWORKS,+ selectedParent: 'unknown-parent',+ selectedChild: 'any',+ selectedGrandchild: 'any',+ })+ expect(path).toBe('')+ })+ })+})diff --git a/apps/studio/components/interfaces/HomeNew/GettingStarted/FrameworkSelector.tsx b/apps/studio/components/interfaces/HomeNew/GettingStarted/FrameworkSelector.tsxindex 5be91506db4..22b38428edf 100644--- a/apps/studio/components/interfaces/HomeNew/GettingStarted/FrameworkSelector.tsx+++ b/apps/studio/components/interfaces/HomeNew/GettingStarted/FrameworkSelector.tsx@@ -45,7 +45,7 @@ export const FrameworkSelector = ({<Buttonsize="tiny"type="default"- className="gap-0 rounded-l-none"+ className="gap-0"iconRight={<ChevronDown strokeWidth={1.5} />}><div className="flex items-center gap-2">@@ -55,7 +55,14 @@ export const FrameworkSelector = ({</Button></PopoverTrigger_Shadcn_></div>- <PopoverContent_Shadcn_ className="p-0 max-w-48" side="bottom" align="start">+ {/* Render in a portal to avoid layout/stacking shifts; prevent auto-focus to stop scroll jump */}+ <PopoverContent_Shadcn_+ className="p-0 max-w-48"+ side="bottom"+ align="start"+ portal+ onOpenAutoFocus={(e) => e.preventDefault()}+ ><Command_Shadcn_><CommandInput_Shadcn_ placeholder="Search..." /><CommandList_Shadcn_>diff --git a/apps/studio/components/interfaces/HomeNew/GettingStarted/GettingStartedSection.tsx b/apps/studio/components/interfaces/HomeNew/GettingStarted/GettingStartedSection.tsxindex ba121daa170..165faed1418 100644--- a/apps/studio/components/interfaces/HomeNew/GettingStarted/GettingStartedSection.tsx+++ b/apps/studio/components/interfaces/HomeNew/GettingStarted/GettingStartedSection.tsx@@ -48,42 +48,68 @@ export function GettingStartedSection({ value, onChange }: GettingStartedSection[aiSnap])- const openConnect = useCallback(() => {- router.push(- {- pathname: router.pathname,- query: {- ...router.query,- showConnect: true,- connectTab: 'frameworks',- framework: selectedFramework,+ const connectPresetLinks = useMemo(() => {+ const basePath = router.asPath.split('?')[0]+ const parent = FRAMEWORKS.find((f) => f.key === selectedFramework)+ if (!parent) {+ return [+ {+ label: 'Connect',+ href: `${basePath}?showConnect=true&connectTab=frameworks`,},- },- undefined,- { shallow: true }- )- }, [router, selectedFramework])+ ]+ }- const connectActions: GettingStartedAction[] = useMemo(- () => [- {- label: 'Framework selector',- component: (- <FrameworkSelector- value={selectedFramework}- onChange={setSelectedFramework}- items={FRAMEWORKS}- />- ),- },+ let using: string | undefined+ let withKey: string | undefined+ if (parent.children && parent.children.length > 0) {+ // prefer App Router for Nextjs by default+ if (parent.key === 'nextjs') {+ const appChild = parent.children.find((c) => c.key === 'app') || parent.children[0]+ using = appChild?.key+ withKey = appChild?.children?.[0]?.key+ } else {+ using = parent.children[0]?.key+ withKey = parent.children[0]?.children?.[0]?.key+ }+ }++ const qs = new URLSearchParams({+ showConnect: 'true',+ connectTab: 'frameworks',+ framework: parent.key,+ })+ if (using) qs.set('using', using)+ if (withKey) qs.set('with', withKey)++ return [{label: 'Connect',- variant: 'primary',- onClick: openConnect,+ href: `${basePath}?${qs.toString()}`,},- ],- [openConnect, selectedFramework]- )+ ]+ }, [router.asPath, selectedFramework])++ const connectActions: GettingStartedAction[] = useMemo(() => {+ const selector: GettingStartedAction = {+ label: 'Framework selector',+ component: (+ <FrameworkSelector+ value={selectedFramework}+ onChange={setSelectedFramework}+ items={FRAMEWORKS}+ />+ ),+ }++ const linkActions: GettingStartedAction[] = connectPresetLinks.map((lnk) => ({+ label: 'Connect',+ href: lnk.href,+ variant: 'primary',+ }))++ return [selector, ...linkActions]+ }, [connectPresetLinks, selectedFramework])const codeSteps: GettingStartedStep[] = useMemo(() =>