Skip to content

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

First draft

Terry Suttonb3a8f922fbcb
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx
index 0b1801f51a2..1c81df2fad7 100644
--- a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx
+++ b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx
@@ -5,7 +5,6 @@ import {
IconGitHub,
IconLoader,
IconPauseCircle,
- IconTriangle,
} from 'ui'
import CardButton from 'components/ui/CardButton'
@@ -13,12 +12,15 @@ import { useProjectReadOnlyStatus } from 'hooks/misc/useProjectReadOnlyStatus'
import { BASE_PATH, PROJECT_STATUS } from 'lib/constants'
import { Project } from 'types'
import { IntegrationProjectConnection } from 'data/integrations/integrations.types'
+import { ResourceWarningResponse } from 'data/usage/resource-warnings-query'
+import ProjectCardWarnings from './ProjectCardWarnings'
export interface ProjectCardProps {
project: Project
rewriteHref?: string
githubIntegration?: IntegrationProjectConnection
vercelIntegration?: IntegrationProjectConnection
+ resourceWarnings?: ResourceWarningResponse
}
const ProjectCard = ({
@@ -26,6 +28,7 @@ const ProjectCard = ({
rewriteHref,
githubIntegration,
vercelIntegration,
+ resourceWarnings,
}: ProjectCardProps) => {
const { name, ref: projectRef } = project
const desc = `${project.cloud_provider} | ${project.region}`
@@ -36,13 +39,23 @@ const ProjectCard = ({
const isVercelIntegrated = vercelIntegration !== undefined
const githubRepository = githubIntegration?.metadata.name ?? undefined
- // Project status should supersede is read only status
+ // 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 checkProjectResourceWarnings = (resourceWarnings: ResourceWarningResponse) => {
+ return Object.values(resourceWarnings).some(
+ (value) => typeof value === 'boolean' && value === true
+ )
+ }
+
+ // const projectHasResourceWarnings =
+ // resourceWarnings !== undefined ? checkProjectResourceWarnings(resourceWarnings) : false
+ const projectHasResourceWarnings = true
+
return (
<li className="col-span-1 list-none">
<CardButton
@@ -74,6 +87,9 @@ const ProjectCard = ({
</>
)}
</div>
+ {resourceWarnings && projectHasResourceWarnings && (
+ <ProjectCardWarnings resourceWarnings={resourceWarnings} />
+ )}
</div>
}
footer={
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx
new file mode 100644
index 00000000000..37fa3c17bd4
--- /dev/null
+++ b/studio/components/interfaces/Home/ProjectList/ProjectCardWarnings.tsx
@@ -0,0 +1,66 @@
+import { ResourceWarningResponse } from 'data/usage/resource-warnings-query'
+import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_, IconAlertTriangle } from 'ui'
+
+export type ResourceWarningResponses = Omit<
+ Omit<ResourceWarningResponse, 'project'>,
+ 'is_readonly_mode_enabled'
+>
+
+export interface ProjectCardWarningsProps {
+ resourceWarnings: ResourceWarningResponses
+}
+
+// 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 in readonly mode',
+ description: 'This database will no longer accept write requests.',
+ },
+ is_disk_io_budget_below_threshold: {
+ title: 'Your project is depleting its Disk IO Budget',
+ description: 'Your instance may become unresponsive if fully exhausted.',
+ },
+ is_disk_space_usage_beyond_threshold: {
+ title: 'Project has exhausted disk space budget',
+ description: 'Your instance may become unresponsive if fully exhausted.',
+ },
+ is_cpu_load_beyond_threshold: {
+ title: 'Your project has high CPU usage',
+ description: `Your instance's performance is affected`,
+ },
+ is_memory_and_swap_usage_beyond_threshold: {
+ title: 'Your project has high memory usage',
+ description: `Your instance's performance is affected.`,
+ },
+ multiple_resource_warnings: {
+ title: 'Your project is burning up',
+ description: `Your instance's performance is affected.`,
+ },
+}
+
+export default function ProjectCardWarnings({ resourceWarnings }: ProjectCardWarningsProps) {
+ const activeWarnings = Object.keys(resourceWarnings).filter(
+ (property) => resourceWarnings[property as keyof typeof resourceWarnings] === true
+ )
+
+ return (
+ <div>
+ <Alert_Shadcn_ variant="warning">
+ <IconAlertTriangle strokeWidth={2} />
+ <AlertTitle_Shadcn_>
+ {activeWarnings.length > 1
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.title
+ : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof resourceWarnings]?.title}
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ {activeWarnings.length > 1
+ ? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.description
+ : RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof resourceWarnings]
+ ?.description}
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ {/* <pre>{JSON.stringify(resourceWarnings, null, 2)}</pre> */}
+ </div>
+ )
+}
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectList.tsx b/studio/components/interfaces/Home/ProjectList/ProjectList.tsx
index d24aa81b1d0..5066c17a004 100644
--- a/studio/components/interfaces/Home/ProjectList/ProjectList.tsx
+++ b/studio/components/interfaces/Home/ProjectList/ProjectList.tsx
@@ -19,6 +19,7 @@ import { Organization, Project, ResponseError } from 'types'
import ProjectCard from './ProjectCard'
import ShimmeringCard from './ShimmeringCard'
import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
+import { useResourceWarningQuery } from 'data/usage/resource-warnings-query'
export interface ProjectListProps {
rewriteHref?: (projectRef: string) => string
@@ -95,6 +96,10 @@ const OrganizationProjects = ({
}: OrganizationProjectsProps) => {
const isEmpty = !projects || projects.length === 0
const canReadProjects = useCheckPermissions(PermissionAction.READ, 'projects', undefined, id)
+ const { data: resourceWarnings } = useResourceWarningQuery()
+
+ console.log(resourceWarnings)
+ console.log('one render')
return (
<div className="space-y-3" key={makeRandomString(5)}>
@@ -165,6 +170,9 @@ const OrganizationProjects = ({
key={makeRandomString(5)}
project={project}
rewriteHref={rewriteHref ? rewriteHref(project.ref) : undefined}
+ resourceWarnings={resourceWarnings?.find(
+ (resourceWarning) => resourceWarning.project === project.ref
+ )}
/>
))
)}
diff --git a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
index 90d627cc098..9f1e2429b0e 100644
--- a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
+++ b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
@@ -17,6 +17,8 @@ import ProjectPausedState from './ProjectPausedState'
import RestoringState from './RestoringState'
import UpgradingState from './UpgradingState'
import AppLayout from '../AppLayout/AppLayout'
+import UsageWarningBanner from 'components/ui/UsageWarnings/UsageWarningBanner'
+import { useResourceWarningQuery } from 'data/usage/resource-warnings-query'
// [Joshen] This is temporary while we unblock users from managing their project
// if their project is not responding well for any reason. Eventually needs a bit of an overhaul
@@ -94,14 +96,12 @@ const ProjectLayout = ({
<div className="flex h-full">
{/* Left-most navigation side bar to access products */}
{!hideIconBar && <NavigationBar />}
-
{/* Product menu bar */}
{!showPausedState && (
<MenuBarWrapper isLoading={isLoading} productMenu={productMenu}>
<ProductMenuBar title={product}>{productMenu}</ProductMenuBar>
</MenuBarWrapper>
)}
-
<main className="flex flex-col flex-1 w-full overflow-x-hidden">
{!navLayoutV2 && !hideHeader && IS_PLATFORM && <LayoutHeader />}
{showPausedState ? (
@@ -179,6 +179,8 @@ const ContentWrapper = ({ isLoading, children }: ContentWrapperProps) => {
selectedProject?.status === PROJECT_STATUS.PAUSING
const isProjectOffline = selectedProject?.postgrestStatus === 'OFFLINE'
+ const { data: resourceWarnings } = useResourceWarningQuery()
+ console.log(resourceWarnings)
return (
<>
{isLoading || (requiresProjectDetails && selectedProject === undefined) ? (
@@ -194,7 +196,10 @@ const ContentWrapper = ({ isLoading, children }: ContentWrapperProps) => {
) : requiresDbConnection && isProjectBuilding ? (
<BuildingState project={selectedProject} />
) : (
- <Fragment key={selectedProject?.ref}>{children}</Fragment>
+ <>
+ <UsageWarningBanner />
+ <Fragment key={selectedProject?.ref}>{children}</Fragment>
+ </>
)}
</>
)
diff --git a/studio/components/ui/CardButton.tsx b/studio/components/ui/CardButton.tsx
index f0696bafe7b..f374f6cef82 100644
--- a/studio/components/ui/CardButton.tsx
+++ b/studio/components/ui/CardButton.tsx
@@ -27,7 +27,7 @@ const CardButton = ({
imgAlt,
onClick,
icon,
- containerHeightClassName = 'h-32',
+ containerHeightClassName = 'h-48',
loading = false,
}: PropsWithChildren<CardButtonProps>) => {
const LinkContainer = ({ children }: { children: React.ReactNode }) => (
diff --git a/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx b/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx
new file mode 100644
index 00000000000..ea70a140856
--- /dev/null
+++ b/studio/components/ui/UsageWarnings/UsageWarningBanner.tsx
@@ -0,0 +1,16 @@
+import Link from 'next/link'
+import React from 'react'
+
+import { useParams } from 'common'
+import { useSelectedOrganization } from 'hooks'
+
+export default function UsageWarningBanner() {
+ const { ref } = useParams()
+ const organization = useSelectedOrganization()
+
+ return (
+ <div className="w-full bg-orange-500">
+ Project is experiencing high [product] usage. <Link href="#">Learn more</Link>
+ </div>
+ )
+}
diff --git a/studio/data/usage/keys.ts b/studio/data/usage/keys.ts
index aac6590a78e..b5aca6f8298 100644
--- a/studio/data/usage/keys.ts
+++ b/studio/data/usage/keys.ts
@@ -1,4 +1,5 @@
export const usageKeys = {
usage: (projectRef: string | undefined) => ['projects', projectRef, 'usage'] as const,
orgUsage: (orgSlug: string | undefined) => ['organizations', orgSlug, 'usage'] as const,
+ resourceWarnings: () => ['project', 'resource-warnings'] as const,
}
diff --git a/studio/data/usage/resource-warnings-query.ts b/studio/data/usage/resource-warnings-query.ts
new file mode 100644
index 00000000000..82be8e7f1eb
--- /dev/null
+++ b/studio/data/usage/resource-warnings-query.ts
@@ -0,0 +1,40 @@
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+import { get, isResponseOk } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
+import { usageKeys } from './keys'
+
+export type ResourceWarningResponse = {
+ 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
+}
+
+export async function getResourceWarnings(signal?: AbortSignal) {
+ const response = await get<ResourceWarningResponse[]>(`${API_URL}/projects-resource-warnings`, {
+ signal,
+ })
+ if (!isResponseOk(response)) {
+ throw response.error
+ }
+
+ return response
+}
+
+export type ResourceWarningData = Awaited<ReturnType<typeof getResourceWarnings>>
+export type ResourceError = unknown
+
+export const useResourceWarningQuery = <TData = ResourceWarningData>({
+ enabled = true,
+ ...options
+}: UseQueryOptions<ResourceWarningData, ResourceError, TData> = {}) =>
+ useQuery<ResourceWarningData, ResourceError, TData>(
+ usageKeys.resourceWarnings(),
+ ({ signal }) => getResourceWarnings(signal),
+ {
+ enabled: enabled,
+ ...options,
+ }
+ )
diff --git a/studio/pages/project/[ref]/index.tsx b/studio/pages/project/[ref]/index.tsx
index 06b56fd2a10..727d5789606 100644
--- a/studio/pages/project/[ref]/index.tsx
+++ b/studio/pages/project/[ref]/index.tsx
@@ -4,6 +4,7 @@ import ProjectUsageSection from 'components/interfaces/Home/ProjectUsageSection'
import { ProjectLayoutWithAuth } from 'components/layouts'
import ProjectPausedState from 'components/layouts/ProjectLayout/ProjectPausedState'
import ProjectUpgradeFailedBanner from 'components/ui/ProjectUpgradeFailedBanner'
+import { useResourceWarningQuery } from 'data/usage/resource-warnings-query'
import { useSelectedProject } from 'hooks'
import { IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
import { NextPageWithLayout } from 'types'
@@ -16,6 +17,9 @@ const Home: NextPageWithLayout = () => {
? project?.name
: 'Welcome to your project'
+ const { data: resourceWarnings } = useResourceWarningQuery()
+
+ console.log(resourceWarnings)
return (
<div className="mx-auto my-16 w-full max-w-7xl space-y-16">
<div className="mx-6 flex items-center space-x-6">