mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
- Reverted the timeline row's Restore action back to its icon-only text-variant button — the ask to make Restore a default-variant button was about the "Back to latest" action in the version preview banner, not the per-row action in the Versions tab - The version preview banner's action is now labeled Restore, styled as a default-variant button, and actually restores the previewed version as current (instead of just clearing the preview) - Versioning can no longer be turned fully "off" on a bucket that's ever had it enabled — it moves to a new suspended state instead, matching how bucket versioning actually behaves. Suspending only stops new noncurrent versions from being created; nothing already retained is deleted, so the destructive typed-confirmation flow for disabling versioning is gone - Added `hasVersioningHistory` (enabled OR suspended) alongside the existing `isBucketVersioned` (enabled only) and repointed every surface that manages or warns about retained version/trash data to the former, since a suspended bucket can still be sitting on plenty of it - Bucket list "Versioning" column, plan-downgrade admonition, and the Versions tab now all reflect the three states (Enabled / Suspended / never enabled) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TiUEvmC84bRsteqsWXHY2p
98 lines
3.1 KiB
TypeScript
98 lines
3.1 KiB
TypeScript
import { useParams } from 'common'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
} from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
|
|
import { useBucketEmptyMutation } from '@/data/storage/bucket-empty-mutation'
|
|
import type { Bucket } from '@/data/storage/buckets-query'
|
|
import { useStorageExplorerStateSnapshot } from '@/state/storage-explorer'
|
|
|
|
import { hasVersioningHistory } from './StorageProtection.constants'
|
|
|
|
export interface EmptyBucketModalProps {
|
|
visible: boolean
|
|
bucket?: Bucket
|
|
onClose: () => void
|
|
}
|
|
|
|
export const EmptyBucketModal = ({ visible, bucket, onClose }: EmptyBucketModalProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const { fetchFolderContents } = useStorageExplorerStateSnapshot()
|
|
const isVersioned = hasVersioningHistory(bucket?.id)
|
|
|
|
const { mutate: emptyBucket, isPending } = useBucketEmptyMutation({
|
|
onSuccess: async () => {
|
|
if (bucket === undefined) return
|
|
await fetchFolderContents({
|
|
bucketId: bucket.id,
|
|
folderId: bucket.id,
|
|
folderName: bucket.name,
|
|
index: -1,
|
|
})
|
|
toast.success(`Successfully emptied bucket ${bucket!.name}`)
|
|
onClose()
|
|
},
|
|
})
|
|
|
|
const onEmptyBucket = async () => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
if (!bucket) return console.error('No bucket is selected')
|
|
emptyBucket({ projectRef, id: bucket.id })
|
|
}
|
|
|
|
return (
|
|
<Dialog
|
|
open={visible}
|
|
onOpenChange={(open) => {
|
|
if (!open) onClose()
|
|
}}
|
|
>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{`Empty bucket “${bucket?.name}”`}</DialogTitle>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
<Admonition
|
|
type="destructive"
|
|
className="rounded-none border-x-0 border-t-0"
|
|
title="This action cannot be undone"
|
|
description={
|
|
isVersioned
|
|
? 'All live objects, noncurrent versions, and soft-deleted files in this bucket will be permanently deleted and cannot be recovered.'
|
|
: 'The contents of your bucket cannot be recovered once deleted.'
|
|
}
|
|
/>
|
|
<DialogSection className="space-y-3">
|
|
<p className="text-sm">
|
|
Are you sure you want to remove all contents from the bucket “{bucket?.name}”?
|
|
</p>
|
|
{isVersioned && (
|
|
<Admonition
|
|
type="warning"
|
|
title="This bucket has retained versions"
|
|
description="Emptying will also permanently delete every noncurrent version and every file currently in the deleted files trash, whether or not versioning is still active. Nothing will be recoverable."
|
|
/>
|
|
)}
|
|
</DialogSection>
|
|
<DialogFooter>
|
|
<Button variant="default" disabled={isPending} onClick={onClose}>
|
|
Cancel
|
|
</Button>
|
|
<Button variant="danger" loading={isPending} onClick={onEmptyBucket}>
|
|
Empty bucket
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|