Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Provide convenient unit selection for custom expiry in storage

Joshen Lim9589b4eea625
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/CustomExpiryModal.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/CustomExpiryModal.tsx
index d20d137cdbc..55197f896fd 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/CustomExpiryModal.tsx
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/CustomExpiryModal.tsx
@@ -1,4 +1,4 @@
-import { Form, Modal, Input, Button } from 'ui'
+import { Form, Modal, Input, Button, Listbox } from 'ui'
import { observer } from 'mobx-react-lite'
import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'
@@ -6,6 +6,13 @@ export interface CustomExpiryModalProps {
onCopyUrl: (name: string, url: string) => void
}
+const unitMap: { seconds: number; days: number; months: number; years: number } = {
+ seconds: 1,
+ days: 3600 * 24,
+ months: 3600 * 24 * 30,
+ years: 3600 * 24 * 365,
+}
+
const CustomExpiryModal = ({ onCopyUrl }: CustomExpiryModalProps) => {
const storageExplorerStore = useStorageStore()
const { getFileUrl, selectedFileCustomExpiry, setSelectedFileCustomExpiry } = storageExplorerStore
@@ -25,34 +32,59 @@ const CustomExpiryModal = ({ onCopyUrl }: CustomExpiryModalProps) => {
>
<Form
validateOnBlur
- initialValues={{ expiresIn: '' }}
+ initialValues={{ expiresIn: '', units: 'seconds' }}
onSubmit={async (values: any, { setSubmitting }: any) => {
setSubmitting(true)
onCopyUrl(
selectedFileCustomExpiry.name,
- await getFileUrl(selectedFileCustomExpiry, values.expiresIn)
+ await getFileUrl(
+ selectedFileCustomExpiry,
+ values.expiresIn * unitMap[values.units as 'seconds' | 'days' | 'months' | 'years']
+ )
)
setSubmitting(false)
onClose()
}}
validate={(values: any) => {
const errors: any = {}
- if (values.expiresIn !== '' && values.expiresIn <= 0)
+ if (values.expiresIn !== '' && values.expiresIn <= 0) {
errors.expiresIn = 'Expiry duration cannot be less than 0'
+ }
return errors
}}
>
{({ values, isSubmitting }: { values: any; isSubmitting: boolean }) => (
<>
- <div className="py-6">
+ <div className="pt-4 pb-2">
<Modal.Content>
- <Input
- disabled={isSubmitting}
- type="number"
- id="expiresIn"
- label="Enter the duration for which the URL will be valid:"
- actions={<p className="text-sm text-scale-1000 mr-2">seconds</p>}
- />
+ <p className="text-sm text-light mb-2">
+ Enter the duration for which the URL will be valid for:
+ </p>
+ <div className="flex items-center space-x-2">
+ <Input disabled={isSubmitting} type="number" id="expiresIn" className="w-full" />
+ <Listbox id="units" className="w-[150px]">
+ <Listbox.Option id="seconds" label="seconds" value="seconds">
+ seconds
+ </Listbox.Option>
+ <Listbox.Option id="days" label="days" value="days">
+ days
+ </Listbox.Option>
+ <Listbox.Option id="months" label="months" value="months">
+ months
+ </Listbox.Option>
+ <Listbox.Option id="years" label="years" value="years">
+ years
+ </Listbox.Option>
+ </Listbox>
+ </div>
+ {values.units !== 'seconds' && (
+ <p className="text-sm text-light mt-2">
+ Equivalent to{' '}
+ {values.expiresIn *
+ unitMap[values.units as 'seconds' | 'days' | 'months' | 'years']}{' '}
+ seconds
+ </p>
+ )}
</Modal.Content>
</div>
<Modal.Separator />
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx
index ba4ee7bc678..36a73884997 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx
@@ -409,6 +409,7 @@ const FileExplorerRow = ({
/>
) : (
<Dropdown
+ modal={false}
side="bottom"
align="end"
overlay={[