Skip to content

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

midway

Joshen Lim1a360a8e8ec7
diff --git a/studio/components/interfaces/Organization/Usage/Bandwidth.tsx b/studio/components/interfaces/Organization/Usage/Bandwidth.tsx
index ca2ead8f66a..ac8aa48591e 100644
--- a/studio/components/interfaces/Organization/Usage/Bandwidth.tsx
+++ b/studio/components/interfaces/Organization/Usage/Bandwidth.tsx
@@ -10,8 +10,8 @@ const MOCK_DATA = [
loopId: '1',
period_start: '2023-06-29T07:05:12Z',
periodStartFormatted: '29 Jun 2023',
- total_storage_egress: (1.5 * GB).toString(),
- total_egress_modified: (1 * GB).toString(),
+ total_storage_egress: (1.53 * GB).toString(),
+ total_egress_modified: (1.12 * GB).toString(),
},
{
id: '2',
diff --git a/studio/components/interfaces/Organization/Usage/Usage.constants.tsx b/studio/components/interfaces/Organization/Usage/Usage.constants.tsx
index d2db45b96b6..e70df805f7f 100644
--- a/studio/components/interfaces/Organization/Usage/Usage.constants.tsx
+++ b/studio/components/interfaces/Organization/Usage/Usage.constants.tsx
@@ -16,7 +16,7 @@ export const USAGE_STATUS = {
export interface CategoryAttribute {
anchor: string
key: string // Property from project usage
- attributes: { name: string; color: string }[] // For querying against stats-daily / infra-monitoring
+ attributes: { key: string; name?: string; color: 'white' | 'blue' | 'green' }[] // For querying against stats-daily / infra-monitoring, maybe can type the color
name: string
chartPrefix?: string
unit: 'bytes' | 'absolute' | 'percentage'
@@ -51,10 +51,10 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
attributes: [
{
anchor: 'dbEgress',
- key: 'db_egress',
+ key: 'db_egress', // This needs to be updated based on the new org usage endpoint
attributes: [
- { name: 'total_egress_modified', color: 'fill-green-1000' },
- { name: 'total_storage_egress', color: 'fill-blue-1000' },
+ { key: 'total_egress_modified', name: 'DB Egress', color: 'green' },
+ { key: 'total_storage_egress', name: 'Storage Egress', color: 'blue' },
],
name: 'Total Egress',
unit: 'bytes',
@@ -72,7 +72,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
{
anchor: 'dbSize',
key: 'db_size',
- attributes: [{ name: 'total_db_size_bytes', color: 'fill-scale-1200' }],
+ attributes: [{ key: 'total_db_size_bytes', color: 'white' }],
name: 'Database size',
chartPrefix: 'Average ',
unit: 'bytes',
@@ -154,7 +154,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
{
anchor: 'storageSize',
key: 'storage_size',
- attributes: [{ name: 'total_storage_size_bytes', color: 'fill-scale-1200' }],
+ attributes: [{ key: 'total_storage_size_bytes', color: 'white' }],
name: 'Storage Size',
chartPrefix: 'Max ',
unit: 'bytes',
@@ -171,7 +171,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
{
anchor: 'funcCount',
key: 'func_count',
- attributes: [{ name: 'total_func_count', color: 'fill-scale-1200' }],
+ attributes: [{ key: 'total_func_count', color: 'white' }],
name: 'Edge Function Count',
chartPrefix: 'Max ',
unit: 'absolute',
@@ -189,7 +189,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
{
anchor: 'mau',
key: 'monthly_active_users',
- attributes: [{ name: 'total_auth_billing_period_mau', color: 'fill-scale-1200' }],
+ attributes: [{ key: 'total_auth_billing_period_mau', color: 'white' }],
name: 'Monthly Active Users',
unit: 'absolute',
description:
@@ -206,7 +206,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
{
anchor: 'mauSso',
key: 'monthly_active_sso_users',
- attributes: [{ name: 'total_auth_billing_period_sso_mau', color: 'fill-scale-1200' }],
+ attributes: [{ key: 'total_auth_billing_period_sso_mau', color: 'white' }],
name: 'Monthly Active SSO Users',
unit: 'absolute',
description:
@@ -223,7 +223,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
{
anchor: 'storageImageTransformations',
key: 'storage_image_render_count',
- attributes: [{ name: 'total_storage_image_render_count', color: 'fill-scale-1200' }],
+ attributes: [{ key: 'total_storage_image_render_count', color: 'white' }],
name: 'Storage Image Transformations',
unit: 'absolute',
description:
@@ -240,7 +240,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
{
anchor: 'functionInvocations',
key: 'func_invocations',
- attributes: [{ name: 'total_func_invocations', color: 'fill-scale-1200' }],
+ attributes: [{ key: 'total_func_invocations', color: 'white' }],
name: 'Edge Function Invocations',
unit: 'absolute',
description:
@@ -256,7 +256,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
{
anchor: 'realtimeMessageCount',
key: 'realtime_message_count',
- attributes: [{ name: 'total_realtime_message_count', color: 'fill-scale-1200' }],
+ attributes: [{ key: 'total_realtime_message_count', color: 'white' }],
name: 'Realtime Message Count',
unit: 'absolute',
description:
@@ -272,7 +272,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [
{
anchor: 'realtimePeakConnection',
key: 'realtime_peak_connection',
- attributes: [{ name: 'total_realtime_peak_connection', color: 'fill-scale-1200' }],
+ attributes: [{ key: 'total_realtime_peak_connection', color: 'white' }],
name: 'Realtime Peak Connections',
chartPrefix: 'Max ',
unit: 'absolute',
diff --git a/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx b/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx
index c5e72e29f15..834442651c6 100644
--- a/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx
+++ b/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx
@@ -10,14 +10,24 @@ import {
YAxis,
} from 'recharts'
import dayjs from 'dayjs'
+import clsx from 'clsx'
// [Joshen] This BarChart is specifically for usage, hence not a reusable component, and not
// replacing the existing BarChart in ui/Charts
+// [Joshen] There's shit ton of clean up to do here for org billing because we were copying over from project usage
+// Please do so properly to prevent any confusion - priority on maintainability
+
+const COLOR_MAP = {
+ white: { bar: 'fill-scale-1200', marker: 'bg-scale-1200' },
+ green: { bar: 'fill-green-1000', marker: 'bg-green-1000' },
+ blue: { bar: 'fill-blue-1000', marker: 'bg-blue-1000' },
+}
+
export interface UsageBarChartProps {
data: DataPoint[]
name: string // Used within the tooltip
- attributes: { name: string; color: string }[]
+ attributes: { key: string; name?: string; color: 'white' | 'blue' | 'green' }[] // [JOSHEN TODO] Extract as type with Usage.constants
unit: 'bytes' | 'absolute' | 'percentage'
yLimit?: number
yLeftMargin?: number
@@ -55,6 +65,8 @@ const UsageBarChart = ({
<Tooltip
content={(props) => {
const { active, payload } = props
+
+ // [JOSHEN TODO] Refactor this, please do away with single attribute logics
if (active && payload && payload.length) {
const dataPeriod = dayjs(payload[0].payload.period_start)
const value =
@@ -63,13 +75,61 @@ const UsageBarChart = ({
: Number(payload[0].value)
return (
- <div className="w-[170px] border bg-scale-300 rounded-md px-2 py-2">
- {dataPeriod.startOf('day').isAfter(dayjs().startOf('day')) ? (
- <p className="text-scale-1000 text-lg">No data yet</p>
+ <div
+ className={clsx(
+ 'border bg-scale-300 rounded-md px-2 py-2',
+ attributes.length > 1 ? 'w-[250px]' : 'w-[170px]'
+ )}
+ >
+ {attributes.length > 1 ? (
+ <>
+ {dataPeriod.startOf('day').isAfter(dayjs().startOf('day')) ? (
+ <p className="text-scale-1000 text-lg">No data yet</p>
+ ) : (
+ <div className="space-y-1">
+ {attributes.map((attr) => {
+ const attrMeta = payload.find((x) => x.dataKey === attr.key)
+ const attrValue = Number(attrMeta?.value ?? 0)
+ const sumValue = payload.reduce((a, b) => a + Number(b.value), 0)
+ const percentageContribution = ((attrValue / sumValue) * 100).toFixed(
+ 1
+ )
+
+ return (
+ <div key={attr.name} className="flex items-center justify-between">
+ <div className="flex items-center space-x-2 w-[200px]">
+ <div
+ className={clsx(
+ 'w-3 h-3 rounded-full border',
+ COLOR_MAP[attr.color].marker
+ )}
+ />
+ <p className="text-sm prose">
+ {attr.name} ({percentageContribution}%):{' '}
+ </p>
+ </div>
+ <p className="text-sm tabular-nums">
+ {tooltipFormatter !== undefined
+ ? tooltipFormatter(attrValue)
+ : attrValue}
+ </p>
+ </div>
+ )
+ })}
+ </div>
+ )}
+ </>
) : (
- <p className="text-xl">
- {tooltipFormatter !== undefined ? tooltipFormatter(value) : value}
- </p>
+ <>
+ <p className="text-xs text-scale-1000">{name}</p>
+ {dataPeriod.startOf('day').isAfter(dayjs().startOf('day')) ? (
+ <p className="text-scale-1000 text-lg">No data yet</p>
+ ) : (
+ <p className="text-xl">
+ {tooltipFormatter !== undefined ? tooltipFormatter(value) : value}
+ </p>
+ )}
+ </>
)}
<p className="text-xs text-scale-1100 mt-1">
{dataPeriod.format('DD MMM YYYY')}
@@ -80,9 +140,9 @@ const UsageBarChart = ({
}}
/>
{attributes?.map((attr) => (
- <Bar key={attr.name} dataKey={attr.name} stackId="a">
+ <Bar key={attr.key} dataKey={attr.key} stackId="a">
{data.map((entry) => {
- return <Cell key={`${entry.period_start}`} className={attr.color} />
+ return <Cell key={`${entry.period_start}`} className={COLOR_MAP[attr.color].bar} />
})}
</Bar>
))}
diff --git a/studio/components/interfaces/Organization/Usage/UsageSection.tsx b/studio/components/interfaces/Organization/Usage/UsageSection.tsx
index 300507922c7..b8e4295bc67 100644
--- a/studio/components/interfaces/Organization/Usage/UsageSection.tsx
+++ b/studio/components/interfaces/Organization/Usage/UsageSection.tsx
@@ -67,7 +67,7 @@ const UsageSection = ({
const notAllValuesZero =
attribute.attributes
?.map((attr) => {
- return chartData.some((dataPoint) => Number(dataPoint[attr.name]) !== 0)
+ return chartData.some((dataPoint) => Number(dataPoint[attr.key]) !== 0)
})
.some((x) => !!x) ?? false