Files
supabase/apps/studio/components/layouts/ProjectLayout/PausedState/DownloadBackupsSection.tsx
Danny White 476d4a5851 refactor(ui): drop redundant Button variant="default" props (#50161)
## What kind of change does this PR introduce?

Mechanical cleanup on top of the Button default-variant change (#50160).

## What is the current behavior?

Many callsites still pass `variant="default"` even though that is now
the component default.

## What is the new behavior?

Removes redundant static `variant="default"` from legacy `Button` and
`ButtonTooltip` callsites. Keeps explicit defaults where they document
the API:

- `button-default.tsx` and `button-sizes.tsx` demos
- `DocsButton`, which pins neutral styling at the wrapper boundary

## To test

Studio:

- [Auth → Rate
Limits](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/auth/rate-limits):
dirty the form so Cancel appears; Cancel stays neutral, Save stays green
- [Project Settings → API
Keys](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/settings/api-keys):
`DocsButton` in the header actions stays neutral

Design system:

- [Design system →
Button](https://design-system-git-dnywh-dc924ac1-supabase.vercel.app/design-system/docs/components/button):
`button-default` / `button-sizes` still show explicit default styling;
Primary (green) is restricted to the Primary section (and `asChild`)

WWW:

- [www → Brand
assets](https://zone-www-dot-com-git-dnywh-dc924ac1-supabase.vercel.app/brand-assets):
Download logo kit / Download button kit stay neutral
2026-09-11 17:05:26 +10:00

155 lines
5.0 KiB
TypeScript

import { useParams } from 'common'
import { Database, Storage } from 'icons'
import { ChevronDown, Download } from 'lucide-react'
import { useEffect, useState } from 'react'
import { toast } from 'sonner'
import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from 'ui'
import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
import { useBackupDownloadMutation } from '@/data/database/backup-download-mutation'
import { useProjectPauseStatusQuery } from '@/data/projects/project-pause-status-query'
import { useStorageArchiveCreateMutation } from '@/data/storage/storage-archive-create-mutation'
import { useStorageArchiveQuery } from '@/data/storage/storage-archive-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { PROJECT_STATUS } from '@/lib/constants'
export const DownloadBackupsSection = () => {
const { ref } = useParams()
const { data: project } = useSelectedProjectQuery()
const [toastId, setToastId] = useState<string | number>()
const [refetchInterval, setRefetchInterval] = useState<number | false>(false)
const dbVersion = project?.dbVersion?.replace('supabase-postgres-', '')
const { data: pauseStatus } = useProjectPauseStatusQuery(
{ ref },
{ enabled: project?.status === PROJECT_STATUS.INACTIVE }
)
const latestBackup = pauseStatus?.latest_downloadable_backup_id
const { data: storageArchive, isSuccess: isStorageArchiveSuccess } = useStorageArchiveQuery(
{ projectRef: ref },
{
refetchInterval,
refetchOnWindowFocus: false,
}
)
useEffect(() => {
if (!isStorageArchiveSuccess) return
if (storageArchive.fileUrl && refetchInterval !== false) {
toast.success('Downloading storage objects', { id: toastId })
setToastId(undefined)
setRefetchInterval(false)
downloadStorageArchive(storageArchive.fileUrl)
}
}, [isStorageArchiveSuccess, storageArchive, refetchInterval])
const storageArchiveUrl = storageArchive?.fileUrl
const { mutate: downloadBackup } = 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 { mutate: createStorageArchive } = useStorageArchiveCreateMutation({
onSuccess: () => {
const toastId = toast.loading(
'Retrieving storage archive. This may take a few minutes depending on the size of your storage objects.'
)
setToastId(toastId)
setRefetchInterval(5000)
},
})
const onSelectDownloadBackup = () => {
if (ref === undefined) return console.error('Project ref is required')
if (!latestBackup) return toast.error('No backups available for download')
const toastId = toast.loading('Fetching database backup')
downloadBackup(
{
ref,
backup: {
id: latestBackup,
},
},
{
onSuccess: () => {
toast.success('Downloading database backup', { id: toastId })
},
}
)
}
const downloadStorageArchive = (url: string) => {
const tempLink = document.createElement('a')
tempLink.href = url
document.body.appendChild(tempLink)
tempLink.click()
document.body.removeChild(tempLink)
}
const onSelectDownloadStorageArchive = () => {
if (!storageArchiveUrl) {
createStorageArchive({ projectRef: ref })
} else {
toast.success('Downloading storage objects')
downloadStorageArchive(storageArchiveUrl)
}
}
return (
<div className="border-t flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center px-6 py-4 bg-alternative">
<div>
<p className="text-sm">Export your data</p>
<p className="text-sm text-foreground-lighter">
Download backups for your database and storage objects
</p>
</div>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button icon={<Download />} iconRight={<ChevronDown />}>
Download backups
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-60" align="end">
<DropdownMenuItemTooltip
className="gap-x-2"
disabled={!latestBackup}
onClick={() => onSelectDownloadBackup()}
tooltip={{
content: {
side: 'right',
text: 'No backups available, please reach out via support for assistance',
},
}}
>
<Database size={16} />
Database backup (PG: {dbVersion})
</DropdownMenuItemTooltip>
<DropdownMenuItem className="gap-x-2" onClick={() => onSelectDownloadStorageArchive()}>
<Storage size={16} />
Storage objects
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
)
}