mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 07:59:03 +00:00
## Problem Users should be able to purge the CDN cache for an individual object or entire bucket via the UI. This feature is only available for Pro+ customers. Free tier customers should be encouraged to upgrade to get access. ## Solution - Add a _Purge CDN cache_ action to the bucket menu. Prompt users on Free plan to upgrade if needed. <img width="182" height="149" alt="image" src="https://github.com/user-attachments/assets/b665c8d0-b540-400e-a328-85c48ddafee0" /> <img width="534" height="242" alt="image" src="https://github.com/user-attachments/assets/15dfd3d3-c8a9-4ad7-9046-0929fd715511" /> <img width="538" height="211" alt="image" src="https://github.com/user-attachments/assets/3e29644e-9335-4b1d-b321-49303c2e8476" /> - Add a _Purge CDN cache_ action to the bucket item menu. Prompt users on Free plan to upgrade if needed. <img width="283" height="313" alt="image" src="https://github.com/user-attachments/assets/a801297e-04b5-46c7-aaf7-4569e66e4714" /> <img width="541" height="249" alt="image" src="https://github.com/user-attachments/assets/b58d264b-76ba-43d4-9579-6c07be9cb684" /> <img width="537" height="207" alt="image" src="https://github.com/user-attachments/assets/132b37bd-3a29-48b5-aa7e-7df29abcbfe6" /> ## Notes - Refactored the _Edit bucket_ menu so that only one modal is allowed - Fixed focus management related to the modals displayed by the _Edit bucket_ menu items - Introduced a way to mock the authenticated users in tests ## Review instructions - On an org on at least _Pro_ plan - Open a bucket _Edit bucket_ menu and click _Purge CDN cache_ - Confirming should call the `/platform/storage/{ref}/cdn/purge-bucket` API endpoint - Open a bucket item menu and click _Purge CDN cache_ - Confirming should call the `/platform/storage/{ref}/cdn/purge-object` API endpoint - On an org on _Free_ plan - Open a bucket _Edit bucket_ menu and click _Purge CDN cache_ - You should be prompted to upgrade - Open a bucket item menu and click _Purge CDN cache_ - You should be prompted to upgrade --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
98 lines
2.8 KiB
TypeScript
98 lines
2.8 KiB
TypeScript
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from 'ui'
|
|
|
|
import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
|
|
interface PurgeCDNCacheDialogProps {
|
|
visible: boolean
|
|
title: string
|
|
description: string
|
|
status: string
|
|
isPurging: boolean
|
|
onConfirm: () => void
|
|
onClose: () => void
|
|
}
|
|
|
|
export const PurgeCDNCacheDialog = ({
|
|
visible,
|
|
title,
|
|
status,
|
|
description,
|
|
isPurging,
|
|
onConfirm,
|
|
onClose,
|
|
}: PurgeCDNCacheDialogProps) => {
|
|
const { data: organization } = useSelectedOrganizationQuery()
|
|
const isFreePlan = organization?.plan.id === 'free'
|
|
|
|
return (
|
|
<AlertDialog
|
|
open={visible}
|
|
onOpenChange={(open) => {
|
|
if (!open && isPurging) return
|
|
onClose()
|
|
}}
|
|
>
|
|
<AlertDialogContent
|
|
size={isFreePlan ? 'small' : 'medium'}
|
|
onClick={(event) =>
|
|
// Avoid triggering the overlay click
|
|
event.stopPropagation()
|
|
}
|
|
dialogOverlayProps={{
|
|
onClick: () => {
|
|
if (isPurging) return
|
|
onClose()
|
|
},
|
|
}}
|
|
>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{title}</AlertDialogTitle>
|
|
<AlertDialogDescription asChild>
|
|
{/* No Admonition (that has an alert role) here as we're already in an alertdialog */}
|
|
<div className="space-y-4">
|
|
{isFreePlan ? (
|
|
<p>Purging the CDN cache requires the Pro plan or higher.</p>
|
|
) : (
|
|
<>
|
|
<p>
|
|
{description + ' '}
|
|
Invalidation can take <strong className="font-bold">up to 60 seconds</strong> to
|
|
propagate across all CDN edge nodes worldwide.
|
|
</p>
|
|
<p>
|
|
Purging the CDN cache does not affect browser caches. Users may see the cached
|
|
version until their browser cache expires.
|
|
</p>
|
|
</>
|
|
)}
|
|
</div>
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel disabled={isPurging}>Cancel</AlertDialogCancel>
|
|
{isFreePlan ? (
|
|
<UpgradePlanButton source="storagePurgeCDNCache" featureProposition="purge CDN cache" />
|
|
) : (
|
|
<AlertDialogAction disabled={isPurging} onClick={onConfirm}>
|
|
Purge CDN cache
|
|
</AlertDialogAction>
|
|
)}
|
|
</AlertDialogFooter>
|
|
<div className="sr-only" aria-live="polite">
|
|
{status}
|
|
</div>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
)
|
|
}
|