The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update based on new API structure for usage
Joshen Lim172f604389bb
diff --git a/studio/components/interfaces/Home/ProjectUsageSection.tsx b/studio/components/interfaces/Home/ProjectUsageSection.tsxindex 0db6bf8c8a1..bdb72fd698d 100644--- a/studio/components/interfaces/Home/ProjectUsageSection.tsx+++ b/studio/components/interfaces/Home/ProjectUsageSection.tsx@@ -12,20 +12,6 @@ const ProjectUsageSection: FC = observer(({}) => {const { ref } = router.queryconst { usage, error: usageError, isLoading } = useProjectUsage(ref as string)- // [Joshen TODO] After API is ready need to update to include dbEgress, storageEgress- // And also to highlight in this chart which components are "approaching" and "over"- const mockUsage: any = {- dbSize: { usage: 20773283, limit: 524288000 },- dbEgress: { usage: 400000000, limit: 524288000 },- storageSize: { usage: 624288000, limit: 524288000 },- storageEgress: { usage: 2048, limit: 524288000 },- }-- const hasProjectData =- usage && (usage?.bucketSize || (usage?.authUsers ?? '0') !== '0' || usage?.dbTables)- ? true- : false-if (usageError) {return (<InformationBox@@ -37,6 +23,12 @@ const ProjectUsageSection: FC = observer(({}) => {)}+ const hasProjectData = usage+ ? Object.keys(usage)+ .map((key) => usage[key].usage)+ .some((usage) => usage > 0)+ : false+return (<>{isLoading ? (@@ -44,7 +36,7 @@ const ProjectUsageSection: FC = observer(({}) => {<IconLoader className="animate-spin" size={14} /><p className="text-sm">Retrieving project usage statistics</p></div>- ) : !usage.error && hasProjectData ? (+ ) : hasProjectData ? (<ProjectUsage />) : (<NewProjectPanel />diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.constants.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.constants.tsxindex 3d2fdbbe353..5a716d794d2 100644--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.constants.tsx+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.constants.tsx@@ -5,16 +5,16 @@ export const usageBasedItems = [title: 'Database',icon: <IconDatabase className="dark:text-scale-100" size={16} strokeWidth={2} />,features: [- { key: 'dbSize', title: 'Database space' },- { key: 'dbEgress', title: 'Database egress' },+ { key: 'db_size', title: 'Database space' },+ { key: 'db_egress', title: 'Database egress' },],},{title: 'Storage',icon: <IconArchive className="dark:text-scale-100" size={16} strokeWidth={2} />,features: [- { key: 'storageSize', title: 'Storage space' },- { key: 'storageEgress', title: 'Storage egress' },+ { key: 'storage_size', title: 'Storage space' },+ { key: 'storage_egress', title: 'Storage egress' },],},]diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsxindex c753c3e688e..1fb4f041166 100644--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx@@ -1,5 +1,5 @@import { FC, useEffect } from 'react'-import { Badge, Loading } from '@supabase/ui'+import { Badge, IconAlertCircle, Loading } from '@supabase/ui'import { useStore, useProjectUsage } from 'hooks'import { formatBytes } from 'lib/helpers'@@ -7,6 +7,7 @@ import { USAGE_APPROACHING_THRESHOLD } from 'lib/constants'import SparkBar from 'components/ui/SparkBar'import ShimmeringLoader from 'components/ui/ShimmeringLoader'import { usageBasedItems } from './ProjectUsageBars.constants'+import InformationBox from 'components/ui/InformationBox'interface Props {projectRef?: string@@ -15,7 +16,6 @@ interface Props {const ProjectUsage: FC<Props> = ({ projectRef }) => {const { ui } = useStore()const { usage, error, isLoading } = useProjectUsage(projectRef)- console.log(usage)useEffect(() => {if (error) {@@ -26,110 +26,111 @@ const ProjectUsage: FC<Props> = ({ projectRef }) => {}}, [error])- // [Joshen TODO] After API is ready need to update to include dbEgress, storageEgress- // And also to highlight in this chart which components are "approaching" and "over"- const mockUsage: any = {- dbSize: { usage: 20773283, limit: 524288000 },- dbEgress: { usage: 400000000, limit: 524288000 },- storageSize: { usage: 624288000, limit: 524288000 },- storageEgress: { usage: 2048, limit: 524288000 },+ if (!isLoading && error) {+ ;<InformationBox+ hideCollapse+ defaultVisibility+ icon={<IconAlertCircle strokeWidth={2} />}+ title="There was an issue loading the usage details of your project"+ />}return (<Loading active={isLoading}>- <div>- {usageBasedItems.map((product) => {- const isExceededUsage = product.features- .map((feature) => {- const featureUsage = mockUsage[feature.key]- return featureUsage.usage / featureUsage.limit > 1- })- .some((x) => x === true)- return (- <div- key={product.title}- className={[- 'mb-8 overflow-hidden rounded border',- 'border-panel-border-light dark:border-panel-border-dark',- ].join(' ')}- >- <table className="bg-panel-body-light dark:bg-panel-body-dark w-full">- {/* Header */}- <thead className="bg-panel-header-light dark:bg-panel-header-dark">- <tr className="overflow-hidden rounded">- <th className="w-1/4 px-6 py-3 text-left">- <div className="flex items-center space-x-4">- <div- className={[- 'flex h-8 w-8 items-center justify-center',- 'rounded bg-scale-500 dark:bg-white',- ].join(' ')}- >- {product.icon}+ {usage && (+ <div>+ {usageBasedItems.map((product) => {+ const isExceededUsage = product.features+ .map((feature) => {+ const featureUsage = usage[feature.key]+ return featureUsage.usage / featureUsage.limit > 1+ })+ .some((x) => x === true)+ return (+ <div+ key={product.title}+ className={[+ 'mb-8 overflow-hidden rounded border',+ 'border-panel-border-light dark:border-panel-border-dark',+ ].join(' ')}+ >+ <table className="bg-panel-body-light dark:bg-panel-body-dark w-full">+ {/* Header */}+ <thead className="bg-panel-header-light dark:bg-panel-header-dark">+ <tr className="overflow-hidden rounded">+ <th className="w-1/4 px-6 py-3 text-left">+ <div className="flex items-center space-x-4">+ <div+ className={[+ 'flex h-8 w-8 items-center justify-center',+ 'rounded bg-scale-500 dark:bg-white',+ ].join(' ')}+ >+ {product.icon}+ </div>+ <h5 className="mb-0">{product.title}</h5></div>- <h5 className="mb-0">{product.title}</h5>- </div>- </th>- {/* Plan Limits */}- <th className="hidden p-3 text-left text-xs font-medium leading-4 text-gray-400 lg:table-cell">- {isExceededUsage && <Badge color="red">Exceeded usage</Badge>}- </th>- {/* Usage */}- <th className="p-3 text-left text-xs font-medium leading-4 text-gray-400" />- </tr>- </thead>+ </th>+ {/* Plan Limits */}+ <th className="hidden p-3 text-left text-xs font-medium leading-4 text-gray-400 lg:table-cell">+ {isExceededUsage && <Badge color="red">Exceeded usage</Badge>}+ </th>+ {/* Usage */}+ <th className="p-3 text-left text-xs font-medium leading-4 text-gray-400" />+ </tr>+ </thead>- {/* Line items */}- {usage === undefined ? (- <div className="w-96 px-4 pt-1 pb-4">- <ShimmeringLoader />- </div>- ) : (- <tbody>- {product.features.map((feature) => {- // [Joshen TODO] Update to use actual usage endpoint- const featureUsage = mockUsage[feature.key]- const usageRatio = featureUsage.usage / featureUsage.limit- const isApproaching = usageRatio >= USAGE_APPROACHING_THRESHOLD- const isExceeded = usageRatio >= 1+ {/* Line items */}+ {usage === undefined ? (+ <div className="w-96 px-4 pt-1 pb-4">+ <ShimmeringLoader />+ </div>+ ) : (+ <tbody>+ {product.features.map((feature) => {+ const featureUsage = usage[feature.key]+ const usageRatio = featureUsage.usage / featureUsage.limit+ const isApproaching = usageRatio >= USAGE_APPROACHING_THRESHOLD+ const isExceeded = usageRatio >= 1- return (- <tr- key={feature.title}- className="border-panel-border-light dark:border-panel-border-dark border-t"- >- <td className="whitespace-nowrap px-6 py-3 text-sm text-scale-1200">- {feature.title}- </td>- <td className="w-1/5 whitespace-nowrap p-3 text-sm lg:table-cell hidden text-scale-1200">- {(usageRatio * 100).toFixed(2)} %- </td>- <td className="px-6 py-3 text-sm text-scale-1200">- <SparkBar- type="horizontal"- barClass={`${- isExceeded- ? 'bg-red-900'- : isApproaching- ? 'bg-yellow-900'- : 'bg-brand-900'- }`}- value={featureUsage.usage}- max={featureUsage.limit}- labelBottom={formatBytes(featureUsage.usage)}- labelTop={formatBytes(featureUsage.limit)}- />- </td>- </tr>- )- })}- </tbody>- )}- </table>- </div>- )- })}- </div>+ return (+ <tr+ key={feature.title}+ className="border-panel-border-light dark:border-panel-border-dark border-t"+ >+ <td className="whitespace-nowrap px-6 py-3 text-sm text-scale-1200">+ {feature.title}+ </td>+ <td className="w-1/5 whitespace-nowrap p-3 text-sm lg:table-cell hidden text-scale-1200">+ {(usageRatio * 100).toFixed(2)} %+ </td>+ <td className="px-6 py-3 text-sm text-scale-1200">+ <SparkBar+ type="horizontal"+ barClass={`${+ isExceeded+ ? 'bg-red-900'+ : isApproaching+ ? 'bg-yellow-900'+ : 'bg-brand-900'+ }`}+ value={featureUsage.usage}+ max={featureUsage.limit}+ labelBottom={formatBytes(featureUsage.usage)}+ labelTop={formatBytes(featureUsage.limit)}+ />+ </td>+ </tr>+ )+ })}+ </tbody>+ )}+ </table>+ </div>+ )+ })}+ </div>+ )}</Loading>)}diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types.ts b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types.tsindex bbc49f797ed..7b419d8f0da 100644--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types.ts+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types.ts@@ -1,25 +1,8 @@-export interface UsageStats {- authUsers: number- bucketSize: number- dbSize: number- dbTables: number-}-export interface ResourceUsage {usage: numberlimit: number}-export interface UsageStatsUpdated {- dbSize: ResourceUsage- dbEgress: ResourceUsage- storageSize: ResourceUsage- storageEgress: ResourceUsage-}--export interface ApiUsageStats {- authUsers: string | null- bucketSize: string | null- dbSize: string | null- dbTables: string | null+export interface UsageStats {+ [key: string]: ResourceUsage}diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsxindex 1ed12b0aa2e..14eff53cfcf 100644--- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx+++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageMinimal.tsx@@ -6,71 +6,55 @@ import { formatBytes } from 'lib/helpers'import { PRICING_TIER_PRODUCT_IDS, USAGE_APPROACHING_THRESHOLD } from 'lib/constants'import SparkBar from 'components/ui/SparkBar'import { usageBasedItems } from './ProjectUsageBars.constants'-import { UsageStats } from './ProjectUsageBars.types'interface ProjectUsageMinimalProps {projectRef?: stringfilter: string}-// [Joshen TODO] Need to update to use the newer usageBasedItems from constantsconst ProjectUsageMinimal: FC<ProjectUsageMinimalProps> = ({ projectRef, filter }) => {const { usage, error: usageError, isLoading } = useProjectUsage(projectRef)- const { subscription, error } = useProjectSubscription(projectRef)-- const stats: UsageStats = {- authUsers: Number(usage?.authUsers),- bucketSize: Number(usage?.bucketSize),- dbSize: Number(usage?.dbSize),- dbTables: Number(usage?.dbTables),- }-- // [Joshen TODO] After API is ready need to update to include dbEgress, storageEgress- // And also to highlight in this chart which components are "approaching" and "over"- const mockUsage: any = {- dbSize: { usage: 20773283, limit: 524288000 },- dbEgress: { usage: 400000000, limit: 524288000 },- storageSize: { usage: 624288000, limit: 524288000 },- storageEgress: { usage: 2048, limit: 524288000 },- }+ const { subscription, error: subscriptionError } = useProjectSubscription(projectRef)if (subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.PAYG) {return <></>}- const tier =- subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.PRO ? 'pro' : 'free'-const product = usageBasedItems.find((item) => item.title === filter)if (!product) return <></>+ if (usageError || subscriptionError) {+ return <div></div>+ }+return (<Loading active={isLoading}>- <div className="space-y-4">- {product.features.map((feature) => {- // [Joshen TODO] Update to use actual usage endpoint- const featureUsage = mockUsage[feature.key]- const usageRatio = featureUsage.usage / featureUsage.limit- const isApproaching = usageRatio >= USAGE_APPROACHING_THRESHOLD- const isExceeded = usageRatio >= 1-- return (- <div key={feature.key} className="space-y-1">- <h5 className="text-scale-1200 text-sm">{feature.title}</h5>- <SparkBar- type="horizontal"- barClass={`${- isExceeded ? 'bg-red-900' : isApproaching ? 'bg-yellow-900' : 'bg-brand-900'- }`}- value={featureUsage.usage}- max={featureUsage.limit}- labelBottom={formatBytes(featureUsage.usage)}- labelTop={formatBytes(featureUsage.limit)}- />- </div>- )- })}- </div>+ {usage && (+ <div className="space-y-8">+ {product.features.map((feature) => {+ const featureUsage = usage[feature.key]+ const usageRatio = featureUsage.usage / featureUsage.limit+ const isApproaching = usageRatio >= USAGE_APPROACHING_THRESHOLD+ const isExceeded = usageRatio >= 1++ return (+ <div key={feature.key} className="space-y-1">+ <h5 className="text-scale-1200 text-sm">{feature.title}</h5>+ <SparkBar+ type="horizontal"+ barClass={`${+ isExceeded ? 'bg-red-900' : isApproaching ? 'bg-yellow-900' : 'bg-brand-900'+ }`}+ value={featureUsage.usage}+ max={featureUsage.limit}+ labelBottom={formatBytes(featureUsage.usage)}+ labelTop={formatBytes(featureUsage.limit)}+ />+ </div>+ )+ })}+ </div>+ )}</Loading>)}diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsxindex 8fc8aba68a5..90059b70cbb 100644--- a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx@@ -19,15 +19,8 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder =const router = useRouter()const { ref } = router.query- // const { usageStatus } = useProjectUsageStatus(ref as string)- // [Joshen TODO] After API is ready, to do up proper logic here- const usage: any = {- dbSize: { usage: 10773283, limit: 524288000 },- dbEgress: { usage: 400000000, limit: 524288000 },- storageSize: { usage: 624288000, limit: 524288000 },- storageEgress: { usage: 0, limit: 524288000 },- }+ const { usage } = useProjectUsage(ref as string)const resourcesExceededLimits = getResourcesExceededLimits(usage)const isOverUsageLimits = resourcesExceededLimits.length > 0diff --git a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/studio/components/layouts/ProjectLayout/ProjectLayout.tsxindex 7830458c91c..8c6c33b835b 100644--- a/studio/components/layouts/ProjectLayout/ProjectLayout.tsx+++ b/studio/components/layouts/ProjectLayout/ProjectLayout.tsx@@ -33,7 +33,6 @@ const ProjectLayout = ({}: PropsWithChildren<Props>) => {const { ui } = useStore()const ongoingIncident = useFlag('ongoingIncident')-const projectName = ui.selectedProject?.namereturn (@@ -66,7 +65,7 @@ const ProjectLayout = ({)}-export const ProjectLayoutWithAuth = withAuth(ProjectLayout)+export const ProjectLayoutWithAuth = withAuth(observer(ProjectLayout))export default ProjectLayoutdiff --git a/studio/components/ui/OveragesBanner/OveragesBanner.tsx b/studio/components/ui/OveragesBanner/OveragesBanner.tsxindex da7deb0f3b8..bf85cdc99e6 100644--- a/studio/components/ui/OveragesBanner/OveragesBanner.tsx+++ b/studio/components/ui/OveragesBanner/OveragesBanner.tsx@@ -15,14 +15,7 @@ const OveragesBanner: FC<Props> = ({ tier, minimal }) => {const { ui } = useStore()const ref = ui.selectedProject?.ref- // [Joshen TODO] After API is ready, to do up proper logic here- // const { usageStatus } = useProjectUsageStatus(ui.selectedProject?.ref)- const usage = {- dbSize: { usage: 10773283, limit: 524288000 },- dbEgress: { usage: 400000000, limit: 524288000 },- storageSize: { usage: 624288000, limit: 524288000 },- storageEgress: { usage: 0, limit: 524288000 },- }+ const { usage, error, isLoading } = useProjectUsage(ref as string)const resourcesApproachingLimits = getResourcesApproachingLimits(usage)const isApproachingUsageLimits = resourcesApproachingLimits.length > 0@@ -31,6 +24,8 @@ const OveragesBanner: FC<Props> = ({ tier, minimal }) => {const isOverUsageLimits = resourcesExceededLimits.length > 0if (+ isLoading ||+ error ||(!isApproachingUsageLimits && !isOverUsageLimits) ||tier === PRICING_TIER_PRODUCT_IDS.ENTERPRISE) {diff --git a/studio/components/ui/OveragesBanner/OveragesBanner.utils.ts b/studio/components/ui/OveragesBanner/OveragesBanner.utils.tsindex de63d9965d0..e46962c9e5f 100644--- a/studio/components/ui/OveragesBanner/OveragesBanner.utils.ts+++ b/studio/components/ui/OveragesBanner/OveragesBanner.utils.ts@@ -2,6 +2,8 @@ import { compact } from 'lodash'import { USAGE_APPROACHING_THRESHOLD } from 'lib/constants'export const getResourcesApproachingLimits = (usages: any) => {+ if (!usages) return []+return compact(Object.keys(usages).map((resourceName) => {const resource = usages[resourceName]@@ -11,6 +13,8 @@ export const getResourcesApproachingLimits = (usages: any) => {}export const getResourcesExceededLimits = (usages: any) => {+ if (!usages) return []+return compact(Object.keys(usages).map((resourceName) => {const resource = usages[resourceName]diff --git a/studio/components/ui/Usage.tsx b/studio/components/ui/Usage.tsxdeleted file mode 100644index 16df755b856..00000000000--- a/studio/components/ui/Usage.tsx+++ /dev/null@@ -1,290 +0,0 @@-import React, { FC, useEffect } from 'react'-import useSWR from 'swr'-import { Loading } from '@supabase/ui'--import { useProjectSubscription, useStore } from 'hooks'-import { API_URL, PRICING_TIER_PRODUCT_IDS } from 'lib/constants'-import { get } from 'lib/common/fetch'-import SparkBar from 'components/ui/SparkBar'-import ShimmeringLoader from './ShimmeringLoader'--interface ApiUsageStats {- authUsers: string | null- bucketSize: string | null- dbSize: string | null- dbTables: string | null-}-interface UsageStats {- authUsers: number- bucketSize: number- dbSize: number- dbTables: number-}--const GB = 1000000000-const MB = 1000000--const usageLimits = {- database: {- title: 'Database',- icon_src: '/img/database.svg',- features: [- {- title: 'API requests',- tiers: {- free: {- description: () => 'Unlimited',- render: null,- },- pro: {- description: () => 'Unlimited',- render: null,- },- },- },- {- title: 'Database space',- tiers: {- free: {- description: (stats: UsageStats) =>- `${((stats.dbSize / (500 * MB)) * 100).toFixed(2)} %`,- render: (stats: UsageStats) => {- const bytes: number = stats.dbSize- const usage = {- gb: bytes / GB,- mb: bytes / MB,- }- return (- <SparkBar- value={usage.mb}- max={500}- type={'horizontal'}- barClass={'bg-brand-900'}- labelBottom={`${usage.mb.toFixed(2).toLocaleString()} MB`}- labelTop={`500 MB`}- />- )- },- },- pro: {- description: (stats: UsageStats) =>- `${((stats.dbSize / (8000 * MB)) * 100).toFixed(2)} %`,- render: (stats: UsageStats) => {- const bytes: number = stats.dbSize- const usage = {- gb: bytes / GB,- mb: bytes / MB,- }- return (- <SparkBar- value={usage.mb}- max={8000}- type={'horizontal'}- barClass={'bg-brand-900'}- labelBottom={`${usage.mb.toFixed(2).toLocaleString()} MB`}- labelTop={`8 GB`}- />- )- },- },- },- },- ],- },- storage: {- title: 'File storage',- icon_src: '/img/archive.svg',- features: [- {- title: 'Storage space',- tiers: {- free: {- description: (stats: UsageStats) =>- `${((stats.bucketSize / (1 * GB)) * 100).toFixed(2)}%`,- render: (stats: UsageStats) => (- <SparkBar- value={stats.bucketSize / (1024 * 1024) || 0}- max={1 * 1024}- type={'horizontal'}- barClass={'bg-brand-900'}- labelBottom={`${(stats.bucketSize / (1024 * 1024)).toLocaleString()} MB`}- labelTop={`${(1 * 1024).toLocaleString()} MB`}- />- ),- },- pro: {- description: (stats: UsageStats) =>- `${((stats.bucketSize / (100 * GB)) * 100).toFixed(2)}%`,- render: (stats: UsageStats) => (- <SparkBar- value={stats.bucketSize / (1024 * 1024) || 0}- max={100 * 1024}- type={'horizontal'}- barClass={'bg-brand-900'}- labelBottom={`${(stats.bucketSize / (1024 * 1024)).toLocaleString()} MB`}- labelTop={`${Number(100).toLocaleString()} GB`}- />- ),- },- },- },- {- title: 'Transfer limits',- tiers: {- free: {- description: () => `${Number(2).toLocaleString()} GB`,- render: () => {},- },- pro: {- description: () => `${Number(200).toLocaleString()} GB`,- render: () => {},- },- },- },- ],- },-}--interface ProjectUsageProps {- projectRef?: string- subscription_id?: string-}--const ProjectUsage: FC<ProjectUsageProps> = ({ projectRef, subscription_id }) => {- const { ui } = useStore()- const { data: stats, error: usageError } = useSWR(`${API_URL}/projects/${projectRef}/usage`, get)- const { subscription, isLoading: loading, error } = useProjectSubscription(projectRef)-- useEffect(() => {- if (error) {- ui.setNotification({- category: 'error',- message: `Failed to get project subscription: ${error?.message ?? 'unknown'}`,- })- }- }, [error])-- const tier =- subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.PRO ? 'pro' : 'free'-- return (- <Loading active={loading}>- <div className="">- {Object.values(usageLimits).map((product) => (- <div- className="border-panel-border-light dark:border-panel-border-dark mb-8 overflow-hidden rounded border"- key={product.title}- >- <table className="bg-panel-body-light dark:bg-panel-body-dark w-full">- <thead className="bg-panel-header-light dark:bg-panel-header-dark">- <tr className="overflow-hidden rounded">- <th className="w-1/4 px-6 py-3 text-left">- <div className="flex items-center space-x-3">- <div className="flex h-8 w-8 items-center justify-center rounded bg-white">- <img width={'16'} src={product.icon_src} />- </div>- <h5 className="mb-0">{product.title}</h5>- </div>- </th>- <th className="hidden p-3 text-left text-xs font-medium leading-4 text-gray-400 lg:table-cell">- {/* Plan Limits */}- </th>- <th className="p-3 text-left text-xs font-medium leading-4 text-gray-400">- {/* Usage */}- </th>- </tr>- </thead>-- {stats === undefined ? (- <div className="w-96 px-4 pt-1 pb-4">- <ShimmeringLoader />- </div>- ) : (- <tbody className="">- {product.features.map((feature) => {- return (- <tr- className="border-panel-border-light dark:border-panel-border-dark border-t"- key={feature.title}- >- <td className="text-typography-body-light dark:text-typography-body-dark whitespace-nowrap px-6 py-3 text-sm">- {feature.title}- </td>- <td className="text-typography-body-light dark:text-typography-body-dark hidden w-1/5 whitespace-nowrap p-3 text-sm lg:table-cell">- {feature.tiers[tier]?.description(stats)}- </td>- <td className="text-typography-body-light dark:text-typography-body-dark px-6 py-3 text-sm ">- {/* @ts-ignore */}- {feature.tiers[tier]?.render ? feature.tiers[tier].render(stats) : null}- </td>- </tr>- )- })}- </tbody>- )}- </table>- </div>- ))}- </div>- </Loading>- )-}--export default ProjectUsage--interface ProjectUsageMinimalProps extends ProjectUsageProps {- filter: string-}--export const ProjectUsageMinimal: FC<ProjectUsageMinimalProps> = ({- projectRef,- subscription_id,- filter,-}) => {- const { data: apiStats, error: usageError } = useSWR<ApiUsageStats>(- `${API_URL}/projects/${projectRef}/usage`,- get- )- const { subscription, isLoading: loading, error } = useProjectSubscription(projectRef)- const stats: UsageStats = {- authUsers: Number(apiStats?.authUsers ?? 0),- bucketSize: Number(apiStats?.bucketSize ?? 0),- dbSize: Number(apiStats?.dbSize ?? 0),- dbTables: Number(apiStats?.dbTables ?? 0),- }-- if (subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.PAYG) {- return <></>- }-- const tier =- subscription?.tier?.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.PRO ? 'pro' : 'free'-- return (- <Loading active={loading}>- <div className="space-y-4">- {Object.values(usageLimits)- .filter((product) => product.title === filter)- .map((product) => {- return (- <div key={product.title}>- {product.features.map((feature) => {- return (- <div key={feature.title}>- {feature.tiers[tier]?.render && feature.title !== 'Transfer limits' ? (- <h5 className="text-scale-900 text-sm">{feature.title}</h5>- ) : null}- <div className="text-typography-body-light dark:text-typography-body-dark text-sm">- {/* @ts-ignore */}- {feature.tiers[tier]?.render ? feature.tiers[tier].render(stats) : null}- </div>- </div>- )- })}- </div>- )- })}- </div>- </Loading>- )-}diff --git a/studio/hooks/queries/useProjectUsage.ts b/studio/hooks/queries/useProjectUsage.tsindex 89e07df0687..aa1eb266c55 100644--- a/studio/hooks/queries/useProjectUsage.ts+++ b/studio/hooks/queries/useProjectUsage.ts@@ -1,6 +1,7 @@import useSWR from 'swr'import { get } from 'lib/common/fetch'import { API_URL } from 'lib/constants'+import { UsageStats } from 'components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.types'export function useProjectUsage(ref?: string) {const url = `${API_URL}/projects/${ref}/usage`@@ -8,7 +9,7 @@ export function useProjectUsage(ref?: string) {const anyError = data?.error || errorreturn {- usage: anyError ? undefined : data,+ usage: anyError ? undefined : (data as UsageStats),error: anyError,isLoading: !anyError && !data,isError: !!anyError,diff --git a/studio/pages/project/[ref]/settings/database.tsx b/studio/pages/project/[ref]/settings/database.tsxindex d72e9eabf0e..d51b816003c 100644--- a/studio/pages/project/[ref]/settings/database.tsx+++ b/studio/pages/project/[ref]/settings/database.tsx@@ -35,7 +35,7 @@ const ProjectSettings: NextPageWithLayout = () => {<div><div className="content h-full w-full overflow-y-auto"><div className="w-full max-w-5xl px-4 py-4">- <Usage project={project} />+ <DatabaseUsage project={project} /><GeneralSettings projectRef={ref} /><ConnectionPooling /></div>@@ -48,7 +48,7 @@ ProjectSettings.getLayout = (page) => <SettingsLayout title="Database">{page}</Sexport default observer(ProjectSettings)-const Usage: FC<any> = ({ project }) => {+const DatabaseUsage: FC<any> = ({ project }) => {const [dateRange, setDateRange] = useState<any>(undefined)const router = useRouter()const ref = router.query.ref as string@@ -130,7 +130,7 @@ const Usage: FC<any> = ({ project }) => {<Paneltitle={<h5 key="panel-title" className="mb-0">- Database storage+ Database usage</h5>}>