The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Joshen/fe 2899 migrate wrappers integration to new UI (#44349)
Joshen Limc9d7d86f9475
diff --git a/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTabV2/InstallIntegrationSheet.tsx b/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTabV2/InstallIntegrationSheet.tsxindex 407adcc98b2..3569954bcbf 100644--- a/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTabV2/InstallIntegrationSheet.tsx+++ b/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTabV2/InstallIntegrationSheet.tsx@@ -108,7 +108,7 @@ export const InstallIntegrationSheet = ({ integration }: InstallIntegrationSheetconst { mutateAsync: enableExtension } = useDatabaseExtensionEnableMutation({ onError: () => {} })const enableExtensionsSQL = getEnableExtensionsSQL({- extensions: requiredExtensions,+ extensions: requiredExtensions.filter((ext) => !ext.installed_version),extensionsSchema,})const installationSQLContent = installationSql ?? enableExtensionsSQL@@ -156,26 +156,28 @@ export const InstallIntegrationSheet = ({ integration }: InstallIntegrationSheetconst { ref: projectRef, connectionString } = projectconst results = await Promise.allSettled(- requiredExtensions.map((ext) => {- const { name, default_version: version } = ext- const createSchema = extensionsSchema[name].schema === 'custom'- const schema =- name === 'pg_cron'- ? 'pg_catalog'- : createSchema- ? (extensionsSchema[name].value as string)- : extensionsSchema[name].schema-- return enableExtension({- projectRef,- connectionString,- schema,- name,- version,- cascade: true,- createSchema,+ requiredExtensions+ .filter((ext) => !ext.installed_version)+ .map((ext) => {+ const { name, default_version: version } = ext+ const createSchema = extensionsSchema[name].schema === 'custom'+ const schema =+ name === 'pg_cron'+ ? 'pg_catalog'+ : createSchema+ ? (extensionsSchema[name].value as string)+ : extensionsSchema[name].schema++ return enableExtension({+ projectRef,+ connectionString,+ schema,+ name,+ version,+ cascade: true,+ createSchema,+ })})- }))const failure = results.find((r) => r.status === 'rejected')@@ -240,11 +242,11 @@ export const InstallIntegrationSheet = ({ integration }: InstallIntegrationSheet)}</TabsList_Shadcn_>- <TabsContent_Shadcn_ value="extensions" className="mt-0 px-4">+ <TabsContent_Shadcn_ value="extensions" className="mt-0 divide-y">{requiredExtensionNames.map((extName) => {const ext = extensions.find((x) => x.name === extName)return (- <div key={extName} className="py-3 flex items-center justify-between">+ <div key={extName} className="py-3 px-4 flex items-center justify-between"><code className="text-xs">{extName}</code>{!ext ? (<Badge>Unavailable</Badge>@@ -290,6 +292,7 @@ export const InstallIntegrationSheet = ({ integration }: InstallIntegrationSheetSelect which schemas to install the database extensions under</p>{requiredExtensionNames.map((extName) => {+ const ext = extensions.find((x) => x.name === extName)const extMeta = extensionsSchema[extName as keyof typeof extensionsSchema]const { schema, value } = extMetaconst recommendedSchema = extensionsWithRecommendedSchemas[extName]@@ -300,8 +303,23 @@ export const InstallIntegrationSheet = ({ integration }: InstallIntegrationSheetisReactForm={false}layout="horizontal"label={extName}+ description={+ !!recommendedSchema ? (+ <>+ Use the{' '}+ <code className="text-code-inline">{recommendedSchema}</code>{' '}+ schema for full compatibility with related features+ </>+ ) : !!ext?.installed_version ? (+ <>+ Installed in{' '}+ <code className="text-code-inline">{ext.schema}</code> schema+ </>+ ) : undefined+ }><Select_Shadcn_+ disabled={!!ext?.installed_version}value={schema}onValueChange={(schema) =>setExtensionsSchema((prev) => ({diff --git a/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx b/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsxindex b184d0beb6d..bce8cbbe422 100644--- a/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx+++ b/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx@@ -192,7 +192,7 @@ const SUPABASE_INTEGRATIONS: Array<IntegrationDefinition> = [<Vault className={cn('inset-0 p-2 text-black w-full h-full', className)} {...props} />),description: 'Application level encryption for your project',- docsUrl: DOCS_URL,+ docsUrl: `${DOCS_URL}/guides/database/vault`,author: authorSupabase,navigation: [{@@ -236,7 +236,7 @@ const SUPABASE_INTEGRATIONS: Array<IntegrationDefinition> = [),description:'Send real-time data from your database to another system when a table event occurs',- docsUrl: DOCS_URL,+ docsUrl: `${DOCS_URL}/guides/database/webhooks`,author: authorSupabase,requiredExtensions: ['pg_net'],navigation: [@@ -357,7 +357,7 @@ const SUPABASE_INTEGRATIONS: Array<IntegrationDefinition> = [/>),description: 'Run GraphQL queries through our interactive in-browser IDE',- docsUrl: DOCS_URL,+ docsUrl: `${DOCS_URL}/guides/database/extensions/pg_graphql`,author: authorSupabase,navigation: [{diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx b/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsxindex 6560414d392..9e875c3c58a 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx+++ b/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx@@ -1,39 +1,87 @@import { PermissionAction } from '@supabase/shared-types/out/constants'-import Link from 'next/link'-import { useState } from 'react'-import { parseAsBoolean, useQueryState } from 'nuqs'--import { useParams } from 'common'-import { ButtonTooltip } from 'components/ui/ButtonTooltip'+import { useFlag, useParams } from 'common'+import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'import { DiscardChangesConfirmationDialog } from 'components/ui-patterns/Dialogs/DiscardChangesConfirmationDialog'+import { ButtonTooltip } from 'components/ui/ButtonTooltip'import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { useConfirmOnClose } from 'hooks/ui/useConfirmOnClose'-import {- Alert_Shadcn_,- AlertDescription_Shadcn_,- AlertTitle_Shadcn_,- Button,- Separator,- Sheet,- SheetContent,- WarningIcon,-} from 'ui'+import Link from 'next/link'+import { Admonition } from 'node_modules/ui-patterns'+import { parseAsBoolean, useQueryState } from 'nuqs'+import { useState } from 'react'+import { Button, Sheet, SheetContent } from 'ui'+import { IntegrationOverviewTab } from '../Integration/IntegrationOverviewTab'+import { IntegrationOverviewTabV2 } from '../Integration/IntegrationOverviewTabV2'+import { useAvailableIntegrations } from '../Landing/useAvailableIntegrations'import { CreateIcebergWrapperSheet } from './CreateIcebergWrapperSheet'import { CreateWrapperSheet } from './CreateWrapperSheet'import { WRAPPERS } from './Wrappers.constants'import { WrapperTable } from './WrapperTable'-export const WrapperOverviewTab = () => {+const WrapperOverviewContent = () => {const { id } = useParams()- const { data: project } = useSelectedProjectQuery()+ const wrapperMeta = WRAPPERS.find((w) => w.name === id)++ const [isDirty, setIsDirty] = useState(false)const [createWrapperShown, setCreateWrapperShown] = useQueryState('new',parseAsBoolean.withDefault(false).withOptions({ history: 'push', clearOnDefault: true }))+ const { confirmOnClose, handleOpenChange, modalProps } = useConfirmOnClose({+ checkIsDirty: () => isDirty,+ onClose: () => {+ setCreateWrapperShown(false)+ setIsDirty(false)+ },+ })++ // [Joshen] Opting to declare custom wrapper sheets here instead of within Wrappers.constants.ts+ // as we'll easily run into circular dependencies doing so unfortunately+ const CreateWrapperSheetComponent = !wrapperMeta+ ? null+ : wrapperMeta.customComponent+ ? wrapperMeta.name === 'iceberg_wrapper'+ ? CreateIcebergWrapperSheet+ : null+ : CreateWrapperSheet++ return (+ <>+ <div className="flex flex-col gap-y-5">+ <p>Recent wrappers</p>+ <WrapperTable />+ </div>++ {!!CreateWrapperSheetComponent && !!wrapperMeta && (+ <Sheet open={!!createWrapperShown} onOpenChange={handleOpenChange}>+ <SheetContent size="lg" tabIndex={undefined}>+ <CreateWrapperSheetComponent+ wrapperMeta={wrapperMeta}+ onDirty={setIsDirty}+ onClose={() => setCreateWrapperShown(false)}+ onCloseWithConfirmation={confirmOnClose}+ />+ </SheetContent>+ </Sheet>+ )}++ <DiscardChangesConfirmationDialog {...modalProps} />+ </>+ )+}++const AddNewWrapperCTA = () => {+ const { id } = useParams()+ const { data: project } = useSelectedProjectQuery()+ const [, setCreateWrapperShown] = useQueryState(+ 'new',+ parseAsBoolean.withDefault(false).withOptions({ history: 'push', clearOnDefault: true })+ )+const { can: canCreateWrapper } = useAsyncCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE,'wrappers'@@ -44,21 +92,7 @@ export const WrapperOverviewTab = () => {connectionString: project?.connectionString,})- const [isDirty, setIsDirty] = useState(false)- const { confirmOnClose, handleOpenChange, modalProps } = useConfirmOnClose({- checkIsDirty: () => isDirty,- onClose: () => {- setCreateWrapperShown(false)- setIsDirty(false)- },- })-const wrapperMeta = WRAPPERS.find((w) => w.name === id)-- if (!wrapperMeta) {- return <p className="text-sm text-foreground-light">Unsupported integration type</p>- }-const wrappersExtension = data?.find((ext) => ext.name === 'wrappers')const isWrappersExtensionInstalled = !!wrappersExtension?.installed_versionconst hasRequiredVersion =@@ -68,92 +102,104 @@ export const WrapperOverviewTab = () => {const databaseNeedsUpgrading =wrappersExtension?.installed_version === wrappersExtension?.default_version- // [Joshen] Opting to declare custom wrapper sheets here instead of within Wrappers.constants.ts- // as we'll easily run into circular dependencies doing so unfortunately- const CreateWrapperSheetComponent = wrapperMeta.customComponent- ? wrapperMeta.name === 'iceberg_wrapper'- ? CreateIcebergWrapperSheet- : ({}) => null- : CreateWrapperSheet+ if (!!wrapperMeta && isWrappersExtensionInstalled && !hasRequiredVersion) {+ return (+ <Admonition type="warning" title="Your extension version is outdated for this wrapper">+ <div className="flex flex-col gap-y-2 [&>p]:!mb-0">+ <p>+ The {wrapperMeta.label} wrapper requires a minimum extension version of{' '}+ {wrapperMeta.minimumExtensionVersion}. You have version{' '}+ {wrappersExtension?.installed_version} installed. Please{' '}+ {databaseNeedsUpgrading && 'upgrade your database then '}update the extension by+ disabling and enabling the <code className="text-code-inline">wrappers</code> extension+ to create this wrapper.+ </p>+ <p className="text-warning">+ Warning: Before reinstalling the wrapper extension, you must first remove all existing+ wrappers. Afterward, you can recreate the wrappers.+ </p>+ </div>+ <Button asChild type="default" className="w-min mt-3">+ <Link+ href={+ databaseNeedsUpgrading+ ? `/project/${project?.ref}/settings/infrastructure`+ : `/project/${project?.ref}/database/extensions?filter=wrappers`+ }+ >+ {databaseNeedsUpgrading ? 'Upgrade database' : 'View wrappers extension'}+ </Link>+ </Button>+ </Admonition>+ )+ }return (- <IntegrationOverviewTab- actions={- isWrappersExtensionInstalled && !hasRequiredVersion ? (- <div className="">- <Alert_Shadcn_ variant="warning">- <WarningIcon />- <AlertTitle_Shadcn_>- Your extension version is outdated for this wrapper.- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_ className="flex flex-col gap-y-2">- <p>- The {wrapperMeta.label} wrapper requires a minimum extension version of{' '}- {wrapperMeta.minimumExtensionVersion}. You have version{' '}- {wrappersExtension?.installed_version} installed. Please{' '}- {databaseNeedsUpgrading && 'upgrade your database then '}update the extension by- disabling and enabling the <code className="text-code-inline">wrappers</code>{' '}- extension to create this wrapper.- </p>- <p className="text-warning">- Warning: Before reinstalling the wrapper extension, you must first remove all- existing wrappers. Afterward, you can recreate the wrappers.- </p>- </AlertDescription_Shadcn_>- <AlertDescription_Shadcn_ className="mt-3">- <Button asChild type="default">- <Link- href={- databaseNeedsUpgrading- ? `/project/${project?.ref}/settings/infrastructure`- : `/project/${project?.ref}/database/extensions?filter=wrappers`- }- >- {databaseNeedsUpgrading ? 'Upgrade database' : 'View wrappers extension'}- </Link>- </Button>- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- </div>- ) : (- <div className="py-3 px-5 border rounded-md">- <ButtonTooltip- type="default"- onClick={() => setCreateWrapperShown(true)}- disabled={!canCreateWrapper}- tooltip={{- content: {- text: !canCreateWrapper- ? 'You need additional permissions to create a foreign data wrapper'- : undefined,- },- }}- >- Add new wrapper- </ButtonTooltip>- </div>- )- }- >- <div className="mx-10 flex flex-col gap-5">- Recent wrappers- <WrapperTable />- </div>- <Separator />-- <Sheet open={!!createWrapperShown} onOpenChange={handleOpenChange}>- <SheetContent size="lg" tabIndex={undefined}>- <CreateWrapperSheetComponent- wrapperMeta={wrapperMeta}- onDirty={(dirty) => setIsDirty(dirty)}- onClose={() => {- setCreateWrapperShown(false)- }}- onCloseWithConfirmation={confirmOnClose}- />- </SheetContent>- </Sheet>- <DiscardChangesConfirmationDialog {...modalProps} />- </IntegrationOverviewTab>+ <div className="py-3 px-5 border rounded-md">+ <ButtonTooltip+ type="default"+ onClick={() => setCreateWrapperShown(true)}+ disabled={!canCreateWrapper}+ tooltip={{+ content: {+ text: !canCreateWrapper+ ? 'You need additional permissions to create a foreign data wrapper'+ : undefined,+ },+ }}+ >+ Add new wrapper+ </ButtonTooltip>+ </div>)}++export const WrapperOverviewTab = () => {+ const { id } = useParams()+ const { data: project } = useSelectedProjectQuery()+ const isMarketplaceEnabled = useFlag('marketplaceIntegrations')++ const { data: integrations = [] } = useAvailableIntegrations()+ const integration = integrations.find((i) => i.id === id)+ const wrapperMeta = WRAPPERS.find((w) => w.name === id)++ const { data: extensions } = useDatabaseExtensionsQuery({+ projectRef: project?.ref,+ connectionString: project?.connectionString,+ })+ const installableExtensions = (extensions ?? []).filter((ext) =>+ (integration?.requiredExtensions ?? []).includes(ext.name)+ )+ const isInstalled = installableExtensions.every((x) => x.installed_version)++ if (!wrapperMeta) {+ return (+ <ScaffoldContainer>+ <ScaffoldSection isFullWidth>+ <p className="text-sm text-foreground-light">Unsupported integration type</p>+ </ScaffoldSection>+ </ScaffoldContainer>+ )+ }++ if (isMarketplaceEnabled) {+ return (+ <IntegrationOverviewTabV2>+ {isInstalled && (+ <>+ <AddNewWrapperCTA />+ <WrapperOverviewContent />+ </>+ )}+ </IntegrationOverviewTabV2>+ )+ } else {+ return (+ <IntegrationOverviewTab actions={<AddNewWrapperCTA />}>+ <div className="mx-10">+ <WrapperOverviewContent />+ </div>+ </IntegrationOverviewTab>+ )+ }+}diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/WrapperTable.tsx b/apps/studio/components/interfaces/Integrations/Wrappers/WrapperTable.tsxindex 0c4ee61aa27..9df814cca95 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/WrapperTable.tsx+++ b/apps/studio/components/interfaces/Integrations/Wrappers/WrapperTable.tsx@@ -94,7 +94,7 @@ export const WrapperTable = ({ isLatest = false }: WrapperTableProps) => {wrappers.length === 0 ? 'border-t-0' : '')}>- <TableRow>+ <TableRow className="border-b-0"><TableCell colSpan={4}>{wrappers.length} {integration?.name}{wrappers.length === 0 || wrappers.length > 1 ? 's' : ''} createddiff --git a/apps/studio/pages/project/[ref]/integrations/[id]/[pageId]/index.tsx b/apps/studio/pages/project/[ref]/integrations/[id]/[pageId]/index.tsxindex 56692fa6b0c..3fbfc121d79 100644--- a/apps/studio/pages/project/[ref]/integrations/[id]/[pageId]/index.tsx+++ b/apps/studio/pages/project/[ref]/integrations/[id]/[pageId]/index.tsx@@ -1,10 +1,10 @@import { useFlag, useParams } from 'common'-import { INTEGRATIONS } from 'components/interfaces/Integrations/Landing/Integrations.constants'import { useInstalledIntegrations } from 'components/interfaces/Integrations/Landing/useInstalledIntegrations'import { DefaultLayout } from 'components/layouts/DefaultLayout'import { UnknownInterface } from 'components/ui/UnknownInterface'+import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'-import { IS_PLATFORM } from 'lib/constants'+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import Link from 'next/link'import { useRouter } from 'next/router'import { useEffect, useMemo } from 'react'@@ -43,16 +43,21 @@ type NavigationItem = { label: string; href: string; active?: boolean }const IntegrationPage: NextPageWithLayout = () => {const router = useRouter()+ const { data: project } = useSelectedProjectQuery()const { ref, id, pageId, childId } = useParams()+const { integrationsWrappers } = useIsFeatureEnabled(['integrations:wrappers'])const isMarketplaceEnabled = useFlag('marketplaceIntegrations')+ const { data: extensions } = useDatabaseExtensionsQuery({+ projectRef: project?.ref,+ connectionString: project?.connectionString,+ })+const { data: allIntegrations, isPending: isAvailableIntegrationsLoading } =useAvailableIntegrations()- const {- installedIntegrations: installedIntegrations,- isLoading: isInstalledIntegrationsLoading,- } = useInstalledIntegrations()+ const { installedIntegrations, isLoading: isInstalledIntegrationsLoading } =+ useInstalledIntegrations()// everything is wrapped in useMemo to avoid UI resets when installing additional extensions like pg_netconst integration = useMemo(() => allIntegrations.find((i) => i.id === id), [allIntegrations, id])@@ -62,6 +67,15 @@ const IntegrationPage: NextPageWithLayout = () => {[installedIntegrations, id])+ const installableExtensions = (extensions ?? []).filter((ext) =>+ (integration?.requiredExtensions ?? []).includes(ext.name)+ )+ const extensionsInstalled = installableExtensions.every((x) => x.installed_version)++ // [Joshen] installedIntegrations doesn't return wrappers unless there's a wrapper created+ const isInstalled =+ !!integration && (!!installation || (integration.type === 'wrapper' && extensionsInstalled))+// Get the corresponding component dynamicallyconst Component = useMemo(() => integration?.navigate({ id, pageId, childId }),@@ -73,10 +87,10 @@ const IntegrationPage: NextPageWithLayout = () => {if (!integration?.navigation) return []// Only show navigation if the integration is installed, or if we're on the overview page- const showNavigation = installation || pageId === 'overview'+ const showNavigation = isInstalled || pageId === 'overview'if (!showNavigation) return []- const availableTabs = installation+ const availableTabs = isInstalled? integration.navigation: integration.navigation.filter((tab) => tab.route === 'overview')@@ -85,7 +99,7 @@ const IntegrationPage: NextPageWithLayout = () => {href: `/project/${ref}/integrations/${id}/${nav.route}`,active: pageId === nav.route,}))- }, [integration, ref, id, pageId, installation])+ }, [integration, pageId, isInstalled, ref, id])useEffect(() => {// if the integration is not installed, redirect to the overview page@@ -93,12 +107,12 @@ const IntegrationPage: NextPageWithLayout = () => {router &&router?.isReady &&!isInstalledIntegrationsLoading &&- !installation &&+ !isInstalled &&pageId !== 'overview') {router.replace(`/project/${ref}/integrations/${id}/overview`)}- }, [installation, isInstalledIntegrationsLoading, pageId, router, ref, id])+ }, [isInstalled, isInstalledIntegrationsLoading, pageId, router, ref, id])// Determine page title, icon, and subtitle based on stateconst pageTitle = integration?.name || 'Integration not found'@@ -199,8 +213,12 @@ const IntegrationPage: NextPageWithLayout = () => {Install integration</a></Button>- ) : isMarketplaceEnabled && !!integration && !installation ? (+ ) : isMarketplaceEnabled && !!integration && !isInstalled ? (<InstallIntegrationSheet integration={integration} />+ ) : isMarketplaceEnabled && isInstalled ? (+ <Button disabled type="outline">+ Installed+ </Button>) : null}</PageHeaderMeta>)}