Skip to content

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

Deprecate old create bucket modal

Joshen Lim347180e2c416
diff --git a/studio/components/interfaces/Storage/CreateBucketModal.tsx b/studio/components/interfaces/Storage/CreateBucketModal.tsx
index 60f2405d8aa..0e63010c07a 100644
--- a/studio/components/interfaces/Storage/CreateBucketModal.tsx
+++ b/studio/components/interfaces/Storage/CreateBucketModal.tsx
@@ -57,7 +57,7 @@ const CreateBucketModal = ({ visible, onClose }: CreateBucketModalProps) => {
if (!values.name) {
errors.name = 'Please provide a name for your bucket'
}
- if (values.has_file_size_limit && values.formatted_size_limit < 0) {
+ if (values.has_file_size_limit && values.formatted_size_limit <= 0) {
errors.formatted_size_limit = 'Please provide a value greater than 0'
}
return errors
@@ -67,7 +67,9 @@ const CreateBucketModal = ({ visible, onClose }: CreateBucketModalProps) => {
const payload: BucketCreatePayload = {
id: values.name,
public: values.public,
- file_size_limit: convertToBytes(values.formatted_size_limit, selectedUnit),
+ file_size_limit: values.has_file_size_limit
+ ? convertToBytes(values.formatted_size_limit, selectedUnit)
+ : 0,
allowed_mime_types: values.allowed_mime_types.split(',').map((x: string) => x.trim()),
}
diff --git a/studio/components/interfaces/Storage/EditBucketModal.tsx b/studio/components/interfaces/Storage/EditBucketModal.tsx
index 60ff6eaf74a..e8c3c912bd5 100644
--- a/studio/components/interfaces/Storage/EditBucketModal.tsx
+++ b/studio/components/interfaces/Storage/EditBucketModal.tsx
@@ -44,7 +44,7 @@ const EditBucketModal = ({ visible, bucket, onClose }: EditBucketModalProps) =>
const validate = (values: any) => {
const errors = {} as any
- if (values.has_file_size_limit && values.formatted_size_limit < 0) {
+ if (values.has_file_size_limit && values.formatted_size_limit <= 0) {
errors.formatted_size_limit = 'Please provide a value greater than 0'
}
return errors
@@ -57,7 +57,9 @@ const EditBucketModal = ({ visible, bucket, onClose }: EditBucketModalProps) =>
const payload: BucketUpdatePayload = {
public: values.public,
- file_size_limit: convertToBytes(values.formatted_size_limit, selectedUnit),
+ file_size_limit: values.has_file_size_limit
+ ? convertToBytes(values.formatted_size_limit, selectedUnit)
+ : 0,
allowed_mime_types: values.allowed_mime_types.split(',').map((x: string) => x.trim()),
}
@@ -154,7 +156,7 @@ const EditBucketModal = ({ visible, bucket, onClose }: EditBucketModalProps) =>
{!bucket?.public && values.public
? `This will make all objects in the bucket "${bucket?.name}" public`
: bucket?.public && !values.public
- ? `This will make all objects in "${bucket?.name}" private. They can only be accessed via signed URLs or downloaded with the right authorisation headers`
+ ? `All objects in "${bucket?.name}" will be made private and will only be accessible via signed URLs or downloaded with the right authorisation headers`
: ''}
</p>
</Alert>
diff --git a/studio/components/to-be-cleaned/Storage/CreateBucketModal.tsx b/studio/components/to-be-cleaned/Storage/CreateBucketModal.tsx
deleted file mode 100644
index 3a9a5f88cc4..00000000000
--- a/studio/components/to-be-cleaned/Storage/CreateBucketModal.tsx
+++ /dev/null
@@ -1,120 +0,0 @@
-import { FC, useEffect, useState } from 'react'
-import { Modal, Alert, Button, Input, Toggle } from 'ui'
-
-interface Props {
- visible: boolean
- onSelectCancel: () => {}
- onSelectSave: (bucketName: string, isPublic: boolean) => {}
-}
-
-const CreateBucketModal: FC<Props> = ({
- visible = false,
- onSelectCancel = () => {},
- onSelectSave = () => {},
-}) => {
- const [saving, setSaving] = useState(false)
- const [error, setError] = useState('')
-
- const [bucketName, setBucketName] = useState('')
- const [isPublic, setIsPublic] = useState(false)
-
- useEffect(() => {
- setError('')
- setBucketName('')
- setSaving(false)
- setIsPublic(false)
- }, [visible])
-
- const onCreateBucket = (event: React.MouseEvent<HTMLElement>) => {
- if (event) {
- event.preventDefault()
- }
-
- if (bucketName.length === 0) {
- onSelectCancel()
- } else {
- if (bucketName.includes(' ')) {
- return setError('Bucket names should not have any spaces')
- }
- if (bucketName.match(/[:;'"/?!#$%^&*()+_{}\[\]|\s]/g)) {
- return setError('Only dots(.) or hyphens(-) are allowed')
- }
- if (bucketName !== bucketName.toLowerCase()) {
- return setError('Only lowercase letters are allowed')
- }
- setError('')
- setSaving(true)
- onSelectSave(bucketName, isPublic)
- }
- }
-
- return (
- <Modal
- visible={visible}
- header="Create storage bucket"
- size="medium"
- onCancel={onSelectCancel}
- customFooter={
- <div className="flex items-center gap-2">
- <Button type="default" onClick={onSelectCancel}>
- Cancel
- </Button>
- <Button type="primary" disabled={saving} loading={saving} onClick={onCreateBucket}>
- {saving ? 'Creating bucket' : 'Create bucket'}
- </Button>
- </div>
- }
- >
- <form className="space-y-6 py-4">
- <Modal.Content>
- <div className="relative flex items-center">
- <Input
- autoFocus
- label="Name of bucket"
- labelOptional="Buckets cannot be renamed once created."
- descriptionText={
- <p className="text-scale-1000">
- Only lowercase letters, numbers, dots, and hyphens
- </p>
- }
- layout="vertical"
- error={error}
- type="text"
- className="w-full"
- placeholder="e.g new-bucket"
- value={bucketName}
- onChange={(event) => setBucketName(event.target.value)}
- />
- </div>
- </Modal.Content>
- <Modal.Separator />
- <Modal.Content>
- <div className="space-y-4">
- <Toggle
- name="isPublic"
- label="Public bucket"
- descriptionText="Anyone can read any object without any authorization"
- layout="flex"
- size="medium"
- onChange={() => setIsPublic(!isPublic)}
- />
- {isPublic && (
- <Alert title="Public buckets are not protected" variant="warning" withIcon>
- <p className="mb-2">
- Users can read objects in public buckets without any authorization.
- </p>
- <p>
- Row level security (RLS) policies are still required for other operations such as
- object uploads and deletes.
- </p>
- </Alert>
- )}
- </div>
- </Modal.Content>
- <button className="hidden" type="submit" onClick={onCreateBucket} />
- </form>
- </Modal>
- )
-}
-
-export default CreateBucketModal
diff --git a/studio/components/to-be-cleaned/Storage/index.ts b/studio/components/to-be-cleaned/Storage/index.ts
index 15a1d10e097..74fd858198e 100644
--- a/studio/components/to-be-cleaned/Storage/index.ts
+++ b/studio/components/to-be-cleaned/Storage/index.ts
@@ -2,7 +2,6 @@ import StorageExplorer from './StorageExplorer/StorageExplorer'
import StoragePolicies from './StoragePolicies/StoragePolicies'
import StorageSettings from './StorageSettings/StorageSettings'
-import CreateBucketModal from './CreateBucketModal'
import DeleteBucketModal from './DeleteBucketModal'
-export { StorageExplorer, StoragePolicies, StorageSettings, CreateBucketModal, DeleteBucketModal }
+export { StorageExplorer, StoragePolicies, StorageSettings, DeleteBucketModal }
diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.js
index 682e71aa5f6..511af472229 100644
--- a/studio/localStores/storageExplorer/StorageExplorerStore.js
+++ b/studio/localStores/storageExplorer/StorageExplorerStore.js
@@ -76,7 +76,6 @@ class StorageExplorerStore {
endpoint = ''
/* FE to toggle page level modals */
- showCreateBucketModal = false
showDeleteBucketModal = false
/* FE Cacheing for file previews */
@@ -183,14 +182,6 @@ class StorageExplorerStore {
this.loaded = val
}
- openCreateBucketModal = () => {
- this.showCreateBucketModal = true
- }
-
- closeCreateBucketModal = () => {
- this.showCreateBucketModal = false
- }
-
openDeleteBucketModal = (bucket) => {
this.selectedBucketToEdit = bucket
this.showDeleteBucketModal = true
@@ -451,11 +442,9 @@ class StorageExplorerStore {
const res = await post(`${this.endpoint}/buckets`, payload)
if (res.error) {
this.ui.setNotification({ category: 'error', message: res.error.message })
- this.closeCreateBucketModal()
- return undefined
+ return res
} else {
await this.fetchBuckets()
- this.closeCreateBucketModal()
return res
}
}
diff --git a/studio/pages/project/[ref]/storage/buckets/[bucketId].tsx b/studio/pages/project/[ref]/storage/buckets/[bucketId].tsx
index 721cd9cc538..1486d50d11a 100644
--- a/studio/pages/project/[ref]/storage/buckets/[bucketId].tsx
+++ b/studio/pages/project/[ref]/storage/buckets/[bucketId].tsx
@@ -24,7 +24,7 @@ const PageLayout: NextPageWithLayout = () => {
const project = ui.selectedProject
const storageStore = useStorageStore()
- const { buckets, loaded, openCreateBucketModal } = storageStore
+ const { buckets, loaded } = storageStore
const kpsEnabled = useFlag('initWithKps')
@@ -43,20 +43,7 @@ const PageLayout: NextPageWithLayout = () => {
{loaded ? (
!bucket ? (
<div className="flex h-full w-full items-center justify-center">
- <ProductEmptyState
- title="Storage"
- ctaButtonLabel="Create a new bucket"
- infoButtonLabel="About storage"
- infoButtonUrl="https://supabase.com/docs/guides/storage"
- onClickCta={openCreateBucketModal}
- >
- <p className="text-scale-1100 text-sm">
- Create buckets to store and serve any type of digital content.
- </p>
- <p className="text-scale-1100 text-sm">
- Make your buckets private or public depending on your security preference.
- </p>
- </ProductEmptyState>
+ <p className="text-sm text-scale-1100">Bucket {bucketId} cannot be found</p>
</div>
) : (
// @ts-ignore
diff --git a/studio/pages/project/[ref]/storage/buckets/index.tsx b/studio/pages/project/[ref]/storage/buckets/index.tsx
index 8f4ad3bba21..8f7212b1d4c 100644
--- a/studio/pages/project/[ref]/storage/buckets/index.tsx
+++ b/studio/pages/project/[ref]/storage/buckets/index.tsx
@@ -1,5 +1,4 @@
import React, { useEffect } from 'react'
-import { useRouter } from 'next/router'
import { observer } from 'mobx-react-lite'
import { API_URL } from 'lib/constants'
@@ -9,10 +8,7 @@ import { post } from 'lib/common/fetch'
import { PROJECT_STATUS } from 'lib/constants'
import { StorageLayout } from 'components/layouts'
import ProductEmptyState from 'components/to-be-cleaned/ProductEmptyState'
-import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'
import { NextPageWithLayout } from 'types'
-import { useProjectApiQuery } from 'data/config/project-api-query'
-import { find } from 'lodash'
/**
* PageLayout is used to setup layout - as usual it will requires inject global store
@@ -21,17 +17,8 @@ const PageLayout: NextPageWithLayout = ({}) => {
const { ref } = useParams()
const { ui } = useStore()
const project = ui.selectedProject
-
- const storageStore = useStorageStore()
- const { openCreateBucketModal } = storageStore
-
const kpsEnabled = useFlag('initWithKps')
- const { data: settings, isLoading } = useProjectApiQuery({ projectRef: ref })
- const apiService = settings?.autoApiService
- const serviceKey = find(apiService?.service_api_keys ?? [], (key) => key.tags === 'service_role')
- const canAccessStorage = !isLoading && apiService && serviceKey !== undefined
-
useEffect(() => {
if (project && project.status === PROJECT_STATUS.INACTIVE) {
post(`${API_URL}/projects/${ref}/restore`, { kps_enabled: kpsEnabled })
@@ -47,9 +34,6 @@ const PageLayout: NextPageWithLayout = ({}) => {
ctaButtonLabel="Create a new bucket"
infoButtonLabel="About storage"
infoButtonUrl="https://supabase.com/docs/guides/storage"
- onClickCta={openCreateBucketModal}
- disabled={!canAccessStorage}
- disabledMessage="You need additional permissions to create buckets"
>
<p className="text-scale-1100 text-sm">
Create buckets to store and serve any type of digital content.