mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
## 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
133 lines
4.2 KiB
TypeScript
133 lines
4.2 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useParams } from 'common'
|
|
import { Download } 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 { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
|
|
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 } = 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)
|
|
},
|
|
})
|
|
|
|
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={<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>
|
|
)
|
|
}
|