Files
supabase/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx
Joshen Lim 6d08d66b7d Add eslint rule for google translate dynamic spans + address all issues (#52949)
## Context

We've been seeing many `NotFoundError: Failed to execute 'removeChild'
on 'Node'` and `NotFoundError: Failed to execute 'insertBefore' on
'Node'` events on Sentry which are historically known to be caused by
Google Translate in the browser.

There's technically no _right way_ to address this unfortunately, but
one of the solutions which should address most of these issues is to
wrap any dynamic text within a span - we've considered that quite a
while back tbh but never took the time to do this until today with the
help of Claude. Although just a heads up that it might not necessarily
completely eradicate those issues.

Also added an eslint rule which should prevent future occurences of this
<img width="1264" height="192" alt="image"
src="https://github.com/user-attachments/assets/b2c32ea0-45a2-4ccd-82fe-1a859905fc29"
/>
2026-11-05 23:28:46 +08:00

119 lines
4.5 KiB
TypeScript

import { useParams } from 'common'
import Link from 'next/link'
import { Button } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { RequiredExtensionsSection } from '../Integration/RequiredExtensionsSection'
import { useAvailableIntegrations } from '../Landing/useAvailableIntegrations'
import { AddWrapperButton } from './AddWrapperButton'
import { WRAPPERS } from './Wrappers.constants'
import { WrapperTable } from './WrapperTable'
import { getServiceVersionsPath } from '@/components/interfaces/Settings/General/ServiceVersions/ServiceVersions.utils'
import { ScaffoldContainer, ScaffoldSection } from '@/components/layouts/Scaffold'
import { useDatabaseExtensionsQuery } from '@/data/database-extensions/database-extensions-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
const WrapperOverviewContent = () => {
return (
<div className="flex flex-col gap-y-5 max-w-5xl">
<div className="flex items-center justify-between">
<p>Recent wrappers</p>
<AddWrapperButton variant="primary" />
</div>
<WrapperTable />
</div>
)
}
const AddNewWrapperCTA = () => {
const { id } = useParams()
const { data: project } = useSelectedProjectQuery()
const { data } = useDatabaseExtensionsQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
const wrapperMeta = WRAPPERS.find((w) => w.name === id)
const wrappersExtension = data?.find((ext) => ext.name === 'wrappers')
const isWrappersExtensionInstalled = !!wrappersExtension?.installed_version
const hasRequiredVersion =
(wrappersExtension?.installed_version ?? '') >= (wrapperMeta?.minimumExtensionVersion ?? '')
// [Joshen] Default version is what's on the DB, so if the installed version is already the default version
// but still doesnt meet the minimum extension version, then DB upgrade is required
const databaseNeedsUpgrading =
wrappersExtension?.installed_version === wrappersExtension?.default_version
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 && <span>{'upgrade your database then '}</span>}
<span>update the extension by disabling and enabling the</span> <code>wrappers</code>{' '}
<span>extension to create this wrapper.</span>
</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 className="w-min mt-3">
<Link
href={
databaseNeedsUpgrading
? getServiceVersionsPath(project?.ref)
: `/project/${project?.ref}/database/extensions?filter=wrappers`
}
>
{databaseNeedsUpgrading ? 'Upgrade database' : 'View wrappers extension'}
</Link>
</Button>
</Admonition>
)
}
return null
}
export const WrapperContent = () => {
const { id } = useParams()
const { data: project } = useSelectedProjectQuery()
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>
)
}
return (
<>
<RequiredExtensionsSection />
<AddNewWrapperCTA />
{isInstalled && <WrapperOverviewContent />}
</>
)
}
export const WrapperOverviewTab = () => <RequiredExtensionsSection />