Files
supabase/apps/studio/components/interfaces/Integrations/Wrappers/WrapperTable.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

141 lines
4.4 KiB
TypeScript

import { useParams } from 'common'
import { parseAsString, useQueryState } from 'nuqs'
import { useEffect, useMemo, useRef, useState } from 'react'
import { toast } from 'sonner'
import {
Card,
cn,
Sheet,
SheetContent,
Table,
TableBody,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
} from 'ui'
import { INTEGRATIONS } from '../Landing/Integrations.constants'
import { DeleteWrapperModal } from './DeleteWrapperModal'
import { EditWrapperSheet } from './EditWrapperSheet'
import { WrapperRow } from './WrapperRow'
import { wrapperMetaComparator } from './Wrappers.utils'
import { useFDWsQuery } from '@/data/fdw/fdws-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
interface WrapperTableProps {
isLatest?: boolean
}
export const WrapperTable = ({ isLatest = false }: WrapperTableProps) => {
const { id, ref } = useParams()
const { data: project } = useSelectedProjectQuery()
const integration = INTEGRATIONS.find((i) => i.id === id)
const [isClosingEditWrapper, setIsClosingEditWrapper] = useState(false)
const { data, isError, isSuccess } = useFDWsQuery({
projectRef: ref,
connectionString: project?.connectionString,
})
const wrappers = useMemo(
() =>
integration && integration.type === 'wrapper' && data
? data.filter((wrapper) => wrapperMetaComparator(integration.meta, wrapper))
: [],
[data, integration]
)
const [selectedWrapperIdToEdit, setSelectedWrapperToEdit] = useQueryState('edit', parseAsString)
const selectedWrapperToEdit = wrappers.find((w) => w.id.toString() === selectedWrapperIdToEdit)
const openedWrapperId = useRef<string | null>(null)
useEffect(() => {
if (!selectedWrapperIdToEdit) {
openedWrapperId.current = null
} else if (selectedWrapperToEdit) {
openedWrapperId.current = selectedWrapperIdToEdit
} else if (isSuccess || isError) {
if (openedWrapperId.current !== selectedWrapperIdToEdit) {
toast('Wrapper not found')
}
setSelectedWrapperToEdit(null)
}
}, [isError, isSuccess, selectedWrapperIdToEdit, selectedWrapperToEdit, setSelectedWrapperToEdit])
if (!integration || integration.type !== 'wrapper') {
return (
<p className="text-foreground-light text-sm">
The referenced ID doesn't correspond to a wrapper integration
</p>
)
}
return (
<>
<Card className="max-w-5xl">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[220px]">Name</TableHead>
<TableHead>Tables</TableHead>
<TableHead>Encrypted keys</TableHead>
<TableHead className="w-24">
<span className="sr-only">Actions</span>
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{(isLatest ? wrappers.slice(0, 3) : wrappers).map((x) => (
<WrapperRow key={x.id} wrapper={x} />
))}
</TableBody>
<TableFooter
className={cn(
'text-xs font-normal text-center text-foreground-muted',
// Prevent the footer from being highlighted on hover
'[&>tr>td]:hover:bg-inherit',
// Conditionally remove the border-top if there are no wrappers
wrappers.length === 0 ? 'border-t-0' : ''
)}
>
<TableRow className="border-b-0">
<TableCell colSpan={4}>
{wrappers.length} {integration?.name}
{wrappers.length === 0 || wrappers.length > 1 ? <span>s</span> : ''}{' '}
<span>created</span>
</TableCell>
</TableRow>
</TableFooter>
</Table>
</Card>
<Sheet
open={!!selectedWrapperToEdit}
onOpenChange={(open) => {
if (!open) setIsClosingEditWrapper(true)
}}
>
<SheetContent size="lg">
{selectedWrapperToEdit && (
<EditWrapperSheet
wrapper={selectedWrapperToEdit}
wrapperMeta={integration.meta}
onClose={() => {
setSelectedWrapperToEdit(null)
setIsClosingEditWrapper(false)
}}
isClosing={isClosingEditWrapper}
setIsClosing={setIsClosingEditWrapper}
/>
)}
</SheetContent>
</Sheet>
<DeleteWrapperModal />
</>
)
}