mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 12:55:06 +03:00
feat(storage): prefill expiration policy inputs with 30 days / 10 versions
Create modal: expiration inputs default to 30 days and 10 versions instead of empty, so toggling versioning on surfaces a policy that's ready to save. Clearing a field still removes that condition from the policy. Edit modal: same defaults, but only when the bucket has never had versioning enabled — buckets already versioned keep their existing values (including explicit null == "no limit on this condition"), so the modal never silently retro-adds a condition the user removed.
This commit is contained in:
3 files changed
+24
-6
No files matched your search
@@ -96,8 +96,9 @@ export const BucketDataProtectionFields = ({
|
||||
// Turning versioning off never deletes anything by itself — a bucket that's
|
||||
// ever had it enabled can only be suspended, not returned to a plain
|
||||
// "disabled" state, so nothing needs a destructive confirmation here.
|
||||
// Both expiration fields default to empty (no limit) — the user opts in to
|
||||
// each condition deliberately rather than receiving prefilled defaults.
|
||||
// The two expiration fields come prefilled with sensible starter values
|
||||
// (see CreateBucketModal / EditBucketModal defaults) — clearing a field
|
||||
// removes that condition from the policy.
|
||||
const handleVersioningToggle = (checked: boolean, onChange: (value: boolean) => void) => {
|
||||
onChange(checked)
|
||||
}
|
||||
|
||||
@@ -130,8 +130,11 @@ export const CreateBucketModal = ({ open, onOpenChange }: CreateBucketModalProps
|
||||
formatted_size_limit: undefined,
|
||||
allowed_mime_types: '',
|
||||
enable_versioning: false,
|
||||
version_expiry_days: '',
|
||||
max_noncurrent_versions: '',
|
||||
// Prefill sensible defaults so the inputs aren't blank the moment
|
||||
// versioning is toggled on. A no-policy bucket has to be an explicit
|
||||
// opt-out — clear the field to remove that condition.
|
||||
version_expiry_days: 30,
|
||||
max_noncurrent_versions: 10,
|
||||
expiration_mode: 'and',
|
||||
},
|
||||
})
|
||||
|
||||
@@ -126,6 +126,20 @@ export const EditBucketModal = ({ visible, bucket, onClose }: EditBucketModalPro
|
||||
},
|
||||
})
|
||||
|
||||
// Prefill the two expiration inputs with sensible starter values when the
|
||||
// bucket has never had versioning turned on — so toggling versioning on
|
||||
// for the first time surfaces a policy ready to save, matching the create
|
||||
// form's defaults. If versioning is already on (or has been in the past)
|
||||
// respect the bucket's own values, including `null` which means the user
|
||||
// explicitly opted out of that particular condition.
|
||||
const hasEverBeenVersioned = bucketProtection.versioning !== 'disabled'
|
||||
const defaultVersionExpiryDays = hasEverBeenVersioned
|
||||
? (bucketProtection.versionExpiryDays ?? ('' as const))
|
||||
: 30
|
||||
const defaultMaxNoncurrentVersions = hasEverBeenVersioned
|
||||
? (bucketProtection.maxNoncurrentVersions ?? ('' as const))
|
||||
: 10
|
||||
|
||||
const defaultValues = {
|
||||
name: bucket?.name ?? '',
|
||||
public: bucket?.public,
|
||||
@@ -133,8 +147,8 @@ export const EditBucketModal = ({ visible, bucket, onClose }: EditBucketModalPro
|
||||
formatted_size_limit: bucket?.file_size_limit ? (fileSizeLimit ?? 0) : undefined,
|
||||
allowed_mime_types: (bucket?.allowed_mime_types ?? []).join(', '),
|
||||
enable_versioning: !!planLimits && bucketProtection.versioning === 'enabled',
|
||||
version_expiry_days: bucketProtection.versionExpiryDays ?? ('' as const),
|
||||
max_noncurrent_versions: bucketProtection.maxNoncurrentVersions ?? ('' as const),
|
||||
version_expiry_days: defaultVersionExpiryDays,
|
||||
max_noncurrent_versions: defaultMaxNoncurrentVersions,
|
||||
expiration_mode: bucketProtection.expirationMode,
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user