Skip to content

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

Improve loading states for project settings (#21254)

Joshen Lim7f084ce27b5e
diff --git a/apps/studio/components/interfaces/Auth/BasicAuthSettingsForm/BasicAuthSettingsForm.tsx b/apps/studio/components/interfaces/Auth/BasicAuthSettingsForm/BasicAuthSettingsForm.tsx
index ac78878ccfa..8d4065310f3 100644
--- a/apps/studio/components/interfaces/Auth/BasicAuthSettingsForm/BasicAuthSettingsForm.tsx
+++ b/apps/studio/components/interfaces/Auth/BasicAuthSettingsForm/BasicAuthSettingsForm.tsx
@@ -161,10 +161,6 @@ const BasicAuthSettingsForm = () => {
return (
<>
- <FormHeader
- title="Auth Settings"
- description="Configure security and user session settings."
- />
<FormPanel
disabled={true}
footer={
diff --git a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx b/apps/studio/components/interfaces/Settings/API/ServiceList.tsx
index 33e374feee8..602bb1ef820 100644
--- a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx
+++ b/apps/studio/components/interfaces/Settings/API/ServiceList.tsx
@@ -1,8 +1,10 @@
import { JwtSecretUpdateError, JwtSecretUpdateStatus } from '@supabase/shared-types/out/events'
import { useQueryClient } from '@tanstack/react-query'
+import { useParams } from 'common'
import { useEffect, useRef } from 'react'
+import { Badge, IconAlertCircle, Input } from 'ui'
-import { useParams } from 'common/hooks'
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import DatabaseSelector from 'components/ui/DatabaseSelector'
import Panel from 'components/ui/Panel'
import { DisplayApiSettings } from 'components/ui/ProjectSettings'
@@ -11,17 +13,18 @@ import { configKeys } from 'data/config/keys'
import { useProjectApiQuery } from 'data/config/project-api-query'
import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
-import { useFlag, useSelectedProject, useStore } from 'hooks'
+import { useFlag, useStore } from 'hooks'
import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'
-import { Badge, IconAlertCircle, Input } from 'ui'
import { JWT_SECRET_UPDATE_ERROR_MESSAGES } from './API.constants'
import JWTSettings from './JWTSettings'
import PostgrestConfig from './PostgrestConfig'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import { PROJECT_STATUS } from 'lib/constants'
const ServiceList = () => {
const { ui } = useStore()
const client = useQueryClient()
- const project = useSelectedProject()
+ const { project, isLoading } = useProjectContext()
const { ref: projectRef } = useParams()
const state = useDatabaseSelectorStateSnapshot()
@@ -84,57 +87,73 @@ const ServiceList = () => {
return (
<div>
<h3 className="mb-6 text-xl text-foreground">API Settings</h3>
- <section>
- <Panel
- title={
- <div className="w-full flex items-center justify-between">
- <h5 className="mb-0">Project URL</h5>
- {showReadReplicasUI && <DatabaseSelector />}
- </div>
- }
- >
- <Panel.Content>
- {isError ? (
- <div className="flex items-center justify-center py-4 space-x-2">
- <IconAlertCircle size={16} strokeWidth={1.5} />
- <p className="text-sm text-foreground-light">Failed to retrieve project URL</p>
- </div>
- ) : (
- <Input
- copy
- label={
- isCustomDomainActive ? (
- <div className="flex items-center space-x-2">
- <p>URL</p>
- <Badge>Custom domain active</Badge>
- </div>
- ) : (
- 'URL'
- )
- }
- readOnly
- disabled
- className="input-mono"
- value={endpoint}
- descriptionText="A RESTful endpoint for querying and managing your database."
- layout="horizontal"
- />
- )}
- </Panel.Content>
- </Panel>
- </section>
-
- <section>
- <DisplayApiSettings key="DisplayAPISettings" />
- </section>
-
- <section>
- <JWTSettings />
- </section>
-
- <section>
- <PostgrestConfig />
- </section>
+ {isLoading ? (
+ <GenericSkeletonLoader />
+ ) : project?.status !== PROJECT_STATUS.ACTIVE_HEALTHY ? (
+ <div>
+ <h3 className="mb-6 text-xl text-foreground">API Settings</h3>
+ <div className="flex items-center justify-center rounded border border-overlay bg-surface-100 p-8">
+ <IconAlertCircle strokeWidth={1.5} />
+ <p className="text-sm text-foreground-light ml-2">
+ API settings are unavailable as the project is not active
+ </p>
+ </div>
+ </div>
+ ) : (
+ <>
+ <section>
+ <Panel
+ title={
+ <div className="w-full flex items-center justify-between">
+ <h5 className="mb-0">Project URL</h5>
+ {showReadReplicasUI && <DatabaseSelector />}
+ </div>
+ }
+ >
+ <Panel.Content>
+ {isError ? (
+ <div className="flex items-center justify-center py-4 space-x-2">
+ <IconAlertCircle size={16} strokeWidth={1.5} />
+ <p className="text-sm text-foreground-light">Failed to retrieve project URL</p>
+ </div>
+ ) : (
+ <Input
+ copy
+ label={
+ isCustomDomainActive ? (
+ <div className="flex items-center space-x-2">
+ <p>URL</p>
+ <Badge>Custom domain active</Badge>
+ </div>
+ ) : (
+ 'URL'
+ )
+ }
+ readOnly
+ disabled
+ className="input-mono"
+ value={endpoint}
+ descriptionText="A RESTful endpoint for querying and managing your database."
+ layout="horizontal"
+ />
+ )}
+ </Panel.Content>
+ </Panel>
+ </section>
+
+ <section>
+ <DisplayApiSettings key="DisplayAPISettings" />
+ </section>
+
+ <section>
+ <JWTSettings />
+ </section>
+
+ <section>
+ <PostgrestConfig />
+ </section>
+ </>
+ )}
</div>
)
}
diff --git a/apps/studio/components/interfaces/Settings/Addons/Addons.tsx b/apps/studio/components/interfaces/Settings/Addons/Addons.tsx
index af9fa0a64fb..e8eae68ac94 100644
--- a/apps/studio/components/interfaces/Settings/Addons/Addons.tsx
+++ b/apps/studio/components/interfaces/Settings/Addons/Addons.tsx
@@ -35,7 +35,7 @@ import {
ScaffoldSectionDetail,
} from 'components/layouts/Scaffold'
import AlertError from 'components/ui/AlertError'
-import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import ShimmeringLoader, { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'
import { useProjectSettingsQuery } from 'data/config/project-settings-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
@@ -57,7 +57,7 @@ const Addons = () => {
const { ref: projectRef, panel } = useParams()
const snap = useSubscriptionPageStateSnapshot()
const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
- const { project: selectedProject } = useProjectContext()
+ const { project: selectedProject, isLoading: isLoadingProject } = useProjectContext()
const { data: projectSettings } = useProjectSettingsQuery({ projectRef })
const selectedOrg = useSelectedOrganization()
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: selectedOrg?.slug })
@@ -239,11 +239,15 @@ const Addons = () => {
</div>
<div className="flex-grow">
<p className="text-sm text-foreground-light">Current option:</p>
- <p>
- {computeInstance?.variant.name ??
- capitalize(selectedProject?.infra_compute_size) ??
- 'Micro'}
- </p>
+ {isLoading || (computeInstance === undefined && isLoadingProject) ? (
+ <ShimmeringLoader className="w-32" />
+ ) : (
+ <p>
+ {computeInstance?.variant.name ??
+ capitalize(selectedProject?.infra_compute_size) ??
+ 'Micro'}
+ </p>
+ )}
<ProjectUpdateDisabledTooltip
projectUpdateDisabled={projectUpdateDisabled}
projectNotActive={!isProjectActive}
diff --git a/apps/studio/components/interfaces/Settings/Database/DatabaseSettings/DatabaseSettings.tsx b/apps/studio/components/interfaces/Settings/Database/DatabaseSettings/DatabaseSettings.tsx
index 8dd0f202082..b45be5b8f4c 100644
--- a/apps/studio/components/interfaces/Settings/Database/DatabaseSettings/DatabaseSettings.tsx
+++ b/apps/studio/components/interfaces/Settings/Database/DatabaseSettings/DatabaseSettings.tsx
@@ -69,7 +69,7 @@ const DatabaseSettings = () => {
: isErrorProjectSettings || isErrorPoolingInfo
const isSuccess = showReadReplicasUI
? isSuccessReadReplicas
- : isSuccessProjectSettings || isSuccessPoolingInfo
+ : isSuccessProjectSettings && isSuccessPoolingInfo
const selectedDatabase = (databases ?? []).find(
(db) => db.identifier === state.selectedDatabaseId
diff --git a/apps/studio/components/layouts/ProjectSettingsLayout/SettingsLayout.tsx b/apps/studio/components/layouts/ProjectSettingsLayout/SettingsLayout.tsx
index 248e1ff7772..33dcf5e41e5 100644
--- a/apps/studio/components/layouts/ProjectSettingsLayout/SettingsLayout.tsx
+++ b/apps/studio/components/layouts/ProjectSettingsLayout/SettingsLayout.tsx
@@ -45,6 +45,7 @@ const SettingsLayout = ({ title, children }: PropsWithChildren<SettingsLayoutPro
return (
<ProjectLayout
+ isBlocking={false}
title={title || 'Settings'}
product="Settings"
productMenu={<ProductMenu page={page} menu={menuRoutes} />}
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 d27ac34b5ff..c816fa74fdc 100644
--- a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.tsx
+++ b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.tsx
@@ -1,52 +1,41 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useState } from 'react'
+import { useEffect, useState } from 'react'
import { Button, Form, IconClock, Input, Listbox } from 'ui'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import UpgradeToPro from 'components/ui/UpgradeToPro'
import { useProjectStorageConfigQuery } from 'data/config/project-storage-config-query'
import { useProjectStorageConfigUpdateUpdateMutation } from 'data/config/project-storage-config-update-mutation'
-import { useCheckPermissions, useStore } from 'hooks'
+import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'
import { IS_PLATFORM } from 'lib/constants'
import { StorageSizeUnits, STORAGE_FILE_SIZE_LIMIT_MAX_BYTES } from './StorageSettings.constants'
import { convertFromBytes, convertToBytes } from './StorageSettings.utils'
+import { useParams } from 'common'
+import toast from 'react-hot-toast'
+import AlertError from 'components/ui/AlertError'
+import { FormHeader } from 'components/ui/Forms'
-export type StorageSettingsProps = {
- projectRef: string | undefined
- organizationSlug: string | undefined
-}
-
-const StorageSettings = ({ projectRef, organizationSlug }: StorageSettingsProps) => {
- const { data, error } = useProjectStorageConfigQuery({ projectRef }, { enabled: IS_PLATFORM })
-
- if (error || data?.error) {
- return (
- <div className="p-6 mx-auto text-center sm:w-full md:w-3/4">
- <p className="text-sm">Error loading storage settings</p>
- </div>
- )
- }
-
- if (!data) {
- return (
- <div className="w-full">
- <GenericSkeletonLoader />
- </div>
- )
- }
+const StorageSettings = () => {
+ const { ui } = useStore()
+ const { ref: projectRef } = useParams()
+ const organization = useSelectedOrganization()
+ const organizationSlug = organization?.slug
- return <StorageConfig config={data} projectRef={projectRef} organizationSlug={organizationSlug} />
-}
+ const canUpdateStorageSettings = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
-const StorageConfig = ({ config, projectRef, organizationSlug }: any) => {
- const { fileSizeLimit, isFreeTier } = config
+ const {
+ data: config,
+ error,
+ isLoading,
+ isSuccess,
+ isError,
+ } = useProjectStorageConfigQuery({ projectRef }, { enabled: IS_PLATFORM })
+ const { fileSizeLimit, isFreeTier } = config || {}
const { value, unit } = convertFromBytes(fileSizeLimit)
- const { ui } = useStore()
const [selectedUnit, setSelectedUnit] = useState(unit)
let initialValues = { fileSizeLimit: value, unformattedFileSizeLimit: fileSizeLimit }
- const canUpdateStorageSettings = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
const { mutate: updateStorageConfig, isLoading: isUpdating } =
useProjectStorageConfigUpdateUpdateMutation({
onSuccess: (res) => {
@@ -81,13 +70,12 @@ const StorageConfig = ({ config, projectRef, organizationSlug }: any) => {
}
const onSubmit = async (values: any) => {
+ if (!projectRef) return console.error('Project ref is required')
+
const errors = onValidate(values)
if (errors.fileSizeLimit) {
- return ui.setNotification({
- category: 'error',
- message: `Upload file size limit must be up to 5GB (${formattedMaxSizeBytes})`,
- })
+ return toast.error(`Upload file size limit must be up to 5GB (${formattedMaxSizeBytes})`)
}
updateStorageConfig({
@@ -96,24 +84,42 @@ const StorageConfig = ({ config, projectRef, organizationSlug }: any) => {
})
}
- // [Joshen] To be refactored using FormContainer, FormPanel, FormContent etc once
- // Jonny's auth config refactor PR goes in
return (
<div>
<Form validateOnBlur initialValues={initialValues} validate={onValidate} onSubmit={onSubmit}>
- {({ values, handleReset }: { values: any; handleReset: () => void }) => {
+ {({
+ values,
+ resetForm,
+ handleReset,
+ }: {
+ values: any
+ resetForm: any
+ handleReset: () => void
+ }) => {
const hasChanges =
initialValues.unformattedFileSizeLimit !==
convertToBytes(values.fileSizeLimit, selectedUnit)
+
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ useEffect(() => {
+ resetForm({ values: initialValues, initialValues })
+ }, [isSuccess])
+
return (
<>
- <div className="mb-6">
- <h3 className="mb-2 text-xl text-foreground">Storage Settings</h3>
- <div className="text-sm text-foreground-lighter">
- Configure your project's storage settings
- </div>
- </div>
- <div className="space-y-20">
+ <FormHeader
+ title="Storage Settings"
+ description="Configure your project's storage settings."
+ />
+
+ {isLoading && <GenericSkeletonLoader />}
+ {isError && (
+ <AlertError
+ error={error}
+ subject="Failed to retrieve project's storage configuration"
+ />
+ )}
+ {isSuccess && (
<div
className={[
'bg-surface-100',
@@ -177,9 +183,9 @@ const StorageConfig = ({ config, projectRef, organizationSlug }: any) => {
<div className="px-6 pb-6">
<UpgradeToPro
icon={<IconClock size="large" />}
- organizationSlug={organizationSlug}
+ organizationSlug={organizationSlug ?? ''}
primaryText="Free Plan has a fixed upload file size limit of 50 MB."
- projectRef={projectRef}
+ projectRef={projectRef ?? ''}
secondaryText="Upgrade to the Pro plan for a configurable upload file size limit of up to 5 GB."
/>
</div>
@@ -219,7 +225,7 @@ const StorageConfig = ({ config, projectRef, organizationSlug }: any) => {
</div>
</div>
</div>
- </div>
+ )}
</>
)
}}
diff --git a/apps/studio/components/ui/Forms/FormHeader.tsx b/apps/studio/components/ui/Forms/FormHeader.tsx
index 1e85d6b3862..e860564c56c 100644
--- a/apps/studio/components/ui/Forms/FormHeader.tsx
+++ b/apps/studio/components/ui/Forms/FormHeader.tsx
@@ -6,13 +6,15 @@ const FormHeader = ({
title,
description,
docsUrl,
+ className,
}: {
title: string
description?: string
docsUrl?: string
+ className?: string
}) => {
return (
- <div className="mb-6 flex items-center justify-between">
+ <div className={`mb-6 flex items-center justify-between ${className}`}>
<div className="space-y-1">
<h3 className="text-foreground text-xl">
<ReactMarkdown unwrapDisallowed disallowedElements={['p']}>
diff --git a/apps/studio/data/config/project-storage-config-query.ts b/apps/studio/data/config/project-storage-config-query.ts
index 4322d26c0be..6fdefd55786 100644
--- a/apps/studio/data/config/project-storage-config-query.ts
+++ b/apps/studio/data/config/project-storage-config-query.ts
@@ -2,6 +2,7 @@ import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { configKeys } from './keys'
+import { ResponseError } from 'types'
export type ProjectStorageConfigVariables = {
projectRef?: string
@@ -29,7 +30,7 @@ export async function getProjectStorageConfig(
}
export type ProjectStorageConfigData = Awaited<ReturnType<typeof getProjectStorageConfig>>
-export type ProjectStorageConfigError = unknown
+export type ProjectStorageConfigError = ResponseError
export const useProjectStorageConfigQuery = <TData = ProjectStorageConfigData>(
{ projectRef }: ProjectStorageConfigVariables,
diff --git a/apps/studio/pages/project/[ref]/settings/api.tsx b/apps/studio/pages/project/[ref]/settings/api.tsx
index 2289ea5c7b3..658356e69e4 100644
--- a/apps/studio/pages/project/[ref]/settings/api.tsx
+++ b/apps/studio/pages/project/[ref]/settings/api.tsx
@@ -1,32 +1,14 @@
-import { IconAlertCircle } from 'ui'
-
import ServiceList from 'components/interfaces/Settings/API/ServiceList'
import { SettingsLayout } from 'components/layouts'
-import { useIsProjectActive } from 'components/layouts/ProjectLayout/ProjectContext'
import { NextPageWithLayout } from 'types'
const ApiSettings: NextPageWithLayout = () => {
- const isActive = useIsProjectActive()
-
return (
<div className="flex flex-col gap-8 px-5 py-6 mx-auto 1xl:px-28 lg:px-16 xl:px-24 2xl:px-32">
- {isActive ? (
- <ServiceList />
- ) : (
- <div>
- <h3 className="mb-6 text-xl text-foreground">API Settings</h3>
- <div className="flex items-center justify-center rounded border border-overlay bg-surface-100 p-8">
- <IconAlertCircle strokeWidth={1.5} />
- <p className="text-sm text-foreground-light ml-2">
- API settings are unavailable as the project is not active
- </p>
- </div>
- </div>
- )}
+ <ServiceList />
</div>
)
}
ApiSettings.getLayout = (page) => <SettingsLayout title="API Settings">{page}</SettingsLayout>
-
export default ApiSettings
diff --git a/apps/studio/pages/project/[ref]/settings/auth.tsx b/apps/studio/pages/project/[ref]/settings/auth.tsx
index ae125ab2768..a96017e7b15 100644
--- a/apps/studio/pages/project/[ref]/settings/auth.tsx
+++ b/apps/studio/pages/project/[ref]/settings/auth.tsx
@@ -6,28 +6,37 @@ import {
AdvancedAuthSettingsForm,
} from 'components/interfaces/Auth'
import { SettingsLayout } from 'components/layouts'
+import { FormHeader } from 'components/ui/Forms'
import NoPermission from 'components/ui/NoPermission'
-import { useCheckPermissions } from 'hooks'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import { useCheckPermissions, usePermissionsLoaded } from 'hooks'
import { NextPageWithLayout } from 'types'
-const PageLayout: NextPageWithLayout = () => {
+const AuthSettings: NextPageWithLayout = () => {
+ const isPermissionsLoaded = usePermissionsLoaded()
const canReadAuthSettings = useCheckPermissions(PermissionAction.READ, 'custom_config_gotrue')
- if (!canReadAuthSettings) {
- return <NoPermission isFullPage resourceText="access your project's authentication settings" />
- } else {
- return (
- <div className="1xl:px-28 mx-auto flex flex-col gap-8 px-5 py-6 lg:px-16 xl:px-24 2xl:px-32">
- <BasicAuthSettingsForm />
- <SmtpForm />
- <AdvancedAuthSettingsForm />
- </div>
- )
- }
+ return (
+ <div className="1xl:px-28 mx-auto flex flex-col gap-8 px-5 py-6 lg:px-16 xl:px-24 2xl:px-32">
+ <FormHeader
+ className="!mb-0"
+ title="Auth Settings"
+ description="Configure security and user session settings."
+ />
+ {!isPermissionsLoaded ? (
+ <GenericSkeletonLoader />
+ ) : !canReadAuthSettings ? (
+ <NoPermission isFullPage resourceText="access your project's authentication settings" />
+ ) : (
+ <>
+ <BasicAuthSettingsForm />
+ <SmtpForm />
+ <AdvancedAuthSettingsForm />
+ </>
+ )}
+ </div>
+ )
}
-PageLayout.getLayout = (page) => {
- return <SettingsLayout>{page}</SettingsLayout>
-}
-
-export default PageLayout
+AuthSettings.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>
+export default AuthSettings
diff --git a/apps/studio/pages/project/[ref]/settings/integrations.tsx b/apps/studio/pages/project/[ref]/settings/integrations.tsx
index 03a074c5f88..bb9bbc89de2 100644
--- a/apps/studio/pages/project/[ref]/settings/integrations.tsx
+++ b/apps/studio/pages/project/[ref]/settings/integrations.tsx
@@ -7,5 +7,4 @@ const OrgIntegrationSettings: NextPageWithLayout = () => {
}
OrgIntegrationSettings.getLayout = (page) => <SettingsLayout>{page}</SettingsLayout>
-
export default OrgIntegrationSettings
diff --git a/apps/studio/pages/project/[ref]/settings/storage.tsx b/apps/studio/pages/project/[ref]/settings/storage.tsx
index cbfdd992d1d..96caad2fbdb 100644
--- a/apps/studio/pages/project/[ref]/settings/storage.tsx
+++ b/apps/studio/pages/project/[ref]/settings/storage.tsx
@@ -1,21 +1,14 @@
-import { useParams } from 'common'
-
import { SettingsLayout } from 'components/layouts'
import { StorageSettings } from 'components/to-be-cleaned/Storage'
-import { useSelectedOrganization } from 'hooks'
import { NextPageWithLayout } from 'types'
const PageLayout: NextPageWithLayout = () => {
- const { ref: projectRef } = useParams()
- const organization = useSelectedOrganization()
-
return (
<div className="1xl:px-28 mx-auto flex flex-col gap-8 px-5 py-6 lg:px-16 xl:px-24 2xl:px-32">
- <StorageSettings projectRef={projectRef} organizationSlug={organization?.slug} />
+ <StorageSettings />
</div>
)
}
PageLayout.getLayout = (page) => <SettingsLayout title="Settings">{page}</SettingsLayout>
-
export default PageLayout