Files
supabase/apps/studio/components/interfaces/Database/Backups/BackupItem.tsx
T
Danny White 87919a08e6 chore(studio): remove physical backups disabled download button (#43160)
## What kind of change does this PR introduce?

UI update

## What is the current behavior?

- The vast majority of projects now have physical backups, not logical
- Physical backups are not downloadable
- But we show a disabled `Download` button for each physical backup
- This button has confusing multi-step instructions about `pg_dump` that
are
[inaccurate](https://supabase.slack.com/archives/C02BJ2239GA/p1771979586829419?thread_ts=1771887878.203199&cid=C02BJ2239GA)

## What is the new behavior?

- We only show the (enabled) `Download` button for logical backups

| Before | After |
| --- | --- |
| <img width="1024" height="563" alt="AWS Healthy Toolshed
Supabase-6FE7C23F-29D6-47B6-819A-84BC49927F3A"
src="https://github.com/user-attachments/assets/167441bf-3ead-4c86-89df-60ab89ce8b98"
/> | <img width="1024" height="563" alt="AWS Healthy Toolshed
Supabase-C9E763B7-B447-468E-B928-BB9AD5ABC588"
src="https://github.com/user-attachments/assets/3fccdf12-ba4e-424a-87ae-2294f1a3b7b1"
/> |


## Additional context

Support believes removing the button entirely will have less of a burden
than a better tooltip explanation.
2026-02-25 16:43:40 +08:00

120 lines
4.0 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { Download } from 'lucide-react'
import { useParams } from 'common'
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 { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { Badge, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import { TimestampInfo } from 'ui-patterns'
interface BackupItemProps {
index: number
isHealthy: boolean
backup: DatabaseBackup
onSelectBackup: () => void
}
export const BackupItem = ({ index, isHealthy, backup, onSelectBackup }: BackupItemProps) => {
const { ref: projectRef } = useParams()
const { can: canTriggerScheduledBackups } = useAsyncCheckPermissions(
PermissionAction.INFRA_EXECUTE,
'queue_job.restore.prepare'
)
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)
},
})
const generateSideButtons = (backup: DatabaseBackup) => {
if (backup.status === 'COMPLETED')
return (
<div className="flex space-x-4">
<ButtonTooltip
type="default"
disabled={!isHealthy || !canTriggerScheduledBackups}
onClick={onSelectBackup}
tooltip={{
content: {
side: 'bottom',
text: !isHealthy
? 'Cannot be restored as project is not active'
: !canTriggerScheduledBackups
? 'You need additional permissions to trigger a restore'
: undefined,
},
}}
>
Restore
</ButtonTooltip>
{!backup.isPhysicalBackup && (
<ButtonTooltip
type="default"
icon={<Download />}
loading={isDownloading}
disabled={!canTriggerScheduledBackups || isDownloading}
onClick={() => {
if (!projectRef) return console.error('Project ref is required')
downloadBackup({ ref: projectRef, backup })
}}
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
? 'File-level backups of your entire database.'
: 'SQL-based backups of your entire database.'}{' '}
<InlineLink href="https://supabase.com/blog/postgresql-physical-logical-backups">
Learn more
</InlineLink>
</TooltipContent>
</Tooltip>
</div>
<div>{generateSideButtons(backup)}</div>
</div>
)
}