Skip to content

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

Midway updating based on endpoint changes

Joshen Limcc43b2e0e498
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx
index 430de0ce0d3..6c70c5ced6b 100644
--- a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx
+++ b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx
@@ -44,15 +44,6 @@ const ProjectCard = ({
const isPaused = project.status === PROJECT_STATUS.INACTIVE
const isRestoring = project.status === PROJECT_STATUS.RESTORING
- const checkProjectResourceWarnings = (resourceWarnings: ResourceWarning) => {
- return Object.values(resourceWarnings).some(
- (value) => typeof value === 'boolean' && value === true
- )
- }
-
- const projectHasResourceWarnings =
- resourceWarnings !== undefined ? checkProjectResourceWarnings(resourceWarnings) : false
-
return (
<li className="col-span-1 list-none">
<CardButton
@@ -127,7 +118,7 @@ const ProjectCard = ({
</div>
}
>
- {resourceWarnings && projectHasResourceWarnings ? (
+ {resourceWarnings ? (
<ProjectCardWarnings resourceWarnings={resourceWarnings} />
) : (
<div className="py-2" />
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx
index a0d7b2bbd85..7ae429f8976 100644
--- a/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx
+++ b/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx
@@ -5,32 +5,66 @@ export interface ProjectCardWarningsProps {
resourceWarnings: ResourceWarning
}
-// reference for message wording
-// www.notion.so/supabase/Notify-users-on-resource-exhaustion-on-the-dashboard-4bb7b9a990104720b179b7a37d07f41c?pvs=4#a79798b5ac72402e8bfea4c4715e7439
const RESOURCE_WARNING_MESSAGES = {
is_readonly_mode_enabled: {
- title: 'Project is in readonly mode',
- description: 'Database is no longer accept write requests.',
+ warning: {
+ title: 'Project is in readonly mode',
+ description: 'Database is no longer accept write requests.',
+ },
+ critical: {
+ title: 'Project is in readonly mode',
+ description: 'Database is no longer accept write requests.',
+ },
},
- is_disk_io_budget_below_threshold: {
- title: 'Project is depleting its Disk IO Budget',
- description: 'Instance may become unresponsive if fully exhausted.',
+ disk_io_exhaustion: {
+ warning: {
+ title: 'Project is depleting its Disk IO Budget',
+ description: 'Instance may become unresponsive if fully exhausted.',
+ },
+ critical: {
+ title: 'Project has depleted its Disk IO Budget',
+ description: 'Instance may become unresponsive.',
+ },
},
- is_disk_space_usage_beyond_threshold: {
- title: 'Project is exhausting disk space budget',
- description: 'Instance may become unresponsive if fully exhausted.',
+ disk_space_exhaustion: {
+ warning: {
+ title: 'Project is exhausting disk space budget',
+ description: 'Instance may become unresponsive if fully exhausted.',
+ },
+ critical: {
+ title: 'Project has exhausted disk space budget',
+ description: 'Instance may become unresponsive.',
+ },
},
- is_cpu_load_beyond_threshold: {
- title: 'Project has high CPU usage',
- description: `Instance's performance is affected`,
+ cpu_exhaustion: {
+ warning: {
+ title: 'Project has high CPU usage',
+ description: `Instance's performance is affected`,
+ },
+ critical: {
+ title: 'Project CPU usage is at 100%',
+ description: `Instance's performance is affected`,
+ },
},
- is_memory_and_swap_usage_beyond_threshold: {
- title: 'Project has high memory usage',
- description: `Instance's performance is affected.`,
+ memory_and_swap_exhaustion: {
+ warning: {
+ title: 'Project has high memory usage',
+ description: `Instance's performance is affected.`,
+ },
+ critical: {
+ title: 'Project memory usage is at 100%',
+ description: `Instance's performance is affected.`,
+ },
},
multiple_resource_warnings: {
- title: 'Project is exhausting multiple resources',
- description: `Instance's performance is affected.`,
+ warning: {
+ title: 'Project is exhausting multiple resources',
+ description: `Instance's performance is affected.`,
+ },
+ critical: {
+ title: 'Project has exhausted at least one resource',
+ description: `Instance's performance is affected.`,
+ },
},
}
@@ -39,32 +73,54 @@ const ProjectCardWarnings = ({ resourceWarnings }: ProjectCardWarningsProps) =>
const activeWarnings = resourceWarnings.is_readonly_mode_enabled
? ['is_readonly_mode_enabled']
: Object.keys(resourceWarnings).filter(
- (property) => resourceWarnings[property as keyof typeof resourceWarnings] === true
+ (property) =>
+ property !== 'project' &&
+ property !== 'is_readonly_mode_enabled' &&
+ resourceWarnings[property as keyof typeof resourceWarnings] !== null
)
- const hasHighPriorityWarning = activeWarnings.includes('is_readonly_mode_enabled')
+
+ const getContent = (metric: string) => {
+ if (metric === 'is_readonly_mode_enabled') {
+ return RESOURCE_WARNING_MESSAGES.is_readonly_mode_enabled.warning
+ }
+ const severity = resourceWarnings[metric as keyof typeof resourceWarnings]
+ if (typeof severity !== 'string') return undefined
+ return RESOURCE_WARNING_MESSAGES[metric as keyof typeof RESOURCE_WARNING_MESSAGES][
+ severity as 'warning' | 'critical'
+ ]
+ }
+
+ const hasCriticalWarning = activeWarnings.some(
+ (x) => resourceWarnings[x as keyof typeof resourceWarnings] === 'critical'
+ )
+
+ const isCritical = activeWarnings.includes('is_readonly_mode_enabled') || hasCriticalWarning
+
+ if (activeWarnings.length === 0) return <div className="py-2" />
return (
<div>
<Alert_Shadcn_
- variant={hasHighPriorityWarning ? 'destructive' : 'warning'}
+ variant={isCritical ? 'destructive' : 'warning'}
className="border-r-0 border-l-0 rounded-none my-2 mb-2.5"
>
<IconAlertTriangle strokeWidth={2} />
<AlertTitle_Shadcn_ className="text-xs mb-0.5">
{activeWarnings.length > 1
- ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.title
- : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
- ?.title}
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings[
+ hasCriticalWarning ? 'critical' : 'warning'
+ ].title
+ : getContent(activeWarnings[0])?.title}
</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_ className="text-xs">
{activeWarnings.length > 1
- ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.description
- : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
- ?.description}
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings[
+ hasCriticalWarning ? 'critical' : 'warning'
+ ].description
+ : getContent(activeWarnings[0])?.description}
</AlertDescription_Shadcn_>
</Alert_Shadcn_>
- {/* <pre>{JSON.stringify(resourceWarnings, null, 2)}</pre> */}
</div>
)
}
diff --git a/studio/components/ui/UsageWarnings/UsageWarningBanner.constants.ts b/studio/components/ui/UsageWarnings/UsageWarningBanner.constants.ts
index 2ef96fafd7a..2cb01037184 100644
--- a/studio/components/ui/UsageWarnings/UsageWarningBanner.constants.ts
+++ b/studio/components/ui/UsageWarnings/UsageWarningBanner.constants.ts
@@ -1,53 +1,111 @@
-// [TODO] Just double check if the docs url and correction urls are all correct
-// [TODO] Correction URL should depend if V2 or V1 billing
export const RESOURCE_WARNING_MESSAGES = {
is_readonly_mode_enabled: {
- title: 'Your project is currently in readonly mode and is no longer accepting write requests',
- description:
- 'You will need to manually override read-only mode and reduce the disk size to below 95%.',
+ content: {
+ warning: {
+ title:
+ 'Your project is currently in readonly mode and is no longer accepting write requests',
+ description:
+ 'You will need to manually override read-only mode and reduce the disk size to below 95%.',
+ },
+ critical: {
+ title:
+ 'Your project is currently in readonly mode and is no longer accepting write requests',
+ description:
+ 'You will need to manually override read-only mode and reduce the disk size to below 95%.',
+ },
+ },
docsUrl: 'https://supabase.com/docs/guides/platform/database-size#disabling-read-only-mode',
buttonText: undefined,
metric: undefined,
},
- is_disk_io_budget_below_threshold: {
- title:
- 'Your project is about to deplete its Disk IO Budget, and your instance may become unresponsive once fully exhausted',
- description:
- 'You will need to either optimize your performance, or upgrade your compute to a larger instance.',
+ disk_io_exhaustion: {
+ content: {
+ warning: {
+ title:
+ 'Your project is about to deplete its Disk IO Budget, and your instance may become unresponsive once fully exhausted',
+ description:
+ 'You will need to either optimize your performance, or upgrade your compute to a larger instance.',
+ },
+ critical: {
+ title:
+ 'Your project has depleted its Disk IO Budget, and your instance may become unresponsive',
+ description:
+ 'You will need to either optimize your performance, or upgrade your compute to a larger instance.',
+ },
+ },
docsUrl: 'https://supabase.com/docs/guides/platform/exhaust-disk-io',
buttonText: 'Check usage',
metric: 'disk_io',
},
- is_disk_space_usage_beyond_threshold: {
- title:
- 'Your project is about to exhaust its disk space budget, and your instance may become unresponsive once fully exhausted',
- description: 'Some CTA description here',
+ disk_space_exhaustion: {
+ content: {
+ warning: {
+ title:
+ 'Your project is about to exhaust its disk space budget, and your instance may become unresponsive once fully exhausted',
+ description: 'Some CTA description here',
+ },
+ critical: {
+ title:
+ 'Your project has exhausted its disk space budget, and your instance may become unresponsive',
+ description: 'Some CTA description here',
+ },
+ },
docsUrl: undefined,
buttonText: undefined,
metric: undefined,
},
- is_cpu_load_beyond_threshold: {
- title:
- "Your project is currently facing high CPU usage, and your instance's performance is affected",
- description:
- 'You will need to either optimize your performance or upgrade your compute to a larger instance',
+ cpu_exhaustion: {
+ content: {
+ warning: {
+ title:
+ "Your project is currently facing high CPU usage, and your instance's performance is affected",
+ description:
+ 'You will need to either optimize your performance or upgrade your compute to a larger instance',
+ },
+ critical: {
+ title: "Your project's CPU usage is at 100% and your instance's performance is affected",
+ description:
+ 'You will need to either optimize your performance or upgrade your compute to a larger instance',
+ },
+ },
docsUrl: 'https://supabase.com/docs/guides/platform/exhaust-cpu',
buttonText: 'Check usage',
metric: 'cpu',
},
- is_memory_and_swap_usage_beyond_threshold: {
- title:
- "Your project is currently facing high memory usage, and your instance's performance is affected",
- description:
- 'You will need to either optimize your performance or upgrade your compute to a larger instance',
+ memory_and_swap_exhaustion: {
+ content: {
+ warning: {
+ title:
+ "Your project is currently facing high memory usage, and your instance's performance is affected",
+ description:
+ 'You will need to either optimize your performance or upgrade your compute to a larger instance',
+ },
+ critical: {
+ title:
+ "Your project's memory usage is at 100%, and your instance's performance is affected",
+ description:
+ 'You will need to either optimize your performance or upgrade your compute to a larger instance',
+ },
+ },
docsUrl: 'https://supabase.com/docs/guides/platform/exhaust-ram',
buttonText: 'Check usage',
metric: 'ram',
},
multiple_resource_warnings: {
- title:
- "Your project is currently exhausting multiple resources, and your instance's performance is affected",
- description: "Check which resources are reaching their threshold on your project's usage page.",
+ content: {
+ warning: {
+ title:
+ "Your project is currently exhausting multiple resources, and your instance's performance is affected",
+ description:
+ "Check which resources are reaching their threshold on your project's usage page.",
+ },
+ critical: {
+ title:
+ "Your project has exhausted at least one resource, and your instance's performance is affected",
+ description:
+ "Check which resources have reached their threshold on your project's usage page.",
+ },
+ },
docsUrl: undefined,
buttonText: 'Check usage',
metric: null,
diff --git a/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx b/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx
index b000addf113..647882dd84c 100644
--- a/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx
+++ b/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx
@@ -1,5 +1,6 @@
-import Link from 'next/link'
import { useParams } from 'common'
+import Link from 'next/link'
+import { useRouter } from 'next/router'
import {
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
@@ -10,9 +11,8 @@ import {
} from 'ui'
import { useResourceWarningsQuery } from 'data/usage/resource-warnings-query'
-import { RESOURCE_WARNING_MESSAGES } from './UsageWarningBanner.constants'
-import { useRouter } from 'next/router'
import { useSelectedOrganization } from 'hooks'
+import { RESOURCE_WARNING_MESSAGES } from './UsageWarningBanner.constants'
const UsageWarningBanner = () => {
const { ref } = useParams()
@@ -32,22 +32,44 @@ const UsageWarningBanner = () => {
? ['is_readonly_mode_enabled']
: Object.keys(projectResourceWarnings).filter(
(property) =>
- projectResourceWarnings[property as keyof typeof projectResourceWarnings] === true
+ property !== 'project' &&
+ property !== 'is_readonly_mode_enabled' &&
+ projectResourceWarnings[property as keyof typeof projectResourceWarnings] !== null
)
: []
- const hasHighPriorityWarning = activeWarnings.includes('is_readonly_mode_enabled')
+ const hasCriticalWarning =
+ projectResourceWarnings !== undefined
+ ? activeWarnings.some(
+ (x) => projectResourceWarnings[x as keyof typeof projectResourceWarnings] === 'critical'
+ )
+ : false
+ const isCritical = activeWarnings.includes('is_readonly_mode_enabled') || hasCriticalWarning
+
+ const getContent = (metric: string) => {
+ if (projectResourceWarnings === undefined) return undefined
+ if (metric === 'is_readonly_mode_enabled') {
+ return RESOURCE_WARNING_MESSAGES.is_readonly_mode_enabled.content.warning
+ }
+ const severity = projectResourceWarnings[metric as keyof typeof projectResourceWarnings]
+ if (typeof severity !== 'string') return undefined
+ return RESOURCE_WARNING_MESSAGES[metric as keyof typeof RESOURCE_WARNING_MESSAGES].content[
+ severity as 'warning' | 'critical'
+ ]
+ }
const title =
activeWarnings.length > 1
- ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.title
- : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
- ?.title
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.content[
+ hasCriticalWarning ? 'critical' : 'warning'
+ ].title
+ : getContent(activeWarnings[0])?.title
const description =
activeWarnings.length > 1
- ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.description
- : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]
- ?.description
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.content[
+ hasCriticalWarning ? 'critical' : 'warning'
+ ].description
+ : getContent(activeWarnings[0])?.description
const learnMoreUrl =
activeWarnings.length > 1
? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.docsUrl
@@ -85,7 +107,7 @@ const UsageWarningBanner = () => {
return (
<Alert_Shadcn_
- variant={hasHighPriorityWarning ? 'destructive' : 'warning'}
+ variant={isCritical ? 'destructive' : 'warning'}
className="border-l-0 border-r-0 rounded-none"
>
<IconAlertTriangle />
diff --git a/studio/data/api.d.ts b/studio/data/api.d.ts
index 30c7c2551c9..adf68e2f1f7 100644
--- a/studio/data/api.d.ts
+++ b/studio/data/api.d.ts
@@ -214,9 +214,13 @@ export interface paths {
"/platform/organizations/{slug}/billing/subscription": {
/** Gets the current subscription */
get: operations["SubscriptionController_getSubscription"];
- /** Updates subscription */
+ /** Previews subscription change */
put: operations["SubscriptionController_updateSubscription"];
};
+ "/platform/organizations/{slug}/billing/subscription/preview": {
+ /** Updates subscription */
+ post: operations["SubscriptionController_previewSubscriptionChange"];
+ };
"/platform/organizations/{slug}/billing/plans": {
/** Gets subscription plans */
get: operations["OrgPlansController_getAvailablePlans"];
@@ -1643,12 +1647,16 @@ export interface components {
redirectTo?: string;
};
ProjectResourceWarningsResponse: {
+ /** @enum {string|null} */
+ disk_io_exhaustion: "critical" | "warning" | null;
+ /** @enum {string|null} */
+ disk_space_exhaustion: "critical" | "warning" | null;
+ /** @enum {string|null} */
+ cpu_exhaustion: "critical" | "warning" | null;
+ /** @enum {string|null} */
+ memory_and_swap_exhaustion: "critical" | "warning" | null;
project: string;
is_readonly_mode_enabled: boolean;
- is_disk_io_budget_below_threshold: boolean;
- is_disk_space_usage_beyond_threshold: boolean;
- is_cpu_load_beyond_threshold: boolean;
- is_memory_and_swap_usage_beyond_threshold: boolean;
};
GetGoTrueConfigResponse: {
SITE_URL: string;
@@ -1818,6 +1826,8 @@ export interface components {
SMS_PROVIDER?: string;
SMS_MESSAGEBIRD_ACCESS_KEY?: string;
SMS_MESSAGEBIRD_ORIGINATOR?: string;
+ SMS_TEST_OTP?: string;
+ SMS_TEST_OTP_VALID_UNTIL?: string;
SMS_TEXTLOCAL_API_KEY?: string;
SMS_TEXTLOCAL_SENDER?: string;
SMS_TWILIO_ACCOUNT_SID?: string;
@@ -5463,6 +5473,26 @@ export interface operations {
500: never;
};
};
+ /** Updates subscription */
+ SubscriptionController_previewSubscriptionChange: {
+ parameters: {
+ path: {
+ /** @description Organization slug */
+ slug: string;
+ };
+ };
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["UpdateSubscriptionBody"];
+ };
+ };
+ responses: {
+ 201: never;
+ 403: never;
+ /** @description Failed to update subscription */
+ 500: never;
+ };
+ };
/** Gets subscription plans */
OrgPlansController_getAvailablePlans: {
parameters: {
diff --git a/studio/data/usage/resource-warnings-query.ts b/studio/data/usage/resource-warnings-query.ts
index d7ecd7c350e..7249b41e989 100644
--- a/studio/data/usage/resource-warnings-query.ts
+++ b/studio/data/usage/resource-warnings-query.ts
@@ -8,6 +8,25 @@ import { components } from 'data/api'
export async function getResourceWarnings(signal?: AbortSignal) {
const { data, error } = await get(`/platform/projects-resource-warnings`, { signal })
if (error) throw error
+
+ return [
+ {
+ project: 'iqixcyokaezexqncgirb',
+ is_readonly_mode_enabled: false,
+ disk_io_exhaustion: null,
+ disk_space_exhaustion: null,
+ cpu_exhaustion: null,
+ memory_and_swap_exhaustion: null,
+ },
+ {
+ project: 'yhkgeeesimzjzbigwxwv',
+ is_readonly_mode_enabled: false,
+ disk_io_exhaustion: null,
+ disk_space_exhaustion: null,
+ cpu_exhaustion: 'critical',
+ memory_and_swap_exhaustion: null,
+ },
+ ] as ResourceWarning[]
return data
}
diff --git a/studio/pages/projects.tsx b/studio/pages/projects.tsx
index c7e183eced8..909a567dad3 100644
--- a/studio/pages/projects.tsx
+++ b/studio/pages/projects.tsx
@@ -48,7 +48,7 @@ const ProjectsPage: NextPageWithLayout = () => {
</div>
)}
- {isError && (
+ {true && (
<div
className={`py-4 px-5 ${navLayoutV2 ? 'h-full flex items-center justify-center' : ''}`}
>