The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Combine project status with resource warnings
Terry Sutton1068773733ee
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsxindex bf101db33cd..9d3f44c63ec 100644--- a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx+++ b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx@@ -1,19 +1,12 @@-import {- Badge,- IconAlertTriangle,- IconGitBranch,- IconGitHub,- IconLoader,- IconPauseCircle,-} from 'ui'+import { IconGitBranch, IconGitHub } from 'ui'import CardButton from 'components/ui/CardButton'import { BASE_PATH, PROJECT_STATUS } from 'lib/constants'import { Project } from 'types'import { IntegrationProjectConnection } from 'data/integrations/integrations.types'import { ResourceWarning } from 'data/usage/resource-warnings-query'-import ProjectCardWarnings from './ProjectCardWarnings'import { useFlag } from 'hooks'+import { ProjectCardStatus } from './ProjectCardStatus'export interface ProjectCardProps {project: Project@@ -23,6 +16,32 @@ export interface ProjectCardProps {resourceWarnings?: ResourceWarning}+const getProjetStatus = (project: Project) => {+ let status+ switch (project.status) {+ case PROJECT_STATUS.ACTIVE_HEALTHY:+ status = 'isHealthy'+ break+ case PROJECT_STATUS.GOING_DOWN:+ case PROJECT_STATUS.PAUSING:+ status = 'isPausing'+ break+ case PROJECT_STATUS.INACTIVE:+ status = 'isPaused'+ break+ case PROJECT_STATUS.RESTORING:+ status = 'isRestoring'+ break+ case PROJECT_STATUS.UNKNOWN:+ case PROJECT_STATUS.COMING_UP:+ status = 'isComingUp'+ break+ default:+ status = ''+ }+ return status+}+const ProjectCard = ({project,rewriteHref,@@ -33,21 +52,11 @@ const ProjectCard = ({const { name, ref: projectRef } = projectconst desc = `${project.cloud_provider} | ${project.region}`- const showResourceExhaustionWarnings = useFlag('resourceExhaustionWarnings')-const isBranchingEnabled = project.preview_branch_refs.length > 0const isGithubIntegrated = githubIntegration !== undefinedconst isVercelIntegrated = vercelIntegration !== undefinedconst githubRepository = githubIntegration?.metadata.name ?? undefined-- // Project status should supersede its read only status- const isHealthy = project.status === PROJECT_STATUS.ACTIVE_HEALTHY- const isPausing =- project.status === PROJECT_STATUS.GOING_DOWN || project.status === PROJECT_STATUS.PAUSING- const isPaused = project.status === PROJECT_STATUS.INACTIVE- const isRestoring = project.status === PROJECT_STATUS.RESTORING- const isComingUp =- project.status === PROJECT_STATUS.UNKNOWN || project.status === PROJECT_STATUS.COMING_UP+ const projectStatus = getProjetStatus(project)return (<li className="col-span-1 list-none">@@ -56,7 +65,8 @@ const ProjectCard = ({containerHeightClassName="h-48"title={<div className="w-full justify-between space-y-1.5 px-6">- <p className="flex-shrink truncate">{name}</p>+ <p className="flex-shrink truncate text-sm">{name}</p>+ <span className="text-xs lowercase text-scale-1000">{desc}</span><div className="flex items-center space-x-1.5">{isVercelIntegrated && (<div className="w-fit p-1 border rounded-md flex items-center border-scale-600">@@ -84,61 +94,16 @@ const ProjectCard = ({</div>}footer={- <div className="flex items-end justify-between px-6">- <span className="text-xs lowercase text-scale-1000">{desc}</span>-- {isHealthy && (- <Badge color="green">- <div className="flex items-center gap-2">- <span className="truncate">Active</span>- </div>- </Badge>- )}-- {isRestoring && (- <Badge color="brand">- <div className="flex items-center gap-2">- <IconLoader className="animate-spin" size={14} strokeWidth={2} />- <span className="truncate">Restoring</span>- </div>- </Badge>- )}-- {isPausing && (- <Badge color="scale">- <div className="flex items-center gap-2">- <IconLoader className="animate-spin" size={14} strokeWidth={2} />- <span className="truncate">Pausing</span>- </div>- </Badge>- )}-- {isPaused && (- <Badge color="scale">- <div className="flex items-center gap-2">- <IconPauseCircle size={14} strokeWidth={2} />- <span className="truncate">Paused</span>- </div>- </Badge>- )}-- {isComingUp && (- <Badge color="scale">- <div className="flex items-center gap-2">- <IconLoader className="animate-spin" size={14} strokeWidth={2} />- <span className="truncate">Coming up</span>- </div>- </Badge>+ <div className="mb-[-26px]">+ {resourceWarnings && (+ <ProjectCardStatus+ projectStatus={projectStatus}+ resourceWarnings={resourceWarnings}+ />)}</div>}- >- {showResourceExhaustionWarnings && resourceWarnings ? (- <ProjectCardWarnings resourceWarnings={resourceWarnings} />- ) : (- <div className="py-2" />- )}- </CardButton>+ ></CardButton></li>)}diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsxnew file mode 100644index 00000000000..e04a27d4bcb--- /dev/null+++ b/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsx@@ -0,0 +1,134 @@+import { RESOURCE_WARNING_MESSAGES } from 'components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants'+import { ResourceWarning } from 'data/usage/resource-warnings-query'+import {+ Alert_Shadcn_,+ AlertDescription_Shadcn_,+ AlertTitle_Shadcn_,+ IconAlertTriangle,+ IconLoader,+ IconPauseCircle,+} from 'ui'++export interface ProjectCardWarningsProps {+ resourceWarnings: ResourceWarning+ projectStatus: string+}++export const ProjectCardStatus = ({+ resourceWarnings,+ projectStatus,+}: ProjectCardWarningsProps) => {+ //const showResourceExhaustionWarnings = useFlag('resourceExhaustionWarnings')+ const showResourceExhaustionWarnings = false++ // [Joshen] Read only takes higher precedence over multiple resource warnings+ const activeWarnings = resourceWarnings.is_readonly_mode_enabled+ ? ['is_readonly_mode_enabled']+ : Object.keys(resourceWarnings).filter(+ (property) =>+ property !== 'project' &&+ property !== 'is_readonly_mode_enabled' &&+ resourceWarnings[property as keyof typeof resourceWarnings] !== null+ )++ const getContent = (metric: string) => {+ if (metric === 'is_readonly_mode_enabled') {+ return RESOURCE_WARNING_MESSAGES.is_readonly_mode_enabled.cardContent.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][+ 'cardContent'+ ][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++ const getWarningType = () => {+ let type = 'default'++ switch (true) {+ case projectStatus === 'isPaused':+ type = 'default'+ break+ case isCritical:+ type = 'destructive'+ break+ default:+ type = 'warning'+ break+ }++ return type as 'warning' | 'destructive' | 'default'+ }++ const AlertIcon = () => {+ switch (true) {+ case projectStatus === 'isPaused' || projectStatus === 'isPausing':+ return <IconPauseCircle strokeWidth={2} />+ case projectStatus === 'isRestoring' || projectStatus === 'isComingUp':+ return <IconLoader size={14} strokeWidth={2} />+ default:+ return <IconAlertTriangle strokeWidth={2} />+ }+ }+ const getTitle = () => {+ if (projectStatus === 'isPaused') return 'Project is paused'+ if (projectStatus === 'isPausing') return 'Project is pausing'+ if (projectStatus === 'isComingUp') return 'Project is coming up'+ if (projectStatus === 'isRestoring') return 'Project is restoring'++ // If none of the paused/restoring states match, proceed with the default logic+ return activeWarnings.length > 1+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.cardContent[+ hasCriticalWarning ? 'critical' : 'warning'+ ].title+ : getContent(activeWarnings[0])?.title+ }++ const getDescription = () => {+ if (projectStatus === 'isPaused')+ return 'This project will not accept any requests until unpaused.'+ if (projectStatus === 'isPausing')+ return 'This project is entering a paused state. This may take a few minutes.'+ if (projectStatus === 'isComingUp')+ return 'This project is coming up. This may take a few minutes.'+ if (projectStatus === 'isRestoring')+ return 'This project is restoring. This may take a few minutes.'++ // If none of the paused/restoring states match, proceed with the default logic+ return activeWarnings.length > 1 && showResourceExhaustionWarnings+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.cardContent[+ hasCriticalWarning ? 'critical' : 'warning'+ ].description+ : getContent(activeWarnings[0])?.description+ }++ const alertTitle = getTitle()+ const alertDescription = getDescription()+ const alertType = getWarningType()++ if (activeWarnings.length === 0 && projectStatus === 'isHealthy') return <div className="py-2" />++ return (+ <div>+ <Alert_Shadcn_+ variant={alertType}+ className="border-0 rounded-none rounded-b-md my-2 mb-2.5 [&>svg]:w-[28px]+[&>svg]:h-[28px] [&>svg]:p-1.5 [&>svg]:left-6 pl-6"+ >+ <AlertIcon />++ <AlertTitle_Shadcn_ className="text-xs mb-0.5">{alertTitle}</AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_ className="text-xs">{alertDescription}</AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ </div>+ )+}diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsxdeleted file mode 100644index a07d41ff3b1..00000000000--- a/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx+++ /dev/null@@ -1,129 +0,0 @@-import { ResourceWarning } from 'data/usage/resource-warnings-query'-import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_, IconAlertTriangle } from 'ui'--export interface ProjectCardWarningsProps {- resourceWarnings: ResourceWarning-}--const RESOURCE_WARNING_MESSAGES = {- is_readonly_mode_enabled: {- 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.',- },- },- 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.',- },- },- 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.',- },- },- 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`,- },- },- 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: {- 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.`,- },- },-}--const ProjectCardWarnings = ({ resourceWarnings }: ProjectCardWarningsProps) => {- // [Joshen] Read only takes higher precedence over multiple resource warnings- const activeWarnings = resourceWarnings.is_readonly_mode_enabled- ? ['is_readonly_mode_enabled']- : Object.keys(resourceWarnings).filter(- (property) =>- property !== 'project' &&- property !== 'is_readonly_mode_enabled' &&- resourceWarnings[property as keyof typeof resourceWarnings] !== null- )-- 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={isCritical ? 'destructive' : 'warning'}- className="border-0 rounded-none my-2 mb-2.5 [&>svg]:w-[28px]-[&>svg]:h-[28px] [&>svg]:p-1.5 [&>svg]:left-6 pl-6"- >- <IconAlertTriangle strokeWidth={2} />-- <AlertTitle_Shadcn_ className="text-xs mb-0.5">- {activeWarnings.length > 1- ? 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[- hasCriticalWarning ? 'critical' : 'warning'- ].description- : getContent(activeWarnings[0])?.description}- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- </div>- )-}--export default ProjectCardWarningsdiff --git a/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts b/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.tsindex 5e54f833199..49fd1ada259 100644--- a/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts+++ b/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts@@ -1,17 +1,27 @@export const RESOURCE_WARNING_MESSAGES = {is_readonly_mode_enabled: {- content: {+ bannerContent: {warning: {title:'Your project is currently in read-only 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%.',+ 'You will need to manually override read-only mode and reduce the disk size to below 95%',},critical: {title:'Your project is currently in read-only 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%.',+ 'You will need to manually override read-only mode and reduce the disk size to below 95%',+ },+ },+ cardContent: {+ warning: {+ title: 'Project is in read-only mode',+ description: 'Database is no longer accepting write requests.',+ },+ critical: {+ title: 'Project is in read-only mode',+ description: 'Database is no longer accepting write requests.',},},docsUrl: 'https://supabase.com/docs/guides/platform/database-size#disabling-read-only-mode',@@ -19,7 +29,7 @@ export const RESOURCE_WARNING_MESSAGES = {metric: undefined,},disk_io_exhaustion: {- content: {+ bannerContent: {warning: {title:'Your project is about to deplete its Disk IO Budget, and may become unresponsive once fully exhausted',@@ -32,12 +42,22 @@ export const RESOURCE_WARNING_MESSAGES = {'You will need to either optimize your performance, or upgrade your compute to a larger plan.',},},+ cardContent: {+ warning: {+ title: 'Project is depleting its Disk IO Budget',+ description: 'Project may become unresponsive if fully exhausted.',+ },+ critical: {+ title: 'Project has depleted its Disk IO Budget',+ description: 'Project may become unresponsive',+ },+ },docsUrl: 'https://supabase.com/docs/guides/platform/exhaust-disk-io',buttonText: 'Check usage',metric: 'disk_io',},disk_space_exhaustion: {- content: {+ bannerContent: {warning: {title:'Your project is about to exhaust its disk space budget, and may become unresponsive once fully exhausted',@@ -50,16 +70,26 @@ export const RESOURCE_WARNING_MESSAGES = {'You can opt to increase your disk size up to 200GB on the database settings page.',},},+ cardContent: {+ warning: {+ title: 'Project is exhausting disk space budget',+ description: 'Project may become unresponsive if fully exhausted',+ },+ critical: {+ title: 'Project has exhausted disk space budget',+ description: 'Project may become unresponsive',+ },+ },docsUrl: 'https://supabase.com/docs/guides/platform/database-size#disk-management',buttonText: undefined,metric: 'disk_space',},cpu_exhaustion: {- content: {+ bannerContent: {warning: {title: 'Your project is currently facing high CPU usage, and its performance is affected',description:- 'You will need to either optimize your performance or upgrade your compute to a larger instance',+ 'You will need to either optimize your performance or upgrade your compute to a larger Project',},critical: {title: "Your project's CPU usage is at 100% and its performance is affected",@@ -67,12 +97,22 @@ export const RESOURCE_WARNING_MESSAGES = {'You will need to either optimize your performance or upgrade your compute to a larger plan',},},+ cardContent: {+ warning: {+ title: 'Project has high CPU usage',+ description: `Project performance is affected`,+ },+ critical: {+ title: 'Project CPU usage is at 100%',+ description: `Project performance is affected`,+ },+ },docsUrl: 'https://supabase.com/docs/guides/platform/exhaust-cpu',buttonText: 'Check usage',metric: 'cpu',},memory_and_swap_exhaustion: {- content: {+ bannerContent: {warning: {title:'Your project is currently facing high memory usage, and its performance is affected',@@ -85,12 +125,22 @@ export const RESOURCE_WARNING_MESSAGES = {'You will need to either optimize your performance or upgrade your compute to a larger plan',},},+ cardContent: {+ warning: {+ title: 'Project has high memory usage',+ description: `Project performance is affected.`,+ },+ critical: {+ title: 'Project memory usage is at 100%',+ description: `Project performance is affected.`,+ },+ },docsUrl: 'https://supabase.com/docs/guides/platform/exhaust-ram',buttonText: 'Check usage',metric: 'ram',},multiple_resource_warnings: {- content: {+ bannerContent: {warning: {title:'Your project is currently exhausting multiple resources, and its performance is affected',@@ -98,11 +148,21 @@ export const RESOURCE_WARNING_MESSAGES = {"Check which resources are reaching their threshold on your project's usage page.",},critical: {- title: 'Your project has exhausted at least one resource, and its performance is affected',+ title: 'Your project has exhausted multiple resources, and its performance is affected',description:"Check which resources have reached their threshold on your project's usage page.",},},+ cardContent: {+ warning: {+ title: 'Project is exhausting multiple resources',+ description: `Project performance is affected.`,+ },+ critical: {+ title: 'Project has exhausted multiple resources',+ description: `Project performance is affected.`,+ },+ },docsUrl: undefined,buttonText: 'Check usage',metric: null,diff --git a/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx b/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsxindex e406b1baaa8..8c0ac31cf89 100644--- a/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx+++ b/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx@@ -49,24 +49,23 @@ const ResourceExhaustionWarningBanner = () => {const getContent = (metric: string) => {if (projectResourceWarnings === undefined) return undefinedif (metric === 'is_readonly_mode_enabled') {- return RESOURCE_WARNING_MESSAGES.is_readonly_mode_enabled.content.warning+ return RESOURCE_WARNING_MESSAGES.is_readonly_mode_enabled.bannerContent.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'- ]+ return RESOURCE_WARNING_MESSAGES[metric as keyof typeof RESOURCE_WARNING_MESSAGES]+ .bannerContent[severity as 'warning' | 'critical']}const title =activeWarnings.length > 1- ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.content[+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.bannerContent[hasCriticalWarning ? 'critical' : 'warning'].title: getContent(activeWarnings[0])?.titleconst description =activeWarnings.length > 1- ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.content[+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.bannerContent[hasCriticalWarning ? 'critical' : 'warning'].description: getContent(activeWarnings[0])?.description@@ -129,7 +128,7 @@ const ResourceExhaustionWarningBanner = () => {{correctionUrl !== undefined && (<Link passHref href={correctionUrl}><a>- <Button type="default">{buttonText}</Button>+ <Button type="default">{buttonText ?? 'Check'}</Button></a></Link>)}diff --git a/studio/data/usage/resource-warnings-query.ts b/studio/data/usage/resource-warnings-query.tsindex b1d56c12cfe..897628e99af 100644--- a/studio/data/usage/resource-warnings-query.ts+++ b/studio/data/usage/resource-warnings-query.ts@@ -9,6 +9,25 @@ export async function getResourceWarnings(signal?: AbortSignal) {const { data, error } = await get(`/platform/projects-resource-warnings`, { signal })if (error) throw error+ // return [+ // {+ // project: 'qahowvikfwlkdqvvbfzd',+ // is_readonly_mode_enabled: false,+ // disk_io_exhaustion: null,+ // disk_space_exhaustion: null,+ // cpu_exhaustion: null,+ // memory_and_swap_exhaustion: 'critical',+ // },+ // {+ // project: 'pkxlobkdgearimcwwgxk',+ // is_readonly_mode_enabled: false,+ // disk_io_exhaustion: 'critical',+ // disk_space_exhaustion: null,+ // cpu_exhaustion: null,+ // memory_and_swap_exhaustion: null,+ // },+ // ] as ResourceWarning[]+return data}