mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## 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" />
133 lines
4.2 KiB
TypeScript
133 lines
4.2 KiB
TypeScript
import { useParams } from 'common'
|
|
import { DownloadIcon } from 'lucide-react'
|
|
import { Badge, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
import { TimestampInfo } from 'ui-patterns/TimestampInfo'
|
|
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import { useBackupDownloadMutation } from '@/data/database/backup-download-mutation'
|
|
import type { DatabaseBackup } from '@/data/database/backups-query'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
|
|
interface BackupItemProps {
|
|
index: number
|
|
isHealthy: boolean
|
|
isHighAvailability: boolean
|
|
backup: DatabaseBackup
|
|
onSelectBackup: () => void
|
|
}
|
|
|
|
export const BackupItem = ({
|
|
index,
|
|
isHealthy,
|
|
isHighAvailability,
|
|
backup,
|
|
onSelectBackup,
|
|
}: BackupItemProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const { can: canTriggerScheduledBackups } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.BACKUPS_WRITE
|
|
)
|
|
|
|
const { mutate: downloadBackup, isPending: isDownloading } = useBackupDownloadMutation({
|
|
onSuccess: (res) => {
|
|
const { fileUrl } = res
|
|
|
|
// Trigger browser download by create,trigger and remove tempLink
|
|
const tempLink = document.createElement('a')
|
|
tempLink.href = fileUrl
|
|
document.body.appendChild(tempLink)
|
|
tempLink.click()
|
|
document.body.removeChild(tempLink)
|
|
},
|
|
})
|
|
|
|
function getTooltipText() {
|
|
if (isHighAvailability) {
|
|
return 'Restoring from a backup is unavailable on High Availability projects'
|
|
} else if (!isHealthy) {
|
|
return 'Cannot be restored as project is not active'
|
|
} else if (!canTriggerScheduledBackups) {
|
|
return 'You need additional permissions to trigger a restore'
|
|
} else {
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
const generateSideButtons = (backup: DatabaseBackup) => {
|
|
if (backup.status === 'COMPLETED')
|
|
return (
|
|
<div className="flex space-x-4">
|
|
<ButtonTooltip
|
|
disabled={!isHealthy || !canTriggerScheduledBackups || isHighAvailability}
|
|
onClick={onSelectBackup}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: getTooltipText(),
|
|
},
|
|
}}
|
|
>
|
|
Restore
|
|
</ButtonTooltip>
|
|
|
|
{!backup.isPhysicalBackup && (
|
|
<ButtonTooltip
|
|
icon={<DownloadIcon />}
|
|
loading={isDownloading}
|
|
disabled={!canTriggerScheduledBackups || isDownloading}
|
|
onClick={() => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
downloadBackup({ ref: projectRef, backupId: backup.id })
|
|
}}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: !canTriggerScheduledBackups
|
|
? 'You need additional permissions to download backups'
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
Download
|
|
</ButtonTooltip>
|
|
)}
|
|
</div>
|
|
)
|
|
return <Badge variant="warning">Backup In Progress...</Badge>
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className={`flex h-12 items-center justify-between px-6 ${
|
|
index ? 'border-t border-default' : ''
|
|
}`}
|
|
>
|
|
<div className="flex items-center gap-x-2">
|
|
<TimestampInfo
|
|
displayAs="utc"
|
|
utcTimestamp={backup.inserted_at}
|
|
labelFormat="DD MMM YYYY HH:mm:ss (ZZ)"
|
|
className="text-left text-sm! font-mono tracking-tight"
|
|
/>
|
|
<Tooltip>
|
|
<TooltipTrigger>
|
|
<Badge variant="default">{backup.isPhysicalBackup ? 'Physical' : 'Logical'}</Badge>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">
|
|
{backup.isPhysicalBackup ? (
|
|
<span>File-level backups of your entire database.</span>
|
|
) : (
|
|
<span>SQL-based backups of your entire database.</span>
|
|
)}{' '}
|
|
<InlineLink href="https://supabase.com/blog/postgresql-physical-logical-backups">
|
|
Learn more
|
|
</InlineLink>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
<div>{generateSideButtons(backup)}</div>
|
|
</div>
|
|
)
|
|
}
|