Skip to content

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

Dynamically render S3 protocol settings (#32589)

Joshen Limffde1dc84144
diff --git a/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx b/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx
index cf853511973..35403e46c58 100644
--- a/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx
+++ b/apps/studio/components/interfaces/Settings/General/Infrastructure/RestartServerButton.tsx
@@ -1,5 +1,6 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useQueryClient } from '@tanstack/react-query'
+import { ChevronDown } from 'lucide-react'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { toast } from 'sonner'
@@ -13,7 +14,6 @@ import { useProjectRestartServicesMutation } from 'data/projects/project-restart
import { setProjectStatus } from 'data/projects/projects-query'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useFlag } from 'hooks/ui/useFlag'
-import { ChevronDown } from 'lucide-react'
import {
Button,
DropdownMenu,
@@ -23,6 +23,7 @@ import {
TooltipContent_Shadcn_,
TooltipTrigger_Shadcn_,
Tooltip_Shadcn_,
+ cn,
} from 'ui'
import ConfirmModal from 'ui-patterns/Dialogs/ConfirmDialog'
@@ -92,7 +93,10 @@ const RestartServerButton = () => {
<div className="flex items-center">
<Button
type="default"
- className={`px-3 ${canRestartProject && isProjectActive ? 'rounded-r-none' : ''}`}
+ className={cn(
+ 'px-3 hover:z-10',
+ canRestartProject && isProjectActive ? 'rounded-r-none' : ''
+ )}
disabled={
project === undefined ||
!canRestartProject ||
@@ -108,7 +112,7 @@ const RestartServerButton = () => {
<DropdownMenuTrigger asChild>
<Button
type="default"
- className="rounded-l-none px-[4px] py-[5px]"
+ className="rounded-l-none px-[4px] py-[5px] -ml-[1px]"
icon={<ChevronDown />}
disabled={!canRestartProject}
/>
diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/CreateCredentialModal.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/CreateCredentialModal.tsx
index 133a33ade14..2df994c711e 100644
--- a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/CreateCredentialModal.tsx
+++ b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/CreateCredentialModal.tsx
@@ -7,6 +7,7 @@ import { z } from 'zod'
import { FormField } from '@ui/components/shadcn/ui/form'
import { useParams } from 'common'
import { useIsProjectActive } from 'components/layouts/ProjectLayout/ProjectContext'
+import { useProjectStorageConfigQuery } from 'data/config/project-storage-config-query'
import { useS3AccessKeyCreateMutation } from 'data/storage/s3-access-key-create-mutation'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import {
@@ -27,8 +28,6 @@ import {
} from 'ui'
import { Input } from 'ui-patterns/DataInputs/Input'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
-import { useProjectStorageConfigQuery } from 'data/config/project-storage-config-query'
-import { ButtonTooltip } from 'components/ui/ButtonTooltip'
interface CreateCredentialModalProps {
visible: boolean
@@ -43,7 +42,8 @@ export const CreateCredentialModal = ({ visible, onOpenChange }: CreateCredentia
const canCreateCredentials = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
const { data: config } = useProjectStorageConfigQuery({ projectRef })
- const isS3ConnectionEnabled = config?.features.s3Protocol.enabled
+ // [Joshen clean up] Remove ?? true once storage BE changes are deployed
+ const isS3ConnectionEnabled = config?.features.s3Protocol?.enabled ?? true
const disableCreation = !isProjectActive || !canCreateCredentials || !isS3ConnectionEnabled
const FormSchema = z.object({
diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/S3Connection.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/S3Connection.tsx
index 41841dbd9d2..21feb7436f7 100644
--- a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/S3Connection.tsx
+++ b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/S3Connection.tsx
@@ -84,6 +84,9 @@ export const S3Connection = () => {
const hasStorageCreds = storageCreds?.data && storageCreds.data.length > 0
const s3connectionUrl = getConnectionURL(projectRef ?? '', protocol, endpoint)
+ // [Joshen clean up]: Can remove this boolean check once storage changes are deployed
+ const hasS3ProtocolFeature = config?.features.s3Protocol !== undefined
+
const onSubmit: SubmitHandler<z.infer<typeof FormSchema>> = async (data) => {
if (!projectRef) return console.error('Project ref is required')
if (!config) return console.error('Storage config is required')
@@ -97,7 +100,9 @@ export const S3Connection = () => {
}
useEffect(() => {
- form.reset({ s3ConnectionEnabled: config?.features.s3Protocol.enabled })
+ if (hasS3ProtocolFeature) {
+ form.reset({ s3ConnectionEnabled: config?.features.s3Protocol.enabled })
+ }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSuccessStorageConfig])
@@ -114,39 +119,43 @@ export const S3Connection = () => {
<GenericSkeletonLoader />
) : isProjectActive ? (
<Panel className="!mb-0">
- <FormField_Shadcn_
- name="s3ConnectionEnabled"
- control={form.control}
- render={({ field }) => (
- <FormItemLayout
- layout="horizontal"
- className="px-8 py-8 [&>*>label]:text-foreground"
- label="Enable connection via S3 protocol"
- description="Allow clients to connect to Supabase Storage via the S3 protocol"
- >
- <FormControl_Shadcn_>
- <Switch
- size="large"
- checked={field.value}
- onCheckedChange={field.onChange}
- disabled={!isSuccessStorageConfig || field.disabled}
+ {hasS3ProtocolFeature && (
+ <>
+ <FormField_Shadcn_
+ name="s3ConnectionEnabled"
+ control={form.control}
+ render={({ field }) => (
+ <FormItemLayout
+ layout="horizontal"
+ className="px-8 py-8 [&>*>label]:text-foreground"
+ label="Enable connection via S3 protocol"
+ description="Allow clients to connect to Supabase Storage via the S3 protocol"
+ >
+ <FormControl_Shadcn_>
+ <Switch
+ size="large"
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ disabled={!isSuccessStorageConfig || field.disabled}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ {isErrorStorageConfig && (
+ <div className="px-8 pb-8">
+ <AlertError
+ subject="Failed to retrieve storage configuration"
+ error={configError}
/>
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
+ </div>
+ )}
- {isErrorStorageConfig && (
- <div className="px-8 pb-8">
- <AlertError
- subject="Failed to retrieve storage configuration"
- error={configError}
- />
- </div>
+ <Separator className="bg-border" />
+ </>
)}
- <Separator className="bg-border" />
-
<div className="flex flex-col gap-y-4 py-8">
<FormItemLayout
layout="horizontal"
@@ -168,35 +177,43 @@ export const S3Connection = () => {
)}
</div>
- <Separator />
+ {hasS3ProtocolFeature && (
+ <>
+ <Separator />
- <div className="flex items-center justify-between w-full gap-2 px-8 py-4">
- {!canUpdateStorageSettings ? (
- <p className="text-sm text-foreground-light">
- You need additional permissions to update storage settings
- </p>
- ) : (
- <div />
- )}
- <div className="flex gap-2">
- <Button
- type="default"
- htmlType="reset"
- onClick={() => form.reset()}
- disabled={!form.formState.isDirty || !canUpdateStorageSettings || isUpdating}
- >
- Cancel
- </Button>
- <Button
- type="primary"
- htmlType="submit"
- loading={isUpdating}
- disabled={!form.formState.isDirty || !canUpdateStorageSettings || isUpdating}
- >
- Save
- </Button>
- </div>
- </div>
+ <div className="flex items-center justify-between w-full gap-2 px-8 py-4">
+ {!canUpdateStorageSettings ? (
+ <p className="text-sm text-foreground-light">
+ You need additional permissions to update storage settings
+ </p>
+ ) : (
+ <div />
+ )}
+ <div className="flex gap-2">
+ <Button
+ type="default"
+ htmlType="reset"
+ onClick={() => form.reset()}
+ disabled={
+ !form.formState.isDirty || !canUpdateStorageSettings || isUpdating
+ }
+ >
+ Cancel
+ </Button>
+ <Button
+ type="primary"
+ htmlType="submit"
+ loading={isUpdating}
+ disabled={
+ !form.formState.isDirty || !canUpdateStorageSettings || isUpdating
+ }
+ >
+ Save
+ </Button>
+ </div>
+ </div>
+ </>
+ )}
</Panel>
) : (
<Alert_Shadcn_ variant="warning">
diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.tsx
index 5ad69e661f2..b93787e3534 100644
--- a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.tsx
+++ b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.tsx
@@ -17,7 +17,6 @@ import { useProjectStorageConfigUpdateUpdateMutation } from 'data/config/project
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
-import { IS_PLATFORM } from 'lib/constants'
import {
Button,
FormControl_Shadcn_,
@@ -132,9 +131,12 @@ const StorageSettings = () => {
updateStorageConfig({
projectRef,
fileSizeLimit: convertToBytes(data.fileSizeLimit, data.unit),
+ // @ts-ignore [Joshen clean up] Remove this once storage changes are deployed'
features: {
imageTransformation: { enabled: data.imageTransformationEnabled },
- s3Protocol: config.features.s3Protocol,
+ ...(config.features.s3Protocol !== undefined
+ ? { s3Protocol: config?.features.s3Protocol }
+ : {}),
},
})
}