mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +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>
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { useParams } from 'common'
|
|
import { useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
|
|
import { PurgeCDNCacheDialog } from '@/components/interfaces/Storage/FilesBuckets/PurgeCDNCacheDialog'
|
|
import { useBucketPurgeCDNCacheMutation } from '@/data/storage/bucket-purge-cdn-cache-mutation'
|
|
import { Bucket } from '@/data/storage/buckets-query'
|
|
|
|
export interface PurgeBucketCDNCacheModalProps {
|
|
visible: boolean
|
|
bucket: Bucket
|
|
onClose: () => void
|
|
}
|
|
|
|
export const PurgeBucketCDNCacheModal = ({
|
|
visible,
|
|
bucket,
|
|
onClose,
|
|
}: PurgeBucketCDNCacheModalProps) => {
|
|
const [status, setStatus] = useState('')
|
|
const { ref: projectRef } = useParams()
|
|
|
|
const { mutateAsync: purgeBucketCDNCache, isPending: isPurgingBucketCDNCache } =
|
|
useBucketPurgeCDNCacheMutation({
|
|
onSuccess: async () => {
|
|
setStatus('')
|
|
// No need to set a status as we show a toast
|
|
toast.success(`Successfully purged CDN cache for bucket “${bucket.name}”`)
|
|
onClose()
|
|
},
|
|
async onError(data) {
|
|
// No need to set a status as we show a toast
|
|
setStatus('')
|
|
toast.error(`Failed to purge CDN cache for bucket “${bucket.name}”: ${data.message}`)
|
|
},
|
|
})
|
|
|
|
const onConfirm = async () => {
|
|
if (!projectRef) return console.error('Project ref is required')
|
|
if (!bucket) return console.error('No bucket is selected')
|
|
setStatus(`Purging CDN cache for bucket “${bucket.name}”…`)
|
|
return purgeBucketCDNCache({ projectRef, id: bucket.id })
|
|
}
|
|
|
|
return (
|
|
<PurgeCDNCacheDialog
|
|
visible={visible}
|
|
title="Purge CDN cache for bucket"
|
|
description={`The CDN cache for all files within the bucket "${bucket.name}" will be purged.`}
|
|
status={status}
|
|
isPurging={isPurgingBucketCDNCache}
|
|
onConfirm={onConfirm}
|
|
onClose={onClose}
|
|
/>
|
|
)
|
|
}
|