Skip to content

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

Make reusable components for SectionHeader and SectionContent

Joshen Lim0c6fc7a23eb7
diff --git a/studio/components/interfaces/BillingV2/Usage/Activity.tsx b/studio/components/interfaces/BillingV2/Usage/Activity.tsx
index 8b037c90c09..6de27c53c4e 100644
--- a/studio/components/interfaces/BillingV2/Usage/Activity.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/Activity.tsx
@@ -1,12 +1,13 @@
import { useParams } from 'common'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
+import SparkBar from 'components/ui/SparkBar'
import { useDailyStatsQuery } from 'data/analytics/daily-stats-query'
import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import { useProjectUsageQuery } from 'data/usage/project-usage-query'
-import BarChart from './BarChart'
-import SparkBar from 'components/ui/SparkBar'
-import { formatBytes } from 'lib/helpers'
import { Button } from 'ui'
+import BarChart from './BarChart'
+import SectionContent from './SectionContent'
+import SectionHeader from './SectionHeader'
import { generateUsageData } from './Usage.utils'
const Activity = () => {
@@ -56,232 +57,183 @@ const Activity = () => {
return (
<>
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="sticky top-16">
- <p className="text-base">Activity</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- </div>
- </div>
+ <SectionHeader title="Activity" description="Some description here" />
- {/* MONTHLY ACTIVE USERS */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">Monthly Active Users (MAU)</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
+ <SectionContent title="Monthly Active Users (MAU)" description="Some description here">
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <p className="text-sm">
+ Monthly active users {subscription?.tier.key.toLowerCase()} quota usage
+ </p>
+ <Button type="default" size="tiny" onClick={() => {}}>
+ Upgrade project
+ </Button>
+ </div>
+ <SparkBar
+ type="horizontal"
+ barClass="bg-scale-1200"
+ value={monthly_active_users?.usage ?? 0}
+ max={monthly_active_users?.limit ?? 0}
+ />
+ <div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">
+ Included in {subscription?.tier.name.toLowerCase()}
+ </p>
+ <p className="text-xs">{(monthly_active_users?.limit ?? 0).toLocaleString()}</p>
</div>
- <div className="col-span-7 space-y-6">
- <div className="space-y-2">
- <div className="flex items-center justify-between">
- <p className="text-sm">
- Monthly active users {subscription?.tier.key.toLowerCase()} quota usage
- </p>
- <Button type="default" size="tiny" onClick={() => {}}>
- Upgrade project
- </Button>
- </div>
- <SparkBar
- type="horizontal"
- barClass="bg-scale-1200"
- value={monthly_active_users?.usage ?? 0}
- max={monthly_active_users?.limit ?? 0}
- />
- <div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">
- Included in {subscription?.tier.name.toLowerCase()}
- </p>
- <p className="text-xs">{(monthly_active_users?.limit ?? 0).toLocaleString()}</p>
- </div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">Used</p>
- <p className="text-xs">{(monthly_active_users?.usage ?? 0).toLocaleString()}</p>
- </div>
- <div className="flex items-center justify-between py-1">
- <p className="text-xs text-scale-1000">Extra volume used this month</p>
- <p className="text-xs">{(mauExcess < 0 ? 0 : mauExcess).toLocaleString()}</p>
- </div>
- </div>
- </div>
- <div className="space-y-1">
- <p>Monthly active users over time</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- {isLoadingMauData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={MAU_KEY}
- data={mauData?.data ?? []}
- unit={undefined}
- yDomain={[0, 100]}
- />
- )}
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">Used</p>
+ <p className="text-xs">{(monthly_active_users?.usage ?? 0).toLocaleString()}</p>
+ </div>
+ <div className="flex items-center justify-between py-1">
+ <p className="text-xs text-scale-1000">Extra volume used this month</p>
+ <p className="text-xs">{(mauExcess < 0 ? 0 : mauExcess).toLocaleString()}</p>
</div>
</div>
</div>
- </div>
+ <div className="space-y-1">
+ <p>Monthly active users over time</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
+ </div>
+ {isLoadingMauData ? (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ ) : (
+ <BarChart
+ attribute={MAU_KEY}
+ data={mauData?.data ?? []}
+ unit={undefined}
+ yDomain={[0, 100]}
+ />
+ )}
+ </SectionContent>
- {/* ASSET TRANSFORMATIONS */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">Asset Transformations</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- </div>
- <div className="col-span-7 space-y-6">
- <div className="space-y-2">
- <div className="flex items-center justify-between">
- <p className="text-sm">
- Asset transformations {subscription?.tier.key.toLowerCase()} quota usage
- </p>
- <Button type="default" size="tiny" onClick={() => {}}>
- Upgrade project
- </Button>
- </div>
- <SparkBar
- type="horizontal"
- barClass="bg-scale-1200"
- value={storage_image_render_count?.usage ?? 0}
- max={storage_image_render_count?.limit ?? 0}
- />
- <div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">
- Included in {subscription?.tier.name.toLowerCase()}
- </p>
- {storage_image_render_count?.limit === -1 ? (
- <p className="text-xs">None</p>
- ) : (
- <p className="text-xs">
- {(storage_image_render_count?.limit ?? 0).toLocaleString()}
- </p>
- )}
- </div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">Used</p>
- <p className="text-xs">
- {(storage_image_render_count?.usage ?? 0).toLocaleString()}
- </p>
- </div>
- <div className="flex items-center justify-between py-1">
- <p className="text-xs text-scale-1000">Extra volume used this month</p>
- <p className="text-xs">
- {((storage_image_render_count?.limit ?? 0) === -1 ||
- assetTransformationExcess < 0
- ? 0
- : assetTransformationExcess
- ).toLocaleString()}
- </p>
- </div>
- </div>
- </div>
- {storage_image_render_count?.available_in_plan && (
- <>
- <div className="space-y-1">
- <p>Asset transformations over time</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- {isLoadingAssetTransformationsData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={MAU_KEY}
- data={assetTransformationsData?.data ?? []}
- unit={undefined}
- yDomain={[0, 100]}
- />
- )}
- </>
+ <SectionContent title="Storage Image Transformations" description="Some description here">
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <p className="text-sm">
+ Asset transformations {subscription?.tier.key.toLowerCase()} quota usage
+ </p>
+ <Button type="default" size="tiny" onClick={() => {}}>
+ Upgrade project
+ </Button>
+ </div>
+ <SparkBar
+ type="horizontal"
+ barClass="bg-scale-1200"
+ value={storage_image_render_count?.usage ?? 0}
+ max={storage_image_render_count?.limit ?? 0}
+ />
+ <div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">
+ Included in {subscription?.tier.name.toLowerCase()}
+ </p>
+ {storage_image_render_count?.limit === -1 ? (
+ <p className="text-xs">None</p>
+ ) : (
+ <p className="text-xs">
+ {(storage_image_render_count?.limit ?? 0).toLocaleString()}
+ </p>
)}
</div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">Used</p>
+ <p className="text-xs">{(storage_image_render_count?.usage ?? 0).toLocaleString()}</p>
+ </div>
+ <div className="flex items-center justify-between py-1">
+ <p className="text-xs text-scale-1000">Extra volume used this month</p>
+ <p className="text-xs">
+ {((storage_image_render_count?.limit ?? 0) === -1 || assetTransformationExcess < 0
+ ? 0
+ : assetTransformationExcess
+ ).toLocaleString()}
+ </p>
+ </div>
</div>
</div>
- </div>
-
- {/* EDGE FUNCTIONS INVOCATIONS */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">Edge Function Invocations</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
+ {storage_image_render_count?.available_in_plan && (
+ <>
+ <div className="space-y-1">
+ <p>Asset transformations over time</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
</div>
- <div className="col-span-7 space-y-6">
+ {isLoadingAssetTransformationsData ? (
<div className="space-y-2">
- <div className="flex items-center justify-between">
- <p className="text-sm">
- Edge function invocations {subscription?.tier.key.toLowerCase()} quota usage
- </p>
- <Button type="default" size="tiny" onClick={() => {}}>
- Upgrade project
- </Button>
- </div>
- <SparkBar
- type="horizontal"
- barClass="bg-scale-1200"
- value={func_invocations?.usage ?? 0}
- max={func_invocations?.limit ?? 0}
- />
- <div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">
- Included in {subscription?.tier.name.toLowerCase()}
- </p>
- <p className="text-xs">{(func_invocations?.limit ?? 0).toLocaleString()}</p>
- </div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">Used</p>
- <p className="text-xs">{(func_invocations?.usage ?? 0).toLocaleString()}</p>
- </div>
- <div className="flex items-center justify-between py-1">
- <p className="text-xs text-scale-1000">Extra volume used this month</p>
- <p className="text-xs">
- {(funcInvocationsExcess < 0 ? 0 : funcInvocationsExcess).toLocaleString()}
- </p>
- </div>
- </div>
- </div>
- <div className="space-y-1">
- <p>Edge function invocations over time</p>
- <p className="text-sm text-scale-1000">Some description here</p>
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
</div>
- {isLoadingFuncInvocationsData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={FUNC_INVOCATIONS_KEY}
- data={funcInvocationsData?.data ?? []}
- unit={undefined}
- yDomain={[0, 100]}
- />
- )}
+ ) : (
+ <BarChart
+ attribute={MAU_KEY}
+ data={assetTransformationsData?.data ?? []}
+ unit={undefined}
+ yDomain={[0, 100]}
+ />
+ )}
+ </>
+ )}
+ </SectionContent>
+
+ <SectionContent title="Edge Function Invocations" description="Some description here">
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <p className="text-sm">
+ Edge function invocations {subscription?.tier.key.toLowerCase()} quota usage
+ </p>
+ <Button type="default" size="tiny" onClick={() => {}}>
+ Upgrade project
+ </Button>
+ </div>
+ <SparkBar
+ type="horizontal"
+ barClass="bg-scale-1200"
+ value={func_invocations?.usage ?? 0}
+ max={func_invocations?.limit ?? 0}
+ />
+ <div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">
+ Included in {subscription?.tier.name.toLowerCase()}
+ </p>
+ <p className="text-xs">{(func_invocations?.limit ?? 0).toLocaleString()}</p>
+ </div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">Used</p>
+ <p className="text-xs">{(func_invocations?.usage ?? 0).toLocaleString()}</p>
+ </div>
+ <div className="flex items-center justify-between py-1">
+ <p className="text-xs text-scale-1000">Extra volume used this month</p>
+ <p className="text-xs">
+ {(funcInvocationsExcess < 0 ? 0 : funcInvocationsExcess).toLocaleString()}
+ </p>
</div>
</div>
</div>
- </div>
+ <div className="space-y-1">
+ <p>Edge function invocations over time</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
+ </div>
+ {isLoadingFuncInvocationsData ? (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ ) : (
+ <BarChart
+ attribute={FUNC_INVOCATIONS_KEY}
+ data={funcInvocationsData?.data ?? []}
+ unit={undefined}
+ yDomain={[0, 100]}
+ />
+ )}
+ </SectionContent>
{/* Sample Chart */}
<div className="border-b">
diff --git a/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx b/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx
index 472b8019653..7f3296df7e0 100644
--- a/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/Bandwidth.tsx
@@ -7,6 +7,8 @@ import { useProjectUsageQuery } from 'data/usage/project-usage-query'
import { formatBytes } from 'lib/helpers'
import { Button } from 'ui'
import BarChart from './BarChart'
+import SectionContent from './SectionContent'
+import SectionHeader from './SectionHeader'
const Bandwidth = () => {
const { ref } = useParams()
@@ -41,150 +43,120 @@ const Bandwidth = () => {
return (
<>
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="sticky top-16">
- <p className="text-base">Bandwidth</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- </div>
- </div>
+ <SectionHeader title="Bandwidth" description="Some description here" />
- {/* DATABASE EGRESS - need to fix if no value yet (API will return period_start as 0 in first data point) */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">Database Egress</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
+ <SectionContent title="Database Egress" description="Some description here">
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <p className="text-sm">Egress {subscription?.tier.key.toLowerCase()} quota usage</p>
+ <Button type="default" size="tiny" onClick={() => {}}>
+ Upgrade project
+ </Button>
+ </div>
+ <SparkBar
+ type="horizontal"
+ barClass="bg-scale-1200"
+ value={db_egress?.usage ?? 0}
+ max={db_egress?.limit ?? 0}
+ />
+ <div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">
+ Included in {subscription?.tier.name.toLowerCase()}
+ </p>
+ <p className="text-xs">{formatBytes(db_egress?.limit ?? 0)}</p>
</div>
- <div className="col-span-7 space-y-6">
- <div className="space-y-2">
- <div className="flex items-center justify-between">
- <p className="text-sm">
- Egress {subscription?.tier.key.toLowerCase()} quota usage
- </p>
- <Button type="default" size="tiny" onClick={() => {}}>
- Upgrade project
- </Button>
- </div>
- <SparkBar
- type="horizontal"
- barClass="bg-scale-1200"
- value={db_egress?.usage ?? 0}
- max={db_egress?.limit ?? 0}
- />
- <div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">
- Included in {subscription?.tier.name.toLowerCase()}
- </p>
- <p className="text-xs">{formatBytes(db_egress?.limit ?? 0)}</p>
- </div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">Used</p>
- <p className="text-xs">{formatBytes(db_egress?.usage ?? 0)}</p>
- </div>
- <div className="flex items-center justify-between py-1">
- <p className="text-xs text-scale-1000">Extra volume used this month</p>
- <p className="text-xs">
- {dbEgressExcess < 0 ? formatBytes(0) : formatBytes(dbEgressExcess)}
- </p>
- </div>
- </div>
- </div>
- <div className="space-y-1">
- <p>Database egress over time</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- {isLoadingDbEgressData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={DB_EGRESS_KEY}
- data={dbEgressData?.data ?? []}
- unit={undefined}
- yDomain={[0, 100]}
- />
- )}
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">Used</p>
+ <p className="text-xs">{formatBytes(db_egress?.usage ?? 0)}</p>
+ </div>
+ <div className="flex items-center justify-between py-1">
+ <p className="text-xs text-scale-1000">Extra volume used this month</p>
+ <p className="text-xs">
+ {dbEgressExcess < 0 ? formatBytes(0) : formatBytes(dbEgressExcess)}
+ </p>
</div>
</div>
</div>
- </div>
+ <div className="space-y-1">
+ <p>Database egress over time</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
+ </div>
+ {isLoadingDbEgressData ? (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ ) : (
+ // [Joshen] TODO
+ // - Provide a way to format y axis (bytes)
+ // - Fix the y axis cartesian grid intervals if possible (atm it looks random)
+ // - the max Y domain could be dynamic (slightly above limit, but take the usage + some threshold if above limit)
+ <BarChart
+ attribute={DB_EGRESS_KEY}
+ data={dbEgressData?.data ?? []}
+ unit={undefined}
+ yDomain={[0, db_egress?.limit ?? 0]}
+ yFormatter={(value) => formatBytes(value)}
+ />
+ )}
+ </SectionContent>
- {/* STORAGE EGRESS - need to fix if no value yet (API will return period_start as 0 in first data point) */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">Storage Egress</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
+ <SectionContent title="Storage Egress" description="Some description here">
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <p className="text-sm">
+ Storage egress {subscription?.tier.key.toLowerCase()} quota usage
+ </p>
+ <Button type="default" size="tiny" onClick={() => {}}>
+ Upgrade project
+ </Button>
+ </div>
+ <SparkBar
+ type="horizontal"
+ barClass="bg-scale-1200"
+ value={storage_egress?.usage ?? 0}
+ max={storage_egress?.limit ?? 0}
+ />
+ <div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">
+ Included in {subscription?.tier.name.toLowerCase()}
+ </p>
+ <p className="text-xs">{formatBytes(storage_egress?.limit ?? 0)}</p>
+ </div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">Used</p>
+ <p className="text-xs">{formatBytes(storage_egress?.usage ?? 0)}</p>
</div>
- <div className="col-span-7 space-y-6">
- <div className="space-y-2">
- <div className="flex items-center justify-between">
- <p className="text-sm">
- Storage egress {subscription?.tier.key.toLowerCase()} quota usage
- </p>
- <Button type="default" size="tiny" onClick={() => {}}>
- Upgrade project
- </Button>
- </div>
- <SparkBar
- type="horizontal"
- barClass="bg-scale-1200"
- value={storage_egress?.usage ?? 0}
- max={storage_egress?.limit ?? 0}
- />
- <div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">
- Included in {subscription?.tier.name.toLowerCase()}
- </p>
- <p className="text-xs">{formatBytes(storage_egress?.limit ?? 0)}</p>
- </div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">Used</p>
- <p className="text-xs">{formatBytes(storage_egress?.usage ?? 0)}</p>
- </div>
- <div className="flex items-center justify-between py-1">
- <p className="text-xs text-scale-1000">Extra volume used this month</p>
- <p className="text-xs">
- {storageEgressExcess < 0 ? formatBytes(0) : formatBytes(storageEgressExcess)}
- </p>
- </div>
- </div>
- </div>
- <div className="space-y-1">
- <p>Storage egress over time</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- {isLoadingStorageEgressData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={STORAGE_EGRESS_KEY}
- data={storageEgressData?.data ?? []}
- unit={undefined}
- yDomain={[0, 100]}
- />
- )}
+ <div className="flex items-center justify-between py-1">
+ <p className="text-xs text-scale-1000">Extra volume used this month</p>
+ <p className="text-xs">
+ {storageEgressExcess < 0 ? formatBytes(0) : formatBytes(storageEgressExcess)}
+ </p>
</div>
</div>
</div>
- </div>
+ <div className="space-y-1">
+ <p>Storage egress over time</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
+ </div>
+ {isLoadingStorageEgressData ? (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ ) : (
+ <BarChart
+ attribute={STORAGE_EGRESS_KEY}
+ data={storageEgressData?.data ?? []}
+ unit={undefined}
+ yDomain={[0, 100]}
+ />
+ )}
+ </SectionContent>
</>
)
}
diff --git a/studio/components/interfaces/BillingV2/Usage/BarChart.tsx b/studio/components/interfaces/BillingV2/Usage/BarChart.tsx
index c332818ce47..86dc7df0c40 100644
--- a/studio/components/interfaces/BillingV2/Usage/BarChart.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/BarChart.tsx
@@ -28,9 +28,10 @@ export interface BarChartProps {
reference?: Reference
unit?: string
yDomain?: number[]
+ yFormatter?: (value: number) => string
}
-const BarChart = ({ data, attribute, reference, unit, yDomain }: BarChartProps) => {
+const BarChart = ({ data, attribute, reference, unit, yDomain, yFormatter }: BarChartProps) => {
return (
<div className="w-full h-[200px]">
<ResponsiveContainer width="100%" height={200}>
@@ -43,6 +44,7 @@ const BarChart = ({ data, attribute, reference, unit, yDomain }: BarChartProps)
tickLine={{ stroke: 'none' }}
domain={yDomain}
unit={unit}
+ tickFormatter={yFormatter}
/>
<Bar dataKey={attribute}>
{data.map((entry) => {
diff --git a/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx b/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx
index b431d586843..64dd23457e0 100644
--- a/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/Infrastructure.tsx
@@ -3,6 +3,8 @@ import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'
import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import BarChart from './BarChart'
+import SectionContent from './SectionContent'
+import SectionHeader from './SectionHeader'
const Infrastructure = () => {
const { ref } = useParams()
@@ -41,116 +43,70 @@ const Infrastructure = () => {
return (
<>
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="sticky top-16">
- <p className="text-base">Infrastructure</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- </div>
- </div>
+ <SectionHeader title="Infrastructure" description="Some description here" />
- {/* CPU USAGE */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">CPU</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- </div>
- <div className="col-span-7 space-y-6">
- <div className="space-y-1">
- <p>Max CPU usage each day</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- {isLoadingCpuUsageData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={CPU_USAGE_KEY}
- data={cpuUsageData?.data ?? []}
- unit={cpuUsageData?.format}
- yDomain={[0, 100]}
- />
- )}
- </div>
- </div>
+ <SectionContent title="CPU" description="Some description here">
+ <div className="space-y-1">
+ <p>Max CPU usage each day</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
</div>
- </div>
-
- {/* MEMORY USAGE */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">Memory</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- </div>
- <div className="col-span-7 space-y-6">
- <div className="space-y-1">
- <p>Max memory usage each day</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- {isLoadingMemoryUsageData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={MEMORY_USAGE_KEY}
- data={memoryUsageData?.data ?? []}
- unit={memoryUsageData?.format}
- yDomain={[0, 100]}
- />
- )}
- </div>
+ {isLoadingCpuUsageData ? (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
</div>
- </div>
- </div>
+ ) : (
+ <BarChart
+ attribute={CPU_USAGE_KEY}
+ data={cpuUsageData?.data ?? []}
+ unit={cpuUsageData?.format}
+ yDomain={[0, 100]}
+ />
+ )}
+ </SectionContent>
- {/* DISK IO BUDGET */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">IO Budget</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- </div>
- <div className="col-span-7 space-y-6">
- <div className="space-y-1">
- <p>Disk IO budget per day</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- {isLoadingIoBudgetData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={DISK_IO_BUDGET_KEY}
- data={ioBudgetData?.data ?? []}
- unit={ioBudgetData?.format}
- yDomain={[0, 100]}
- />
- )}
- </div>
+ <SectionContent title="Memory" description="Some description here">
+ <div className="space-y-1">
+ <p>Max memory usage each day</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
+ </div>
+ {isLoadingMemoryUsageData ? (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
</div>
+ ) : (
+ <BarChart
+ attribute={MEMORY_USAGE_KEY}
+ data={memoryUsageData?.data ?? []}
+ unit={memoryUsageData?.format}
+ yDomain={[0, 100]}
+ />
+ )}
+ </SectionContent>
+
+ <SectionContent title="IO Budget" description="Some description here">
+ <div className="space-y-1">
+ <p>Disk IO budget per day</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
</div>
- </div>
+ {isLoadingIoBudgetData ? (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ ) : (
+ <BarChart
+ attribute={DISK_IO_BUDGET_KEY}
+ data={ioBudgetData?.data ?? []}
+ unit={ioBudgetData?.format}
+ yDomain={[0, 100]}
+ />
+ )}
+ </SectionContent>
</>
)
}
diff --git a/studio/components/interfaces/BillingV2/Usage/SectionContent.tsx b/studio/components/interfaces/BillingV2/Usage/SectionContent.tsx
new file mode 100644
index 00000000000..1f3dc1d0deb
--- /dev/null
+++ b/studio/components/interfaces/BillingV2/Usage/SectionContent.tsx
@@ -0,0 +1,26 @@
+import { PropsWithChildren } from 'react'
+
+export interface SectionContent {
+ title: string
+ description: string
+}
+
+const SectionContent = ({ title, description, children }: PropsWithChildren<SectionContent>) => {
+ return (
+ <div className="border-b">
+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
+ <div className="grid grid-cols-12">
+ <div className="col-span-5">
+ <div className="sticky top-16">
+ <p className="text-base">{title}</p>
+ <p className="text-sm text-scale-1000">{description}</p>
+ </div>
+ </div>
+ <div className="col-span-7 space-y-6">{children}</div>
+ </div>
+ </div>
+ </div>
+ )
+}
+
+export default SectionContent
diff --git a/studio/components/interfaces/BillingV2/Usage/SectionHeader.tsx b/studio/components/interfaces/BillingV2/Usage/SectionHeader.tsx
new file mode 100644
index 00000000000..45cc9cd30ce
--- /dev/null
+++ b/studio/components/interfaces/BillingV2/Usage/SectionHeader.tsx
@@ -0,0 +1,19 @@
+export interface SectionHeaderProps {
+ title: string
+ description: string
+}
+
+const SectionHeader = ({ title, description }: SectionHeaderProps) => {
+ return (
+ <div className="border-b">
+ <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
+ <div className="sticky top-16">
+ <p className="text-base">{title}</p>
+ <p className="text-sm text-scale-1000">{description}</p>
+ </div>
+ </div>
+ </div>
+ )
+}
+
+export default SectionHeader
diff --git a/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx
index 3a822b4dc19..c00076ffab8 100644
--- a/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx
+++ b/studio/components/interfaces/BillingV2/Usage/SizeAndCounts.tsx
@@ -1,12 +1,14 @@
import { useParams } from 'common'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
-import BarChart from './BarChart'
+import SparkBar from 'components/ui/SparkBar'
import { useDailyStatsQuery } from 'data/analytics/daily-stats-query'
import { useProjectSubscriptionQuery } from 'data/subscriptions/project-subscription-query'
import { useProjectUsageQuery } from 'data/usage/project-usage-query'
-import SparkBar from 'components/ui/SparkBar'
import { formatBytes } from 'lib/helpers'
import { Button } from 'ui'
+import BarChart from './BarChart'
+import SectionContent from './SectionContent'
+import SectionHeader from './SectionHeader'
const SizeAndCounts = () => {
const { ref } = useParams()
@@ -40,148 +42,113 @@ const SizeAndCounts = () => {
return (
<>
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="sticky top-16">
- <p className="text-base">Size & Counts</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- </div>
- </div>
+ <SectionHeader title="Size & Counts" description="Some description here" />
- {/* DATABASE SIZE - need to fix if no value yet (API will return period_start as 0 in first data point) */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">Database size</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
+ <SectionContent title="Database Size" description="Some description here">
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <p className="text-sm">Database size per day</p>
+ <Button type="default" size="tiny" onClick={() => {}}>
+ Upgrade project
+ </Button>
+ </div>
+ <SparkBar
+ type="horizontal"
+ barClass="bg-scale-1200"
+ value={db_size?.usage ?? 0}
+ max={db_size?.limit ?? 0}
+ />
+ <div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">
+ Included in {subscription?.tier.name.toLowerCase()}
+ </p>
+ <p className="text-xs">{formatBytes(db_size?.limit ?? 0)}</p>
</div>
- <div className="col-span-7 space-y-6">
- <div className="space-y-2">
- <div className="flex items-center justify-between">
- <p className="text-sm">Database size per day</p>
- <Button type="default" size="tiny" onClick={() => {}}>
- Upgrade project
- </Button>
- </div>
- <SparkBar
- type="horizontal"
- barClass="bg-scale-1200"
- value={db_size?.usage ?? 0}
- max={db_size?.limit ?? 0}
- />
- <div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">
- Included in {subscription?.tier.name.toLowerCase()}
- </p>
- <p className="text-xs">{formatBytes(db_size?.limit ?? 0)}</p>
- </div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">Used</p>
- <p className="text-xs">{formatBytes(db_size?.usage ?? 0)}</p>
- </div>
- <div className="flex items-center justify-between py-1">
- <p className="text-xs text-scale-1000">Extra volume used this month</p>
- <p className="text-xs">
- {dbSizeExcess < 0 ? formatBytes(0) : formatBytes(dbSizeExcess)}
- </p>
- </div>
- </div>
- </div>
- <div className="space-y-1">
- <p>Database egress over time</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- {isLoadingDbSizeData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={TOTAL_DB_SIZE_KEY}
- data={dbSizeData?.data ?? []}
- unit={undefined}
- yDomain={[0, 100]}
- />
- )}
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">Used</p>
+ <p className="text-xs">{formatBytes(db_size?.usage ?? 0)}</p>
+ </div>
+ <div className="flex items-center justify-between py-1">
+ <p className="text-xs text-scale-1000">Extra volume used this month</p>
+ <p className="text-xs">
+ {dbSizeExcess < 0 ? formatBytes(0) : formatBytes(dbSizeExcess)}
+ </p>
</div>
</div>
</div>
- </div>
+ <div className="space-y-1">
+ <p>Database egress over time</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
+ </div>
+ {isLoadingDbSizeData ? (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ ) : (
+ <BarChart
+ attribute={TOTAL_DB_SIZE_KEY}
+ data={dbSizeData?.data ?? []}
+ unit={undefined}
+ yDomain={[0, 100]}
+ />
+ )}
+ </SectionContent>
- {/* STORAGE SIZE - need to fix if no value yet (API will return period_start as 0 in first data point) */}
- <div className="border-b">
- <div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 lg:px-16 2xl:px-32 py-16">
- <div className="grid grid-cols-12">
- <div className="col-span-5">
- <div className="sticky top-16">
- <p className="text-base">Storage size</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
+ <SectionContent title="Storage Size" description="Some description here">
+ <div className="space-y-2">
+ <div className="flex items-center justify-between">
+ <p className="text-sm">Storage {subscription?.tier.key.toLowerCase()} quota usage</p>
+ <Button type="default" size="tiny" onClick={() => {}}>
+ Upgrade project
+ </Button>
+ </div>
+ <SparkBar
+ type="horizontal"
+ barClass="bg-scale-1200"
+ value={storage_size?.usage ?? 0}
+ max={storage_size?.limit ?? 0}
+ />
+ <div>
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">
+ Included in {subscription?.tier.name.toLowerCase()}
+ </p>
+ <p className="text-xs">{formatBytes(storage_size?.limit ?? 0)}</p>
</div>
- <div className="col-span-7 space-y-6">
- <div className="space-y-2">
- <div className="flex items-center justify-between">
- <p className="text-sm">
- Storage {subscription?.tier.key.toLowerCase()} quota usage
- </p>
- <Button type="default" size="tiny" onClick={() => {}}>
- Upgrade project
- </Button>
- </div>
- <SparkBar
- type="horizontal"
- barClass="bg-scale-1200"
- value={storage_size?.usage ?? 0}
- max={storage_size?.limit ?? 0}
- />
- <div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">
- Included in {subscription?.tier.name.toLowerCase()}
- </p>
- <p className="text-xs">{formatBytes(storage_size?.limit ?? 0)}</p>
- </div>
- <div className="flex items-center justify-between border-b py-1">
- <p className="text-xs text-scale-1000">Used</p>
- <p className="text-xs">{formatBytes(storage_size?.usage ?? 0)}</p>
- </div>
- <div className="flex items-center justify-between py-1">
- <p className="text-xs text-scale-1000">Extra volume used this month</p>
- <p className="text-xs">
- {storageSizeExcess < 0 ? formatBytes(0) : formatBytes(storageSizeExcess)}
- </p>
- </div>
- </div>
- </div>
- <div className="space-y-1">
- <p>Storage size over time</p>
- <p className="text-sm text-scale-1000">Some description here</p>
- </div>
- {isLoadingStorageSizeData ? (
- <div className="space-y-2">
- <ShimmeringLoader />
- <ShimmeringLoader className="w-3/4" />
- <ShimmeringLoader className="w-1/2" />
- </div>
- ) : (
- <BarChart
- attribute={TOTAL_STORAGE_SIZE_KEY}
- data={storageSizeData?.data ?? []}
- unit={undefined}
- yDomain={[0, 100]}
- />
- )}
+ <div className="flex items-center justify-between border-b py-1">
+ <p className="text-xs text-scale-1000">Used</p>
+ <p className="text-xs">{formatBytes(storage_size?.usage ?? 0)}</p>
+ </div>
+ <div className="flex items-center justify-between py-1">
+ <p className="text-xs text-scale-1000">Extra volume used this month</p>
+ <p className="text-xs">
+ {storageSizeExcess < 0 ? formatBytes(0) : formatBytes(storageSizeExcess)}
+ </p>
</div>
</div>
</div>
- </div>
+ <div className="space-y-1">
+ <p>Storage size over time</p>
+ <p className="text-sm text-scale-1000">Some description here</p>
+ </div>
+ {isLoadingStorageSizeData ? (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ ) : (
+ <BarChart
+ attribute={TOTAL_STORAGE_SIZE_KEY}
+ data={storageSizeData?.data ?? []}
+ unit={undefined}
+ yDomain={[0, 100]}
+ />
+ )}
+ </SectionContent>
</>
)
}