The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Chore/branch management fixes 151123 (#18978)
Joshen Lim09a924c2e79f
diff --git a/studio/components/interfaces/Integrations/IntegrationConnection.tsx b/studio/components/interfaces/Integrations/IntegrationConnection.tsxindex b184fa6bf2c..5159c2ec90a 100644--- a/studio/components/interfaces/Integrations/IntegrationConnection.tsx+++ b/studio/components/interfaces/Integrations/IntegrationConnection.tsx@@ -25,11 +25,12 @@ import { IntegrationProjectConnection } from 'data/integrations/integrations.typimport { useStore } from 'hooks'interface IntegrationConnectionItemProps extends IntegrationConnectionProps {+ disabled?: booleanonDeleteConnection: (connection: IntegrationProjectConnection) => void | Promise<void>}const IntegrationConnectionItem = forwardRef<HTMLLIElement, IntegrationConnectionItemProps>(- ({ onDeleteConnection, ...props }, ref) => {+ ({ disabled, onDeleteConnection, ...props }, ref) => {const { ui } = useStore()const [isOpen, setIsOpen] = useState(false)const [dropdownVisible, setDropdownVisible] = useState(false)@@ -69,55 +70,61 @@ const IntegrationConnectionItem = forwardRef<HTMLLIElement, IntegrationConnectio<><IntegrationConnectionactions={- <DropdownMenu- open={dropdownVisible}- onOpenChange={() => setDropdownVisible(!dropdownVisible)}- modal={false}- >- <DropdownMenuTrigger>- <Button asChild iconRight={<IconChevronDown />} type="default">- <span>Manage</span>- </Button>- </DropdownMenuTrigger>- <DropdownMenuContent side="bottom" align="end">- {props.type === 'Vercel' && (- <>- {router.pathname !== projectIntegrationUrl && (- <DropdownMenuItem disabled={isSyncEnvLoading} asChild>- <Link- href={projectIntegrationUrl.replace(- '[ref]',- props.connection.supabase_project_ref- )}- >- View project configuration- </Link>- </DropdownMenuItem>- )}- <DropdownMenuItem- className="space-x-2"- onSelect={(event) => {- event.preventDefault()- onReSyncEnvVars()- }}- disabled={isSyncEnvLoading}- >- {isSyncEnvLoading ? (- <IconLoader className="animate-spin" size={14} />- ) : (- <IconRefreshCw size={14} />+ disabled ? (+ <Button asChild disabled iconRight={<IconChevronDown />} type="default">+ <span>Manage</span>+ </Button>+ ) : (+ <DropdownMenu+ open={dropdownVisible}+ onOpenChange={() => setDropdownVisible(!dropdownVisible)}+ modal={false}+ >+ <DropdownMenuTrigger>+ <Button asChild iconRight={<IconChevronDown />} type="default">+ <span>Manage</span>+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent side="bottom" align="end">+ {props.type === 'Vercel' && (+ <>+ {router.pathname !== projectIntegrationUrl && (+ <DropdownMenuItem disabled={isSyncEnvLoading} asChild>+ <Link+ href={projectIntegrationUrl.replace(+ '[ref]',+ props.connection.supabase_project_ref+ )}+ >+ View project configuration+ </Link>+ </DropdownMenuItem>)}- <p>Resync environment variables</p>- </DropdownMenuItem>- <DropdownMenuSeparator />- </>- )}- <DropdownMenuItem className="space-x-2" onSelect={() => setIsOpen(true)}>- <IconTrash size={14} />- <p>Delete connection</p>- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>+ <DropdownMenuItem+ className="space-x-2"+ onSelect={(event) => {+ event.preventDefault()+ onReSyncEnvVars()+ }}+ disabled={isSyncEnvLoading}+ >+ {isSyncEnvLoading ? (+ <IconLoader className="animate-spin" size={14} />+ ) : (+ <IconRefreshCw size={14} />+ )}+ <p>Resync environment variables</p>+ </DropdownMenuItem>+ <DropdownMenuSeparator />+ </>+ )}+ <DropdownMenuItem className="space-x-2" onSelect={() => setIsOpen(true)}>+ <IconTrash size={14} />+ <p>Delete connection</p>+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ )}{...props}/>diff --git a/studio/components/interfaces/Integrations/IntegrationPanels.tsx b/studio/components/interfaces/Integrations/IntegrationPanels.tsxindex a2d5331d23e..2bad1d4eeeb 100644--- a/studio/components/interfaces/Integrations/IntegrationPanels.tsx+++ b/studio/components/interfaces/Integrations/IntegrationPanels.tsx@@ -16,6 +16,7 @@ const ICON_SIZE = 14export interface IntegrationInstallationProps extends React.RefAttributes<HTMLLIElement> {title: stringintegration: Integration+ disabled?: boolean}type HandleIconType = Integration['integration']['name'] | 'Supabase'@@ -67,7 +68,7 @@ const Avatar = ({ src }: { src: string | undefined }) => {}const IntegrationInstallation = React.forwardRef<HTMLLIElement, IntegrationInstallationProps>(- ({ title, integration, ...props }, ref) => {+ ({ title, integration, disabled, ...props }, ref) => {const IntegrationIconBlock = () => {return (<div className="bg-black text-white w-8 h-8 rounded flex items-center justify-center">@@ -114,14 +115,18 @@ const IntegrationInstallation = React.forwardRef<HTMLLIElement, IntegrationInsta</div></div>- <Button asChild type="default" iconRight={<IconExternalLink />}>- <Link- href={getIntegrationConfigurationUrl(integration)}- target="_blank"- rel="noopener noreferrer"- >- Manage- </Link>+ <Button asChild disabled={disabled} type="default" iconRight={<IconExternalLink />}>+ {disabled ? (+ <p>Manage</p>+ ) : (+ <Link+ href={getIntegrationConfigurationUrl(integration)}+ target="_blank"+ rel="noopener noreferrer"+ >+ Manage+ </Link>+ )}</Button></li>)diff --git a/studio/components/interfaces/Settings/Addons/Addons.tsx b/studio/components/interfaces/Settings/Addons/Addons.tsxindex 5fcedbfe40c..f6d3a3eb83d 100644--- a/studio/components/interfaces/Settings/Addons/Addons.tsx+++ b/studio/components/interfaces/Settings/Addons/Addons.tsx@@ -106,10 +106,7 @@ const Addons = () => {<AlertDescription_Shadcn_>Updating addons are not available while you're on a preview branch. To manage youraddons, you may return to your{' '}- <Link- href={`/project/${parentProject.ref}/settings/general`}- className="text-brand-900"- >+ <Link href={`/project/${parentProject.ref}/settings/general`} className="text-brand">main branch</Link>.diff --git a/studio/components/interfaces/Settings/General/General.tsx b/studio/components/interfaces/Settings/General/General.tsxindex 0dd3647e4e2..e42ca693bff 100644--- a/studio/components/interfaces/Settings/General/General.tsx+++ b/studio/components/interfaces/Settings/General/General.tsx@@ -66,10 +66,7 @@ const General = () => {<AlertDescription_Shadcn_>Certain settings are not available while you're on a preview branch. To adjust yourproject settings, you may return to your{' '}- <Link- href={`/project/${parentProject.ref}/settings/general`}- className="text-brand-900"- >+ <Link href={`/project/${parentProject.ref}/settings/general`} className="text-brand">main branch</Link>.diff --git a/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx b/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsxindex c1203dd2809..515d7823970 100644--- a/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx+++ b/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx@@ -1,6 +1,6 @@+import { useParams } from 'common'import { useCallback } from 'react'-import { useParams } from 'common'import { IntegrationConnectionItem } from 'components/interfaces/Integrations/IntegrationConnection'import {IntegrationConnectionHeader,@@ -16,7 +16,7 @@ import {import { useIntegrationsGitHubInstalledConnectionDeleteMutation } from 'data/integrations/integrations-github-connection-delete-mutation'import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'import { IntegrationName, IntegrationProjectConnection } from 'data/integrations/integrations.types'-import { useSelectedOrganization, useStore } from 'hooks'+import { useSelectedOrganization, useSelectedProject, useStore } from 'hooks'import { pluralize } from 'lib/helpers'import { IntegrationImageHandler } from '../IntegrationsSettings'import GitHubIntegrationConnectionForm from './GitHubIntegrationConnectionForm'@@ -39,10 +39,13 @@ These connections will be part of a GitHub workflow that is currently in developconst GitHubSection = () => {const { ui } = useStore()+ const project = useSelectedProject()const org = useSelectedOrganization()const { data } = useOrgIntegrationsQuery({ orgSlug: org?.slug })const { ref: projectRef } = useParams()+ const isBranch = project?.parent_project_ref !== undefined+const githubIntegrations = data?.filter((integration) => integration.integration.name === 'GitHub')@@ -81,24 +84,22 @@ const GitHubSection = () => {{githubIntegrations &&githubIntegrations.length > 0 &&githubIntegrations.map((integration, i) => {- const ConnectionHeaderTitle = `${integration.connections.length} project ${pluralize(- integration.connections.length,- 'connection'- )} `-const connections = integration.connections.filter((connection) =>- projectRef ? connection.supabase_project_ref === projectRef : true+ isBranch+ ? connection.supabase_project_ref === project.parent_project_ref+ : connection.supabase_project_ref === projectRef)return (<div key={integration.id}>- <IntegrationInstallation title={'GitHub'} integration={integration} />+ <IntegrationInstallation+ title={'GitHub'}+ integration={integration}+ disabled={isBranch}+ />{connections.length > 0 ? (<>- <IntegrationConnectionHeader- // title={ConnectionHeaderTitle}- // markdown={`Repository connections for GitHub`}- />+ <IntegrationConnectionHeader /><ul className="flex flex-col">{connections.map((connection) => (<div@@ -107,6 +108,7 @@ const GitHubSection = () => {><IntegrationConnectionItemshowNode={false}+ disabled={isBranch}key={connection.id}connection={connection}type={'GitHub' as IntegrationName}diff --git a/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx b/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsxindex 53154a6206b..022286c234c 100644--- a/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx+++ b/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx@@ -1,6 +1,10 @@+import Link from 'next/link'+import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, IconAlertCircle } from 'ui'+import SidePanelGitHubRepoLinker from 'components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker'import SidePanelVercelProjectLinker from 'components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker'-import { ScaffoldDivider } from 'components/layouts/Scaffold'+import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'+import { useProjectByRef, useSelectedProject } from 'hooks'import { BASE_PATH } from 'lib/constants'import GitHubSection from './GithubIntegration/GithubSection'import VercelSection from './VercelIntegration/VercelSection'@@ -16,8 +20,29 @@ export const IntegrationImageHandler = ({ title }: { title: 'vercel' | 'github'}const IntegrationSettings = () => {+ const project = useSelectedProject()+ const parentProject = useProjectByRef(project?.parent_project_ref)+ const isBranch = project?.parent_project_ref !== undefined+return (<>+ {isBranch && (+ <ScaffoldContainer>+ <Alert_Shadcn_ variant="default" className="mt-6">+ <IconAlertCircle strokeWidth={2} />+ <AlertTitle_Shadcn_>+ You are currently on a preview branch of your project+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ To adjust your project's integration settings, you may return to your{' '}+ <Link href={`/project/${parentProject?.ref}/settings/general`} className="text-brand">+ main branch+ </Link>+ .+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ </ScaffoldContainer>+ )}<GitHubSection /><ScaffoldDivider /><VercelSection isProjectScoped={true} />diff --git a/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx b/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsxindex ddbbe6af5d1..dfc5c904c6d 100644--- a/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx+++ b/studio/components/interfaces/Settings/Integrations/VercelIntegration/VercelSection.tsx@@ -34,6 +34,8 @@ const VercelSection = ({ isProjectScoped }: { isProjectScoped: boolean }) => {const { data } = useOrgIntegrationsQuery({ orgSlug: org?.slug })const sidePanelsStateSnapshot = useSidePanelsStateSnapshot()+ const isBranch = project?.parent_project_ref !== undefined+const { mutate: deleteVercelConnection } = useIntegrationsVercelInstalledConnectionDeleteMutation({onSuccess: () => {@@ -195,10 +197,14 @@ You can change the scope of the access for Supabase by configuring</div>) : (<div>- <Button asChild type="default" iconRight={<IconExternalLink />}>- <Link href={integrationUrl} target="_blank">- Install Vercel Integration- </Link>+ <Button asChild type="default" disabled={isBranch} iconRight={<IconExternalLink />}>+ {isBranch ? (+ <p>Install Vercel Integration</p>+ ) : (+ <Link href={integrationUrl} target="_blank" rel="noreferrer">+ Install Vercel Integration+ </Link>+ )}</Button></div>)}diff --git a/studio/components/layouts/StorageLayout/StorageMenu.tsx b/studio/components/layouts/StorageLayout/StorageMenu.tsxindex 3ef5e6bf05a..1b2b39cb9e5 100644--- a/studio/components/layouts/StorageLayout/StorageMenu.tsx+++ b/studio/components/layouts/StorageLayout/StorageMenu.tsx@@ -1,24 +1,35 @@import * as Tooltip from '@radix-ui/react-tooltip'import { PermissionAction } from '@supabase/shared-types/out/constants'+import { useParams } from 'common'import { observer } from 'mobx-react-lite'import Link from 'next/link'import { useRouter } from 'next/router'import { useState } from 'react'-import { Alert, Button, IconEdit, Menu } from 'ui'+import {+ Alert,+ AlertDescription_Shadcn_,+ AlertTitle_Shadcn_,+ Alert_Shadcn_,+ Button,+ IconEdit,+ Menu,+} from 'ui'-import { useParams } from 'common/hooks'import CreateBucketModal from 'components/interfaces/Storage/CreateBucketModal'import EditBucketModal from 'components/interfaces/Storage/EditBucketModal'import { StorageBucket } from 'components/interfaces/Storage/Storage.types'import { DeleteBucketModal } from 'components/to-be-cleaned/Storage'import ShimmeringLoader from 'components/ui/ShimmeringLoader'import { useBucketsQuery } from 'data/storage/buckets-query'-import { useCheckPermissions } from 'hooks'+import { useCheckPermissions, useSelectedProject } from 'hooks'import BucketRow from './BucketRow'const StorageMenu = () => {const router = useRouter()const { ref, bucketId } = useParams()+ const projectDetails = useSelectedProject()+ const isBranch = projectDetails?.parent_project_ref !== undefined+const [showCreateBucketModal, setShowCreateBucketModal] = useState(false)const [selectedBucketToEdit, setSelectedBucketToEdit] = useState<StorageBucket>()const [selectedBucketToDelete, setSelectedBucketToDelete] = useState<StorageBucket>()@@ -31,8 +42,9 @@ const StorageMenu = () => {| 'usage'| 'logs'- const { data, isLoading, isError, isSuccess } = useBucketsQuery({ projectRef: ref })+ const { data, error, isLoading, isError, isSuccess } = useBucketsQuery({ projectRef: ref })const buckets = data ?? []+ const tempNotSupported = error?.message.includes('Tenant config') && isBranchreturn (<>@@ -75,51 +87,58 @@ const StorageMenu = () => {</Tooltip.Root></div><div className="space-y-6">- <div className="">- <div>- <Menu.Group title="All buckets" />+ <div>+ <Menu.Group title="All buckets" />- {isLoading && (- <div className="space-y-2 mx-2">- <ShimmeringLoader className="!py-2.5" />- <ShimmeringLoader className="!py-2.5" />- <ShimmeringLoader className="!py-2.5" />- </div>- )}+ {isLoading && (+ <div className="space-y-2 mx-2">+ <ShimmeringLoader className="!py-2.5" />+ <ShimmeringLoader className="!py-2.5" />+ <ShimmeringLoader className="!py-2.5" />+ </div>+ )}- {isError && (- <div className="px-2">- <Alert variant="warning" title="Failed to fetch buckets">- Please refresh to try again.- </Alert>- </div>- )}+ {isError && (+ <div className="px-2">+ <Alert_Shadcn_ variant={tempNotSupported ? 'default' : 'warning'}>+ <AlertTitle_Shadcn_ className="text-xs tracking-normal">+ {tempNotSupported+ ? 'Storage is not available on preview branches for now'+ : 'Failed to fetch buckets'}+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_ className="text-xs">+ {tempNotSupported+ ? "We're actively looking into making this available on preview branches"+ : 'Please refresh to try again'}+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ </div>+ )}- {isSuccess && (- <>- {buckets.length === 0 && (- <div className="px-2">- <Alert title="No buckets available">- Buckets that you create will appear here- </Alert>- </div>- )}- {buckets.map((bucket, idx: number) => {- const isSelected = bucketId === bucket.id- return (- <BucketRow- key={`${idx}_${bucket.id}`}- bucket={bucket}- projectRef={ref}- isSelected={isSelected}- onSelectDeleteBucket={() => setSelectedBucketToDelete(bucket)}- onSelectEditBucket={() => setSelectedBucketToEdit(bucket)}- />- )- })}- </>- )}- </div>+ {isSuccess && (+ <>+ {buckets.length === 0 && (+ <div className="px-2">+ <Alert title="No buckets available">+ Buckets that you create will appear here+ </Alert>+ </div>+ )}+ {buckets.map((bucket, idx: number) => {+ const isSelected = bucketId === bucket.id+ return (+ <BucketRow+ key={`${idx}_${bucket.id}`}+ bucket={bucket}+ projectRef={ref}+ isSelected={isSelected}+ onSelectDeleteBucket={() => setSelectedBucketToDelete(bucket)}+ onSelectEditBucket={() => setSelectedBucketToEdit(bucket)}+ />+ )+ })}+ </>+ )}</div><div className="h-px w-full bg-border"></div><div className="">diff --git a/studio/data/storage/buckets-query.ts b/studio/data/storage/buckets-query.tsindex 793254c8340..762df8b94bf 100644--- a/studio/data/storage/buckets-query.ts+++ b/studio/data/storage/buckets-query.ts@@ -1,8 +1,9 @@import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'lib/common/fetch'+import { get } from 'data/fetchers'import { API_URL } from 'lib/constants'import { useCallback } from 'react'import { storageKeys } from './keys'+import { ResponseError } from 'types'export type BucketsVariables = { projectRef?: string }@@ -20,13 +21,17 @@ export type Bucket = {export async function getBuckets({ projectRef }: BucketsVariables, signal?: AbortSignal) {if (!projectRef) throw new Error('projectRef is required')- const response = await get(`${API_URL}/storage/${projectRef}/buckets`, { signal })- if (response.error) throw response.error- return response as Bucket[]+ const { data, error } = await get('/platform/storage/{ref}/buckets', {+ params: { path: { ref: projectRef } },+ signal,+ })++ if (error) throw error+ return data as Bucket[]}export type BucketsData = Awaited<ReturnType<typeof getBuckets>>-export type BucketsError = unknown+export type BucketsError = ResponseErrorexport const useBucketsQuery = <TData = BucketsData>({ projectRef }: BucketsVariables,@@ -35,17 +40,24 @@ export const useBucketsQuery = <TData = BucketsData>(useQuery<BucketsData, BucketsError, TData>(storageKeys.buckets(projectRef),({ signal }) => getBuckets({ projectRef }, signal),- { enabled: enabled && typeof projectRef !== 'undefined', ...options }- )--export const useBucketsPrefetch = ({ projectRef }: BucketsVariables) => {- const client = useQueryClient()-- return useCallback(() => {- if (projectRef) {- client.prefetchQuery(storageKeys.buckets(projectRef), ({ signal }) =>- getBuckets({ projectRef }, signal)- )+ {+ enabled: enabled && typeof projectRef !== 'undefined',+ ...options,+ retry: (failureCount, error) => {+ if (+ typeof error === 'object' &&+ error !== null &&+ error.message.startsWith('Tenant config') &&+ error.message.endsWith('not found')+ ) {+ return false+ }++ if (failureCount < 3) {+ return true+ }++ return false+ },}- }, [projectRef])-}+ )