The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: studio connect framework state (#38637)
hallidayo22e09b81d0c5
diff --git a/apps/studio/components/interfaces/Connect/Connect.tsx b/apps/studio/components/interfaces/Connect/Connect.tsxindex 7118434b3d7..93083518fb5 100644--- a/apps/studio/components/interfaces/Connect/Connect.tsx+++ b/apps/studio/components/interfaces/Connect/Connect.tsx@@ -2,7 +2,7 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'import { useParams } from 'common'import { ExternalLink, Plug } from 'lucide-react'import { parseAsBoolean, parseAsString, useQueryState } from 'nuqs'-import { useMemo, useState } from 'react'+import { useEffect, useMemo, useState } from 'react'import { DatabaseConnectionString } from 'components/interfaces/Connect/DatabaseConnectionString'import { ButtonTooltip } from 'components/ui/ButtonTooltip'@@ -69,7 +69,24 @@ export const Connect = () => {parseAsBoolean.withDefault(false))+ // helper to get tthe connection type object+ function getConnectionObjectForTab(tab: string | null, frameworks: ConnectionType[]) {+ switch (tab) {+ case 'frameworks':+ return frameworks+ case 'mobiles':+ return MOBILES+ case 'orms':+ return ORMS+ default:+ return FRAMEWORKS+ }+ }+const [tab, setTab] = useQueryState('tab', parseAsString.withDefault('direct'))+ const [queryFramework, setQueryFramework] = useQueryState('framework', parseAsString)+ const [queryUsing, setQueryUsing] = useQueryState('using', parseAsString)+ const [queryWith, setQueryWith] = useQueryState('with', parseAsString)const [connectionObject, setConnectionObject] = useState<ConnectionType[]>(FRAMEWORKS)const [selectedParent, setSelectedParent] = useState(connectionObject[0].key) // aka nextjs@@ -92,31 +109,55 @@ export const Connect = () => {const handleParentChange = (value: string) => {setSelectedParent(value)+ setQueryFramework(value)- // check if parent has children- setSelectedChild(connectionObject.find((item) => item.key === value)?.children[0]?.key ?? '')+ const parent = connectionObject.find((item) => item.key === value)+ const firstChild = parent?.children?.[0]- // check if child has grandchildren- setSelectedGrandchild(- connectionObject.find((item) => item.key === value)?.children[0]?.children[0]?.key ?? ''- )+ if (firstChild) {+ setSelectedChild(firstChild.key)+ setQueryUsing(firstChild.key)++ const firstGrandchild = firstChild.children?.[0]+ if (firstGrandchild) {+ setSelectedGrandchild(firstGrandchild.key)+ setQueryWith(firstGrandchild.key)+ } else {+ setSelectedGrandchild('')+ setQueryWith(null)+ }+ } else {+ setSelectedChild('')+ setQueryUsing(null)+ setSelectedGrandchild('')+ setQueryWith(null)+ }}const handleChildChange = (value: string) => {setSelectedChild(value)+ setQueryUsing(value)const parent = connectionObject.find((item) => item.key === selectedParent)const child = parent?.children.find((child) => child.key === value)+ const firstGrandchild = child?.children?.[0]- if (child && child.children.length > 0) {- setSelectedGrandchild(child.children[0].key)+ if (firstGrandchild) {+ setSelectedGrandchild(firstGrandchild.key)+ setQueryWith(firstGrandchild.key)} else {setSelectedGrandchild('')+ setQueryWith(null)}}const handleGrandchildChange = (value: string) => {setSelectedGrandchild(value)+ if (value) {+ setQueryWith(value)+ } else {+ setQueryWith(null)+ }}// reset the parent/child/grandchild when the connection type (tab) changes@@ -207,11 +248,45 @@ export const Connect = () => {if (!open) {setShowConnect(null)setTab(null)+ setQueryFramework(null)+ setQueryUsing(null)+ setQueryWith(null)} else {setShowConnect(open)}}+ useEffect(() => {+ if (!showConnect) return++ const newConnectionObject = getConnectionObjectForTab(tab, frameworks)+ setConnectionObject(newConnectionObject)++ const parent =+ newConnectionObject.find((item) => item.key === queryFramework) ?? newConnectionObject[0]+ setSelectedParent(parent?.key ?? '')++ if (queryFramework) {+ if (parent?.key !== queryFramework) setQueryFramework(parent?.key ?? null)+ }++ const child =+ parent?.children.find((child) => child.key === queryUsing) ?? parent?.children?.[0]+ setSelectedChild(child?.key ?? '')++ if (queryUsing) {+ if (child?.key !== queryUsing) setQueryUsing(child?.key ?? null)+ }++ const grandchild =+ child?.children.find((child) => child.key === queryWith) ?? child?.children?.[0]+ setSelectedGrandchild(grandchild?.key ?? '')++ if (queryWith) {+ if (grandchild?.key !== queryWith) setQueryWith(grandchild?.key ?? null)+ }+ }, [showConnect, tab, frameworks, queryFramework, queryUsing, queryWith])+if (!isActiveHealthy) {return (<ButtonTooltip