The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add URL param support to toggle connect UI (#31241)
Joshen Lime64896613117
diff --git a/apps/studio/components/interfaces/Connect/Connect.tsx b/apps/studio/components/interfaces/Connect/Connect.tsxindex 9a4c306e578..9a107bf7c3c 100644--- a/apps/studio/components/interfaces/Connect/Connect.tsx+++ b/apps/studio/components/interfaces/Connect/Connect.tsx@@ -10,7 +10,7 @@ import Panel from 'components/ui/Panel'import { getAPIKeys, useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'import { useFlag } from 'hooks/ui/useFlag'-import { useAppStateSnapshot } from 'state/app-state'+import { parseAsBoolean, useQueryState } from 'nuqs'import {Button,DIALOG_PADDING_X,@@ -33,10 +33,14 @@ import ConnectDropdown from './ConnectDropdown'import ConnectTabContent from './ConnectTabContent'const Connect = () => {- const state = useAppStateSnapshot()const { ref: projectRef } = useParams()const connectDialogUpdate = useFlag('connectDialogUpdate')+ const [showConnect, setShowConnect] = useQueryState(+ 'showConnect',+ parseAsBoolean.withDefault(false)+ )+const [connectionObject, setConnectionObject] = useState<ConnectionType[]>(FRAMEWORKS)const [selectedParent, setSelectedParent] = useState(connectionObject[0].key) // aka nextjsconst [selectedChild, setSelectedChild] = useState(@@ -148,141 +152,135 @@ const Connect = () => {})return (- <>- <Dialog open={state.showConnectDialog} onOpenChange={state.setShowConnectDialog}>- <DialogTrigger asChild>- <Button- type={connectDialogUpdate ? 'default' : 'primary'}- className={cn(connectDialogUpdate && 'rounded-full')}- icon={<Plug className="rotate-90" />}- >- <span>Connect</span>- </Button>- </DialogTrigger>- <DialogContent className={cn('sm:max-w-5xl p-0')} centered={false}>- <DialogHeader className={DIALOG_PADDING_X}>- <DialogTitle>Connect to your project</DialogTitle>- <DialogDescription>- Get the connection strings and environment variables for your app- </DialogDescription>- </DialogHeader>+ <Dialog open={showConnect} onOpenChange={(open) => setShowConnect(!open ? null : open)}>+ <DialogTrigger asChild>+ <Button+ type={connectDialogUpdate ? 'default' : 'primary'}+ className={cn(connectDialogUpdate && 'rounded-full')}+ icon={<Plug className="rotate-90" />}+ >+ <span>Connect</span>+ </Button>+ </DialogTrigger>+ <DialogContent className={cn('sm:max-w-5xl p-0')} centered={false}>+ <DialogHeader className={DIALOG_PADDING_X}>+ <DialogTitle>Connect to your project</DialogTitle>+ <DialogDescription>+ Get the connection strings and environment variables for your app+ </DialogDescription>+ </DialogHeader>- <Tabs_Shadcn_- defaultValue="direct"- onValueChange={(value) => handleConnectionType(value)}- >- <TabsList_Shadcn_ className={cn('flex gap-x-4', DIALOG_PADDING_X)}>- {CONNECTION_TYPES.map((type) => (- <TabsTrigger_Shadcn_ key={type.key} value={type.key} className="px-0">- {type.label}- </TabsTrigger_Shadcn_>- ))}- </TabsList_Shadcn_>+ <Tabs_Shadcn_ defaultValue="direct" onValueChange={(value) => handleConnectionType(value)}>+ <TabsList_Shadcn_ className={cn('flex gap-x-4', DIALOG_PADDING_X)}>+ {CONNECTION_TYPES.map((type) => (+ <TabsTrigger_Shadcn_ key={type.key} value={type.key} className="px-0">+ {type.label}+ </TabsTrigger_Shadcn_>+ ))}+ </TabsList_Shadcn_>- {CONNECTION_TYPES.map((type) => {- const hasChildOptions =- (connectionObject.find((parent) => parent.key === selectedParent)?.children- .length || 0) > 0- const hasGrandChildOptions =- (connectionObject- .find((parent) => parent.key === selectedParent)- ?.children.find((child) => child.key === selectedChild)?.children.length || 0) > 0-- if (type.key === 'direct') {- return (- <TabsContent_Shadcn_- key="direct"- value="direct"- className={cn('!mt-0', 'p-0', 'flex flex-col gap-6')}- >- <div className={DIALOG_PADDING_Y}>- {connectDialogUpdate ? (- <DatabaseConnectionString />- ) : (- <div className="px-7">- <OldDatabaseConnectionString appearance="minimal" />- </div>- )}- </div>- </TabsContent_Shadcn_>- )- }+ {CONNECTION_TYPES.map((type) => {+ const hasChildOptions =+ (connectionObject.find((parent) => parent.key === selectedParent)?.children.length ||+ 0) > 0+ const hasGrandChildOptions =+ (connectionObject+ .find((parent) => parent.key === selectedParent)+ ?.children.find((child) => child.key === selectedChild)?.children.length || 0) > 0+ if (type.key === 'direct') {return (<TabsContent_Shadcn_- key={`content-${type.key}`}- value={type.key}- className={cn(DIALOG_PADDING_X, DIALOG_PADDING_Y, '!mt-0')}+ key="direct"+ value="direct"+ className={cn('!mt-0', 'p-0', 'flex flex-col gap-6')}>- <div className="flex justify-between">- <div className="flex items-center gap-3">+ <div className={DIALOG_PADDING_Y}>+ {connectDialogUpdate ? (+ <DatabaseConnectionString />+ ) : (+ <div className="px-7">+ <OldDatabaseConnectionString appearance="minimal" />+ </div>+ )}+ </div>+ </TabsContent_Shadcn_>+ )+ }++ return (+ <TabsContent_Shadcn_+ key={`content-${type.key}`}+ value={type.key}+ className={cn(DIALOG_PADDING_X, DIALOG_PADDING_Y, '!mt-0')}+ >+ <div className="flex justify-between">+ <div className="flex items-center gap-3">+ <ConnectDropdown+ state={selectedParent}+ updateState={handleParentChange}+ label={+ connectionObject === FRAMEWORKS || connectionObject === MOBILES+ ? 'Framework'+ : 'Tool'+ }+ items={connectionObject}+ />+ {selectedParent && hasChildOptions && (<ConnectDropdown- state={selectedParent}- updateState={handleParentChange}- label={- connectionObject === FRAMEWORKS || connectionObject === MOBILES- ? 'Framework'- : 'Tool'- }- items={connectionObject}+ state={selectedChild}+ updateState={handleChildChange}+ label="Using"+ items={getChildOptions()}+ />+ )}+ {selectedChild && hasGrandChildOptions && (+ <ConnectDropdown+ state={selectedGrandchild}+ updateState={handleGrandchildChange}+ label="With"+ items={getGrandchildrenOptions()}/>- {selectedParent && hasChildOptions && (- <ConnectDropdown- state={selectedChild}- updateState={handleChildChange}- label="Using"- items={getChildOptions()}- />- )}- {selectedChild && hasGrandChildOptions && (- <ConnectDropdown- state={selectedGrandchild}- updateState={handleGrandchildChange}- label="With"- items={getGrandchildrenOptions()}- />- )}- </div>- {connectionObject.find((item) => item.key === selectedParent)?.guideLink && (- <Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>- <a- target="_blank"- rel="noreferrer"- href={- connectionObject.find((item) => item.key === selectedParent)- ?.guideLink || ''- }- >- {connectionObject.find((item) => item.key === selectedParent)?.label}{' '}- guide- </a>- </Button>)}</div>- <p className="text-xs text-foreground-lighter my-3">- Add the following files below to your application- </p>- <ConnectTabContent- projectKeys={projectKeys}- filePath={filePath}- className="rounded-b-none"- />- <Panel.Notice- className="border border-t-0 rounded-lg rounded-t-none"- title="New API keys coming Q4 2024"- description={`+ {connectionObject.find((item) => item.key === selectedParent)?.guideLink && (+ <Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>+ <a+ target="_blank"+ rel="noreferrer"+ href={+ connectionObject.find((item) => item.key === selectedParent)?.guideLink ||+ ''+ }+ >+ {connectionObject.find((item) => item.key === selectedParent)?.label} guide+ </a>+ </Button>+ )}+ </div>+ <p className="text-xs text-foreground-lighter my-3">+ Add the following files below to your application+ </p>+ <ConnectTabContent+ projectKeys={projectKeys}+ filePath={filePath}+ className="rounded-b-none"+ />+ <Panel.Notice+ className="border border-t-0 rounded-lg rounded-t-none"+ title="New API keys coming Q4 2024"+ description={`\`anon\` and \`service_role\` API keys will be changing to \`publishable\` and \`secret\` API keys.`}- href="https://github.com/orgs/supabase/discussions/29260"- buttonText="Read the announcement"- />- </TabsContent_Shadcn_>- )- })}- </Tabs_Shadcn_>- </DialogContent>- </Dialog>- </>+ href="https://github.com/orgs/supabase/discussions/29260"+ buttonText="Read the announcement"+ />+ </TabsContent_Shadcn_>+ )+ })}+ </Tabs_Shadcn_>+ </DialogContent>+ </Dialog>)}diff --git a/apps/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx b/apps/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsxindex 149f5631e32..4140d5e66af 100644--- a/apps/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx+++ b/apps/studio/components/interfaces/Organization/TeamSettings/TeamSettings.tsx@@ -17,6 +17,7 @@ import { useOrganizationMembersQuery } from 'data/organizations/organization-memimport { usePermissionsQuery } from 'data/permissions/permissions-query'import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'+import { BASE_PATH } from 'lib/constants'import { useProfile } from 'lib/profile'import { Input } from 'ui'import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'@@ -25,13 +26,12 @@ import MembersView from './MembersView'import { hasMultipleOwners, useGetRolesManagementPermissions } from './TeamSettings.utils'const TeamSettings = () => {- const { slug } = useParams()-const {organizationMembersCreate: organizationMembersCreationEnabled,organizationMembersDelete: organizationMembersDeletionEnabled,} = useIsFeatureEnabled(['organization_members:create', 'organization_members:delete'])+ const { slug } = useParams()const { profile } = useProfile()const selectedOrganization = useSelectedOrganization()const isOwner = selectedOrganization?.is_owner@@ -58,7 +58,7 @@ const TeamSettings = () => {onSuccess: () => {setIsLeaving(false)setIsLeaveTeamModalOpen(false)- window?.location.replace('/') // Force reload to clear Store+ window?.location.replace(BASE_PATH) // Force reload to clear Store},onError: (error) => {setIsLeaving(false)@@ -81,6 +81,7 @@ const TeamSettings = () => {<ScaffoldFilterAndContent><ScaffoldActionsContainer className="justify-between"><Input+ autoComplete="off"icon={<Search size={12} />}size="small"value={searchString}diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/Infrastructure.constants.ts b/apps/studio/components/interfaces/Settings/Infrastructure/Infrastructure.constants.tsindex 10b0adac3ce..a936975a75d 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/Infrastructure.constants.ts+++ b/apps/studio/components/interfaces/Settings/Infrastructure/Infrastructure.constants.ts@@ -58,7 +58,7 @@ export const INFRA_ACTIVITY_METRICS: CategoryMeta[] = [name: 'Memory',unit: 'percentage',description:- 'Memory usage of your server.\nYou might observe elevated memory usage, even with little to no load. Besides Postgres, a wide range of services is running under the hood resulting in an elevated base memory usage.',+ 'Memory usage of your server.\nYou might observe elevated memory usage, even with little to no load. Besides Postgres, a wide range of services are running under the hood resulting in an elevated base memory usage.',chartDescription: '',links: [{diff --git a/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsxindex 5aae43c23d6..b9f06ebbed7 100644--- a/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx+++ b/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx@@ -1,14 +1,6 @@import Head from 'next/head'import { useRouter } from 'next/router'-import {- forwardRef,- Fragment,- PropsWithChildren,- ReactNode,- useCallback,- useEffect,- useState,-} from 'react'+import { forwardRef, Fragment, PropsWithChildren, ReactNode, useEffect, useState } from 'react'import { useParams } from 'common'import ProjectAPIDocs from 'components/interfaces/ProjectAPIDocs/ProjectAPIDocs'@@ -22,16 +14,17 @@ import { withAuth } from 'hooks/misc/withAuth'import { IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'import { useAppStateSnapshot } from 'state/app-state'import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'-import { cn, ResizableHandle, ResizablePanel, ResizablePanelGroup, Sheet, SheetContent } from 'ui'+import { cn, ResizableHandle, ResizablePanel, ResizablePanelGroup } from 'ui'+import MobileSheetNav from 'ui-patterns/MobileSheetNav/MobileSheetNav'import AppLayout from '../AppLayout/AppLayout'import EnableBranchingModal from '../AppLayout/EnableBranchingButton/EnableBranchingModal'import BuildingState from './BuildingState'import ConnectingState from './ConnectingState'import { LayoutHeader } from './LayoutHeader'import LoadingState from './LoadingState'-import NavigationBar from './NavigationBar/NavigationBar'import MobileNavigationBar from './NavigationBar/MobileNavigationBar'import MobileViewNav from './NavigationBar/MobileViewNav'+import NavigationBar from './NavigationBar/NavigationBar'import { ProjectPausedState } from './PausedState/ProjectPausedState'import PauseFailedState from './PauseFailedState'import PausingState from './PausingState'@@ -42,7 +35,6 @@ import RestartingState from './RestartingState'import RestoreFailedState from './RestoreFailedState'import RestoringState from './RestoringState'import { UpgradingState } from './UpgradingState'-import MobileSheetNav from 'ui-patterns/MobileSheetNav/MobileSheetNav'// [Joshen] This is temporary while we unblock users from managing their project// if their project is not responding well for any reason. Eventually needs a bit of an overhaul@@ -98,6 +90,7 @@ const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<ProjectLayoutref) => {const router = useRouter()+ const [isClient, setIsClient] = useState(false)const [isSheetOpen, setIsSheetOpen] = useState(false)const { ref: projectRef } = useParams()const selectedOrganization = useSelectedOrganization()@@ -119,7 +112,9 @@ const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<ProjectLayoutrouter.pathname === '/project/[ref]' || router.pathname.includes('/project/[ref]/settings')const showPausedState = isPaused && !ignorePausedState- const [isClient, setIsClient] = useState(false)+ const handleMobileMenu = () => {+ setIsSheetOpen(true)+ }useEffect(() => {setIsClient(true)@@ -138,10 +133,6 @@ const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<ProjectLayout// eslint-disable-next-line react-hooks/exhaustive-deps}, [open])- const handleMobileMenu = () => {- setIsSheetOpen(true)- }-return (<AppLayout><ProjectContextProvider projectRef={projectRef}>diff --git a/apps/studio/components/ui/DatabaseSelector.tsx b/apps/studio/components/ui/DatabaseSelector.tsxindex 72dc0c795d9..002cb3cabc8 100644--- a/apps/studio/components/ui/DatabaseSelector.tsx+++ b/apps/studio/components/ui/DatabaseSelector.tsx@@ -2,6 +2,7 @@ import { noop } from 'lodash'import { Check, ChevronDown, Loader2, Plus } from 'lucide-react'import Link from 'next/link'import { useRouter } from 'next/router'+import { parseAsBoolean, useQueryState } from 'nuqs'import { useState } from 'react'import { useParams } from 'common'@@ -9,6 +10,7 @@ import { Markdown } from 'components/interfaces/Markdown'import { REPLICA_STATUS } from 'components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceConfiguration.constants'import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'import { formatDatabaseID, formatDatabaseRegion } from 'data/read-replicas/replicas.utils'+import { useAppStateSnapshot } from 'state/app-state'import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'import {Button,@@ -26,7 +28,6 @@ import {Tooltip_Shadcn_,cn,} from 'ui'-import { useAppStateSnapshot } from 'state/app-state'interface DatabaseSelectorProps {variant?: 'regular' | 'connected-on-right' | 'connected-on-left' | 'connected-on-both'@@ -45,6 +46,7 @@ const DatabaseSelector = ({const router = useRouter()const { ref: projectRef } = useParams()const [open, setOpen] = useState(false)+ const [, setShowConnect] = useQueryState('showConnect', parseAsBoolean.withDefault(false))const appState = useAppStateSnapshot()const state = useDatabaseSelectorStateSnapshot()@@ -206,7 +208,7 @@ const DatabaseSelector = ({onClick={() => {setOpen(false)// [Joshen] This is used in the Connect UI which is available across all pages- appState.setShowConnectDialog(false)+ setShowConnect(null)}}className="w-full flex items-center gap-2">diff --git a/apps/studio/hooks/ui/useUrlState.ts b/apps/studio/hooks/ui/useUrlState.tsindex e6f739852d6..f687296b482 100644--- a/apps/studio/hooks/ui/useUrlState.ts+++ b/apps/studio/hooks/ui/useUrlState.ts@@ -5,6 +5,7 @@ export type UrlStateParams = {[k: string]: string | string[] | undefined}+/** @deprecated Use useQueryState from nuqs instead for URL state */export function useUrlState<ValueParams extends UrlStateParams>({replace = true,arrayKeys = [],diff --git a/apps/studio/state/app-state.ts b/apps/studio/state/app-state.tsindex d4ddad5b74a..40acb74d84f 100644--- a/apps/studio/state/app-state.ts+++ b/apps/studio/state/app-state.ts@@ -68,7 +68,6 @@ const getInitialState = () => {showGenerateSqlModal: false,navigationPanelOpen: false,navigationPanelJustClosed: false,- showConnectDialog: false,}}@@ -112,7 +111,6 @@ const getInitialState = () => {showGenerateSqlModal: false,navigationPanelOpen: false,navigationPanelJustClosed: false,- showConnectDialog: false,}}@@ -212,11 +210,6 @@ export const appState = proxy({...value,}},-- showConnectDialog: false,- setShowConnectDialog: (value: boolean) => {- appState.showConnectDialog = value- },})// Set up localStorage subscriptiondiff --git a/apps/studio/tests/pages/projects/reports/api-report.test.tsx b/apps/studio/tests/pages/projects/reports/api-report.test.tsxindex cc9feb0a89c..8514a511145 100644--- a/apps/studio/tests/pages/projects/reports/api-report.test.tsx+++ b/apps/studio/tests/pages/projects/reports/api-report.test.tsx@@ -1,5 +1,5 @@import { screen } from '@testing-library/react'-import { test } from 'vitest'+import { test, vi } from 'vitest'import { ApiReport } from 'pages/project/[ref]/reports/api-overview'import { render } from '../../../helpers'@@ -10,6 +10,18 @@ import { render } from '../../../helpers'// which for some reason none of them worked when I was trying to mock the data within the file itself// I'd be keen to see how we can do this better if anyone is more familiar to jest 🙏+beforeAll(() => {+ vi.mock('nuqs', async () => {+ let queryValue = 'example'+ return {+ useQueryState: () => [queryValue, (v: string) => (queryValue = v)],+ parseAsBoolean: {+ withDefault: () => true,+ },+ }+ })+})+test(`Render static elements`, async () => {render(<ApiReport dehydratedState={{}} />)await screen.findByText('Total Requests')diff --git a/packages/ui-patterns/Dialogs/TextConfirmModal.tsx b/packages/ui-patterns/Dialogs/TextConfirmModal.tsxindex 19b0cfee4f1..39dc7971598 100644--- a/packages/ui-patterns/Dialogs/TextConfirmModal.tsx+++ b/packages/ui-patterns/Dialogs/TextConfirmModal.tsx@@ -143,7 +143,11 @@ const TextConfirmModal = forwardRef<</>)}<Form_Shadcn_ {...form}>- <form onSubmit={form.handleSubmit(onSubmit)} className="px-5 flex flex-col gap-2 pt-3">+ <form+ autoComplete="off"+ onSubmit={form.handleSubmit(onSubmit)}+ className="px-5 flex flex-col gap-2 pt-3"+ ><FormField_Shadcn_control={form.control}name="confirmValue"@@ -154,7 +158,12 @@ const TextConfirmModal = forwardRef<confirm.</FormLabel_Shadcn_><FormControl_Shadcn_>- <Input_Shadcn_ placeholder={confirmPlaceholder} {...input} {...field} />+ <Input_Shadcn_+ autoComplete="off"+ placeholder={confirmPlaceholder}+ {...input}+ {...field}+ /></FormControl_Shadcn_><FormDescription_Shadcn_ {...description} /><FormMessage_Shadcn_ {...formMessage} />