Skip to content

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

Chore/restrict banner to select routes (#29649)

Terry Sutton12b7eab22992
diff --git a/apps/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsx b/apps/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsx
index b74540f5fbe..38b007ba75b 100644
--- a/apps/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsx
+++ b/apps/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsx
@@ -12,11 +12,21 @@ export interface ProjectCardWarningsProps {
}
export const ProjectCardStatus = ({
- resourceWarnings,
+ resourceWarnings: allResourceWarnings,
projectStatus,
}: ProjectCardWarningsProps) => {
const showResourceExhaustionWarnings = false
+ // [Terry] temp to remove auth_restricted_email_sending property from resourceWarnings
+ // set auth_restricted_email_sending from 'warning' to null so it doesn't show up in the warning banner
+ // [Joshen] Can remove this eventually once the auth email thing is resolved (Nov 2024)
+ const resourceWarnings = allResourceWarnings
+ ? {
+ ...allResourceWarnings,
+ auth_restricted_email_sending: null,
+ }
+ : undefined
+
// [Joshen] Read only takes higher precedence over multiple resource warnings
const activeWarnings = resourceWarnings?.is_readonly_mode_enabled
? ['is_readonly_mode_enabled']
diff --git a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts
index 41b756a1d32..1ae5e0d4f5f 100644
--- a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts
+++ b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts
@@ -1,6 +1,9 @@
const AFTER_26_09_2024 = Date.now() >= new Date('2024-09-26T00:00:00Z').getTime()
interface ResourceWarningMessage {
+ // should match pathnames, ex: ('/', 'project/[ref]/auth', 'project/[ref]/database', '/project/[ref]/settings/auth')
+ restrictToRoutes?: string[]
+
bannerContent: {
warning: { title: string; description: string }
critical: { title?: string; description?: string }
@@ -212,6 +215,7 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =
metric: null,
},
auth_restricted_email_sending: {
+ restrictToRoutes: ['/project/[ref]', '/project/[ref]/auth', '/project/[ref]/settings/auth'], // project home, auth, settings
bannerContent: {
warning: {
title: AFTER_26_09_2024
diff --git a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx
index 912f31856ba..65eee860ab5 100644
--- a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx
+++ b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx
@@ -15,7 +15,6 @@ const ResourceExhaustionWarningBanner = () => {
const projectResourceWarnings = (resourceWarnings ?? [])?.find(
(warning) => warning.project === ref
)
-
// [Joshen] Read only takes higher precedence over multiple resource warnings
const activeWarnings =
projectResourceWarnings !== undefined
@@ -68,19 +67,25 @@ const ResourceExhaustionWarningBanner = () => {
: RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
?.metric
- const correctionUrl = (
- metric === undefined
- ? undefined
- : metric === null
- ? '/project/[ref]/settings/[infra-path]'
- : metric === 'disk_space' || metric === 'read_only'
- ? '/project/[ref]/settings/database'
- : metric === 'auth_email_rate_limit'
- ? '/project/[ref]/settings/auth'
- : metric === 'auth_restricted_email_sending'
- ? `/project/[ref]/settings/auth`
- : `/project/[ref]/settings/[infra-path]#${metric}`
- )
+ const correctionUrlVariants = {
+ undefined: undefined,
+ null: '/project/[ref]/settings/[infra-path]',
+ disk_space: '/project/[ref]/settings/database',
+ read_only: '/project/[ref]/settings/database',
+ auth_email_rate_limit: '/project/[ref]/settings/auth',
+ auth_restricted_email_sending: '/project/[ref]/settings/auth',
+ default: (metric: string) => `/project/[ref]/settings/[infra-path]#${metric}`,
+ }
+
+ const getCorrectionUrl = (metric: string | undefined | null) => {
+ const variant = metric === undefined ? 'undefined' : metric === null ? 'null' : metric
+ const url =
+ correctionUrlVariants[variant as keyof typeof correctionUrlVariants] ||
+ correctionUrlVariants.default(metric as string)
+ return typeof url === 'function' ? url(metric as string) : url
+ }
+
+ const correctionUrl = getCorrectionUrl(metric)
?.replace('[ref]', ref ?? 'default')
?.replace('[infra-path]', 'infrastructure')
@@ -90,14 +95,42 @@ const ResourceExhaustionWarningBanner = () => {
: RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
?.buttonText
- // Don't show banner if no warnings, or on usage/infra page
+ const hasNoWarnings = activeWarnings.length === 0
+ const hasNoWarningContent = warningContent === undefined
+ const isUsageOrInfraPage =
+ router.pathname.endsWith('/usage') || router.pathname.endsWith('/infrastructure')
+ const onUsageOrInfraAndNotInReadOnlyMode =
+ isUsageOrInfraPage && !activeWarnings.includes('is_readonly_mode_enabled')
+ const onDatabaseSettingsAndInReadOnlyMode =
+ router.pathname.endsWith('settings/database') &&
+ activeWarnings.includes('is_readonly_mode_enabled')
+
+ // these take precedence over each other, so there's only one active warning to check
+ const activeWarning =
+ RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
+ const restrictToRoutes = activeWarning?.restrictToRoutes
+
+ const isVisible =
+ restrictToRoutes === undefined ||
+ restrictToRoutes.some((route: string) => {
+ // check for exact match with /project/[ref] (project home) first
+ // doing this let's us avoid checking with regex, keeping it simple
+ if (route === '/project/[ref]') {
+ const isExactMatch = router.pathname === '/project/[ref]'
+ return isExactMatch
+ }
+
+ // For other routes, use the original startsWith logic
+ const isMatch = router.pathname.startsWith(route)
+ return isMatch
+ })
+
if (
- activeWarnings.length === 0 ||
- warningContent === undefined ||
- ((router.pathname.endsWith('/usage') || router.pathname.endsWith('/infrastructure')) &&
- !activeWarnings.includes('is_readonly_mode_enabled')) ||
- (activeWarnings.includes('is_readonly_mode_enabled') &&
- router.pathname.endsWith('settings/database'))
+ hasNoWarnings ||
+ hasNoWarningContent ||
+ onUsageOrInfraAndNotInReadOnlyMode ||
+ onDatabaseSettingsAndInReadOnlyMode ||
+ !isVisible
) {
return null
}