The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Vercel install layout (#47550)
Saxon Fletcher09ea558d54be
diff --git a/apps/studio/components/layouts/InterstitialLayout.tsx b/apps/studio/components/layouts/InterstitialLayout.tsxindex 9d996d216b4..b32393b8b8d 100644--- a/apps/studio/components/layouts/InterstitialLayout.tsx+++ b/apps/studio/components/layouts/InterstitialLayout.tsx@@ -128,10 +128,20 @@ export const LogoPair = ({ left, right }: { left: ReactNode; right: ReactNode })</div>)-/** Partner logo rendered edge-to-edge inside a LogoBox. */-export const PartnerLogo = ({ src, alt }: { src: string; alt: string }) => (- <LogoBox>- <img alt={alt} src={src} className="size-full object-cover" />+/** Partner logo rendered edge-to-edge inside a LogoBox by default. */+export const PartnerLogo = ({+ src,+ alt,+ className,+ imageClassName,+}: {+ src: string+ alt: string+ className?: string+ imageClassName?: string+}) => (+ <LogoBox className={className}>+ <img alt={alt} src={src} className={cn('size-full object-cover', imageClassName)} /></LogoBox>)diff --git a/apps/studio/lib/integrations/vercel-install.utils.ts b/apps/studio/lib/integrations/vercel-install.utils.tsnew file mode 100644index 00000000000..cdc30c48cd3--- /dev/null+++ b/apps/studio/lib/integrations/vercel-install.utils.ts@@ -0,0 +1,70 @@+export function getErrorMessage(error: unknown): string | undefined {+ if (error instanceof Error) return error.message+ if (+ typeof error === 'object' &&+ error !== null &&+ 'message' in error &&+ typeof (error as { message: unknown }).message === 'string'+ ) {+ return (error as { message: string }).message+ }+ return undefined+}++export type VercelInstallSource = 'deploy-button' | 'marketplace' | 'external'++export function getVercelInstallSource(+ source: string | undefined+): VercelInstallSource | undefined {+ switch (source) {+ case 'deploy-button':+ case 'marketplace':+ case 'external':+ return source+ default:+ return undefined+ }+}++type BuildVercelInstallRouteQueryArgs = {+ source?: VercelInstallSource+ organizationSlug?: string+ configurationId?: string+ currentProjectId?: string+ externalId?: string+ next?: string+}++function removeUndefinedValues(query: Record<string, string | undefined>) {+ return Object.fromEntries(+ Object.entries(query).filter((entry): entry is [string, string] => entry[1] !== undefined)+ )+}++export function buildVercelInstallRouteQuery({+ source,+ organizationSlug,+ configurationId,+ currentProjectId,+ externalId,+ next,+}: BuildVercelInstallRouteQueryArgs) {+ switch (source) {+ case 'deploy-button':+ return removeUndefinedValues({+ organizationSlug,+ currentProjectId,+ externalId,+ next,+ })+ case 'marketplace':+ case 'external':+ return removeUndefinedValues({+ organizationSlug,+ configurationId,+ next,+ })+ default:+ return removeUndefinedValues({ organizationSlug })+ }+}diff --git a/apps/studio/pages/integrations/vercel/install.tsx b/apps/studio/pages/integrations/vercel/install.tsxindex ebc5f82559a..bc01578a213 100644--- a/apps/studio/pages/integrations/vercel/install.tsx+++ b/apps/studio/pages/integrations/vercel/install.tsx@@ -1,22 +1,51 @@import { useParams } from 'common'-import { AlertTriangle, Info } from 'lucide-react'+import Head from 'next/head'import Link from 'next/link'import { useRouter } from 'next/router'import { useEffect, useMemo, useState } from 'react'import { toast } from 'sonner'-import { Alert, AlertDescription, AlertTitle, Button } from 'ui'+import {+ Badge,+ Button,+ Card,+ CardContent,+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from 'ui'+import { Admonition } from 'ui-patterns/admonition'+import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'-import OrganizationPicker from '@/components/interfaces/Integrations/Vercel/OrganizationPicker'-import { Markdown } from '@/components/interfaces/Markdown'import { getHasInstalledObject } from '@/components/layouts/IntegrationsLayout/Integrations.utils'-import VercelIntegrationWindowLayout from '@/components/layouts/IntegrationsLayout/VercelIntegrationWindowLayout'-import { ScaffoldColumn, ScaffoldContainer } from '@/components/layouts/Scaffold'+import {+ InterstitialAccountRow,+ InterstitialLayout,+ LogoPair,+ PartnerLogo,+ SupabaseLogo,+} from '@/components/layouts/InterstitialLayout'import { useIntegrationsQuery } from '@/data/integrations/integrations-query'import { useVercelIntegrationCreateMutation } from '@/data/integrations/vercel-integration-create-mutation'import { useOrganizationsQuery } from '@/data/organizations/organizations-query'+import { withAuth } from '@/hooks/misc/withAuth'+import { BASE_PATH } from '@/lib/constants'+import {+ buildVercelInstallRouteQuery,+ getErrorMessage,+ getVercelInstallSource,+} from '@/lib/integrations/vercel-install.utils'+import { buildStudioPageTitle } from '@/lib/page-title'+import { useProfileNameAndPicture } from '@/lib/profile'import { useIntegrationInstallationSnapshot } from '@/state/integration-installation'import type { NextPageWithLayout, Organization } from '@/types'+const PAGE_TITLE = buildStudioPageTitle({+ section: 'Install Vercel Integration',+ brand: 'Supabase',+})+/*** Variations of the Vercel integration flow.* They require different UI and logic.@@ -29,22 +58,31 @@ export type VercelIntegrationFlow = 'deploy-button' | 'marketing'const VercelIntegration: NextPageWithLayout = () => {const router = useRouter()- const { code, configurationId, teamId, source } = useParams()+ const { code, configurationId, currentProjectId, externalId, next, teamId, source } = useParams()const [selectedOrg, setSelectedOrg] = useState<Organization | null>(null)+ const { username, primaryEmail, avatarUrl } = useProfileNameAndPicture()const snapshot = useIntegrationInstallationSnapshot()+ const displayName = primaryEmail ?? username ?? ''/*** Fetch the list of organization based integration installations for Vercel.** Array of integrations installed on all*/- const { data: integrationData } = useIntegrationsQuery()+ const {+ data: integrationData,+ isPending: isLoadingIntegrationsQuery,+ isError: isIntegrationsError,+ error: integrationsError,+ } = useIntegrationsQuery()const {data: organizationsData,isPending: isLoadingOrganizationsQuery,isSuccess: isOrganizationsDataSuccess,+ isError: isOrganizationsError,+ error: organizationsError,} = useOrganizationsQuery()useEffect(() => {@@ -53,10 +91,9 @@ const VercelIntegration: NextPageWithLayout = () => {if (firstOrg && selectedOrg === null) {setSelectedOrg(firstOrg)- router.query.organizationSlug = firstOrg.slug}}- }, [organizationsData, integrationData])+ }, [organizationsData, integrationData, selectedOrg])/*** Organizations with extra `installationInstalled` attribute@@ -87,12 +124,21 @@ const VercelIntegration: NextPageWithLayout = () => {*/function handleRouteChange() {const orgSlug = selectedOrg?.slug+ const vercelInstallSource = getVercelInstallSource(source)+ const query = buildVercelInstallRouteQuery({+ source: vercelInstallSource,+ organizationSlug: orgSlug,+ configurationId,+ currentProjectId,+ externalId,+ next,+ })- switch (source) {+ switch (vercelInstallSource) {case 'deploy-button': {router.push({pathname: `/integrations/vercel/${orgSlug}/deploy-button/new-project`,- query: router.query,+ query,})break}@@ -100,7 +146,7 @@ const VercelIntegration: NextPageWithLayout = () => {case 'external': {router.push({pathname: `/integrations/vercel/${orgSlug}/marketplace/choose-project`,- query: router.query,+ query,})break}@@ -121,6 +167,7 @@ const VercelIntegration: NextPageWithLayout = () => {snapshot.setLoading(false)},onError(error) {+ snapshot.setLoading(false)toast.error(`Creating Vercel integration failed: ${error.message}`)},})@@ -163,7 +210,10 @@ const VercelIntegration: NextPageWithLayout = () => {}}- const dataLoading = isLoadingVercelIntegrationCreateMutation || isLoadingOrganizationsQuery+ const dataLoading =+ isLoadingVercelIntegrationCreateMutation ||+ isLoadingOrganizationsQuery ||+ isLoadingIntegrationsQueryconst noOrganizations = useMemo(() => {return isOrganizationsDataSuccess && organizationsData?.length === 0 ? true : false@@ -173,87 +223,204 @@ const VercelIntegration: NextPageWithLayout = () => {return selectedOrg && installed[selectedOrg.slug] && source === 'marketplace' && !dataLoading? true: false- }, [installed, selectedOrg, source, dataLoading])+ }, [dataLoading, installed, selectedOrg, source])++ const missingParams = [+ !code ? 'code' : undefined,+ !configurationId ? 'configurationId' : undefined,+ !source ? 'source' : undefined,+ ].filter(Boolean) as string[]++ const isError = isOrganizationsError || isIntegrationsError+ const errorMessage = getErrorMessage(organizationsError) ?? getErrorMessage(integrationsError)+ const showLoadingState = isLoadingOrganizationsQuery || isLoadingIntegrationsQueryconst disableInstallationForm =- (isLoadingVercelIntegrationCreateMutation && !dataLoading) ||+ dataLoading ||// disables installation button if integration is already installed and it is Marketplace flowalreadyInstalled ||- noOrganizations-- const isLoading = useMemo(() => {- return isLoadingVercelIntegrationCreateMutation || isLoadingOrganizationsQuery- }, [isLoadingVercelIntegrationCreateMutation, isLoadingOrganizationsQuery])+ noOrganizations ||+ !selectedOrg ||+ missingParams.length > 0 ||+ isErrorreturn (<>- <ScaffoldContainer className="flex flex-col gap-6 grow py-8">- <ScaffoldColumn className="mx-auto w-full max-w-md">- <h2>Choose organization</h2>- <>- <Markdown content={`Choose the Supabase organization you wish to install in`} />- <OrganizationPicker- integrationName="Vercel"- selectedOrg={selectedOrg}- disabled={noOrganizations || isLoading}- onSelectedOrgChange={(org) => {- setSelectedOrg(org)- router.query.organizationSlug = org.slug- }}- configurationId={configurationId}- />- {alreadyInstalled && (- <Alert variant="warning">- <AlertTriangle className="h-4 w-4" strokeWidth={2} />- <AlertTitle>Vercel Integration is already installed.</AlertTitle>- <AlertDescription>- You will need to choose another organization to install the integration.- </AlertDescription>- </Alert>- )}- {noOrganizations && (- <Alert variant="warning">- <AlertTriangle className="h-4 w-4" strokeWidth={2} />- <AlertTitle>No Supabase Organizations to install Integration.</AlertTitle>- <AlertDescription className="prose">- You will need to create a Supabase Organization before you can install the Vercel- Integration. You can create a new organization{' '}- <Link href="https://supabase.com/dashboard/new" target="_blank">- here- </Link>- .- </AlertDescription>- </Alert>- )}- <div className="flex flex-row w-full justify-end">- <Button- size="medium"- className="self-end"- disabled={disableInstallationForm || isLoadingVercelIntegrationCreateMutation}- loading={isLoadingVercelIntegrationCreateMutation}- onClick={onInstall}- >- Install integration- </Button>+ <Head>+ <title>{PAGE_TITLE}</title>+ </Head>++ <InterstitialLayout+ logo={+ <LogoPair+ left={+ <PartnerLogo+ src={`${BASE_PATH}/img/icons/vercel-icon.svg`}+ alt="Vercel"+ className="bg-surface-75"+ imageClassName="size-7 object-contain dark:invert"+ />+ }+ right={<SupabaseLogo />}+ />+ }+ title="Install Vercel integration"+ description="Choose an organization to connect to Vercel"+ >+ <div className="px-6 pb-6">+ {showLoadingState ? (+ <InstallationLoadingState />+ ) : isError ? (+ <InstallationErrorState errorMessage={errorMessage} />+ ) : (+ <div className="flex flex-col gap-5">+ <InterstitialAccountRow avatarUrl={avatarUrl} displayName={displayName} />++ <OrganizationSelect+ organizations={organizationsData ?? []}+ selectedOrg={selectedOrg}+ disabled={noOrganizations || dataLoading}+ installed={installed}+ onSelectedOrgChange={setSelectedOrg}+ />++ {missingParams.length > 0 && (+ <Admonition+ type="warning"+ title="Missing Vercel installation details"+ description={`Retry from Vercel. The installation URL is missing: ${missingParams.join(+ ', '+ )}.`}+ />+ )}++ {alreadyInstalled && (+ <Admonition+ type="warning"+ title="Vercel integration is already installed"+ description="Choose another organization to install this marketplace integration."+ />+ )}++ {noOrganizations && (+ <Admonition+ type="warning"+ title="No Supabase organizations found"+ description={+ <>+ Create a Supabase organization before installing the Vercel integration. You+ can create a new organization{' '}+ <Link href="https://supabase.com/dashboard/new" target="_blank">+ here+ </Link>+ .+ </>+ }+ />+ )}++ <div className="flex flex-col gap-2">+ <Button+ block+ variant="primary"+ disabled={disableInstallationForm}+ loading={dataLoading}+ onClick={onInstall}+ >+ Install integration+ </Button>+ </div></div>- </>- </ScaffoldColumn>- </ScaffoldContainer>- <ScaffoldContainer className="flex flex-col gap-6 py-3">- <Alert variant="default">- <Info className="h-4 w-4" strokeWidth={2} />- <AlertTitle>You can uninstall this Integration at any time.</AlertTitle>- <AlertDescription>- Remove this integration at any time from Vercel or the Supabase dashboard.- </AlertDescription>- </Alert>- </ScaffoldContainer>+ )}+ </div>+ </InterstitialLayout></>)}-VercelIntegration.getLayout = (page) => (- <VercelIntegrationWindowLayout>{page}</VercelIntegrationWindowLayout>+const InstallationLoadingState = () => (+ <div className="flex flex-col gap-5">+ <Card className="shadow-none">+ <CardContent className="flex items-center gap-3 border-none px-4 py-3">+ <ShimmeringLoader className="size-8 flex-shrink-0 rounded-full py-0" />+ <div className="min-w-0 flex-1 space-y-2">+ <ShimmeringLoader className="h-3 w-20 py-0" />+ <ShimmeringLoader className="h-4 w-40 max-w-full py-0" />+ </div>+ </CardContent>+ </Card>+ <section className="space-y-2" aria-label="Organization loading">+ <ShimmeringLoader className="h-3 w-24 py-0" />+ <ShimmeringLoader className="h-[34px] w-full rounded-md py-0" />+ </section>+ <ShimmeringLoader className="h-10 w-full rounded-md py-0" />+ </div>+)++const InstallationErrorState = ({ errorMessage }: { errorMessage?: string }) => (+ <div className="flex flex-col gap-3">+ <Admonition+ type="warning"+ title="Unable to load installation"+ description={+ <>+ Retry the installation request from Vercel.+ {errorMessage && (+ <span className="mt-1 block text-foreground-lighter">Error: {errorMessage}</span>+ )}+ </>+ }+ />+ <Button variant="default" block asChild>+ <Link href="/">Back to dashboard</Link>+ </Button>+ </div>)-export default VercelIntegration+interface OrganizationSelectProps {+ organizations: Organization[]+ selectedOrg: Organization | null+ disabled?: boolean+ installed: Record<string, boolean>+ onSelectedOrgChange: (organization: Organization) => void+}++function OrganizationSelect({+ organizations,+ selectedOrg,+ disabled,+ installed,+ onSelectedOrgChange,+}: OrganizationSelectProps) {+ return (+ <section className="space-y-2" aria-label="Organization">+ <p className="text-xs font-medium uppercase tracking-wider text-foreground-light">+ Organization+ </p>+ <Select+ value={selectedOrg?.slug ?? ''}+ disabled={disabled}+ onValueChange={(slug) => {+ const org = organizations.find((org) => org.slug === slug)+ if (org) onSelectedOrgChange(org)+ }}+ >+ <SelectTrigger size="small" aria-label="Supabase organization to install Vercel into">+ <SelectValue placeholder="Choose an organization" />+ </SelectTrigger>+ <SelectContent>+ {organizations.map((org) => (+ <SelectItem key={org.slug} value={org.slug} className="text-xs">+ <div className="flex items-center gap-2">+ <span className="truncate">{org.name}</span>+ {installed[org.slug] && <Badge className="flex-none!">Installed</Badge>}+ </div>+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </section>+ )+}++export default withAuth(VercelIntegration)diff --git a/apps/studio/tests/pages/integrations/vercel/install.utils.test.ts b/apps/studio/tests/pages/integrations/vercel/install.utils.test.tsnew file mode 100644index 00000000000..3c88df74c09--- /dev/null+++ b/apps/studio/tests/pages/integrations/vercel/install.utils.test.ts@@ -0,0 +1,101 @@+import { describe, expect, test } from 'vitest'++import {+ buildVercelInstallRouteQuery,+ getErrorMessage,+ getVercelInstallSource,+} from '@/lib/integrations/vercel-install.utils'++describe('getErrorMessage', () => {+ test('returns the message from an Error instance', () => {+ expect(getErrorMessage(new Error('Something went wrong'))).toBe('Something went wrong')+ })++ test('returns the message from an error-like object', () => {+ expect(getErrorMessage({ message: 'Request failed' })).toBe('Request failed')+ })++ test('returns undefined for non-string object messages', () => {+ expect(getErrorMessage({ message: 404 })).toBeUndefined()+ })++ test('returns undefined for primitive and empty inputs', () => {+ expect(getErrorMessage('Request failed')).toBeUndefined()+ expect(getErrorMessage(null)).toBeUndefined()+ expect(getErrorMessage(undefined)).toBeUndefined()+ })+})++describe('buildVercelInstallRouteQuery', () => {+ test('only keeps deploy-button destination params', () => {+ expect(+ buildVercelInstallRouteQuery({+ source: 'deploy-button',+ organizationSlug: 'acme',+ currentProjectId: 'vercel-project',+ externalId: 'github-repo',+ next: 'https://vercel.com/callback',+ configurationId: 'configuration-id',+ })+ ).toStrictEqual({+ organizationSlug: 'acme',+ currentProjectId: 'vercel-project',+ externalId: 'github-repo',+ next: 'https://vercel.com/callback',+ })+ })++ test('only keeps marketplace destination params', () => {+ expect(+ buildVercelInstallRouteQuery({+ source: 'marketplace',+ organizationSlug: 'acme',+ configurationId: 'configuration-id',+ currentProjectId: 'vercel-project',+ externalId: 'github-repo',+ next: 'https://vercel.com/callback',+ })+ ).toStrictEqual({+ organizationSlug: 'acme',+ configurationId: 'configuration-id',+ next: 'https://vercel.com/callback',+ })+ })++ test('removes undefined params', () => {+ expect(+ buildVercelInstallRouteQuery({+ source: 'external',+ organizationSlug: 'acme',+ configurationId: undefined,+ next: undefined,+ })+ ).toStrictEqual({ organizationSlug: 'acme' })+ })++ test('only keeps organizationSlug when source is undefined', () => {+ expect(+ buildVercelInstallRouteQuery({+ source: undefined,+ organizationSlug: 'acme',+ configurationId: 'configuration-id',+ currentProjectId: 'vercel-project',+ externalId: 'github-repo',+ next: 'https://vercel.com/callback',+ })+ ).toStrictEqual({ organizationSlug: 'acme' })+ })+})++describe('getVercelInstallSource', () => {+ test('returns supported Vercel install sources', () => {+ expect(getVercelInstallSource('deploy-button')).toBe('deploy-button')+ expect(getVercelInstallSource('marketplace')).toBe('marketplace')+ expect(getVercelInstallSource('external')).toBe('external')+ })++ test('returns undefined for unsupported sources', () => {+ expect(getVercelInstallSource('deploybutton')).toBeUndefined()+ expect(getVercelInstallSource(undefined)).toBeUndefined()+ })+})