The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update UsageBarChart to accept a list of attributes, instead of a single one
Joshen Lim7d5096d3ca6d
diff --git a/studio/components/interfaces/Organization/Usage/Bandwidth.tsx b/studio/components/interfaces/Organization/Usage/Bandwidth.tsxindex ef46ec26dc3..ca2ead8f66a 100644--- a/studio/components/interfaces/Organization/Usage/Bandwidth.tsx+++ b/studio/components/interfaces/Organization/Usage/Bandwidth.tsx@@ -3,6 +3,90 @@ import { useDailyStatsQuery } from 'data/analytics/daily-stats-query'import { ProjectSubscriptionResponse } from 'data/subscriptions/project-subscription-v2-query'import UsageSection from './UsageSection'+const GB = 1073741824+const MOCK_DATA = [+ {+ id: '1',+ 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(),+ },+ {+ id: '2',+ loopId: '2',+ period_start: '2023-06-30T07:05:12Z',+ periodStartFormatted: '30 Jun 2023',+ total_storage_egress: (1 * GB).toString(),+ total_egress_modified: (1.1 * GB).toString(),+ },+ {+ id: '3',+ loopId: '3',+ period_start: '2023-07-01T07:05:12Z',+ periodStartFormatted: '01 Jul 2023',+ total_storage_egress: (1 * GB).toString(),+ total_egress_modified: (1.2 * GB).toString(),+ },+ {+ id: '4',+ loopId: '4',+ period_start: '2023-07-02T07:05:12Z',+ periodStartFormatted: '02 Jul 2023',+ total_storage_egress: (1 * GB).toString(),+ total_egress_modified: (1.5 * GB).toString(),+ },+ {+ id: '5',+ loopId: '5',+ period_start: '2023-07-03T07:05:12Z',+ periodStartFormatted: '03 Jul 2023',+ total_storage_egress: (1 * GB).toString(),+ total_egress_modified: (2 * GB).toString(),+ },+ {+ id: '6',+ loopId: '6',+ period_start: '2023-07-04T07:05:12Z',+ periodStartFormatted: '04 Jul 2023',+ total_storage_egress: (1 * GB).toString(),+ total_egress_modified: (3 * GB).toString(),+ },+ {+ id: '7',+ loopId: '7',+ period_start: '2023-07-05T07:05:12Z',+ periodStartFormatted: '05 Jul 2023',+ total_storage_egress: (1 * GB).toString(),+ total_egress_modified: (4.5 * GB).toString(),+ },+ {+ id: '8',+ loopId: '8',+ period_start: '2023-07-06T07:05:12Z',+ periodStartFormatted: '06 Jul 2023',+ total_storage_egress: (1 * GB).toString(),+ total_egress_modified: (4 * GB).toString(),+ },+ {+ id: '9',+ loopId: '9',+ period_start: '2023-07-07T07:05:12Z',+ periodStartFormatted: '07 Jul 2023',+ total_storage_egress: (1 * GB).toString(),+ total_egress_modified: (3.8 * GB).toString(),+ },+ {+ id: '10',+ loopId: '10',+ period_start: '2023-07-08T07:05:12Z',+ periodStartFormatted: '08 Jul 2023',+ total_storage_egress: (1 * GB).toString(),+ total_egress_modified: (3.5 * GB).toString(),+ },+]+export interface BandwidthProps {projectRef: stringstartDate: string | undefined@@ -18,22 +102,22 @@ const Bandwidth = ({endDate,currentBillingCycleSelected,}: BandwidthProps) => {- const { data: dbEgressData, isLoading: isLoadingDbEgressData } = useDailyStatsQuery({- projectRef,- attribute: 'total_egress_modified',- interval: '1d',- startDate,- endDate,- })+ // const { data: dbEgressData, isLoading: isLoadingDbEgressData } = useDailyStatsQuery({+ // projectRef,+ // attribute: 'total_egress_modified',+ // interval: '1d',+ // startDate,+ // endDate,+ // })const chartMeta: {[key: string]: { data: DataPoint[]; margin: number; isLoading: boolean; hasNoData: boolean }} = {db_egress: {- data: dbEgressData?.data ?? [],+ data: MOCK_DATA, // dbEgressData?.data ?? [],margin: 16,- isLoading: isLoadingDbEgressData,- hasNoData: dbEgressData?.hasNoData ?? false,+ isLoading: false, // isLoadingDbEgressData,+ hasNoData: false, // dbEgressData?.hasNoData ?? false,},}diff --git a/studio/components/interfaces/Organization/Usage/Usage.constants.tsx b/studio/components/interfaces/Organization/Usage/Usage.constants.tsxindex 0cbb438d5c2..d2db45b96b6 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: stringkey: string // Property from project usage- attribute: string // For querying against stats-daily / infra-monitoring+ attributes: { name: string; color: string }[] // For querying against stats-daily / infra-monitoringname: stringchartPrefix?: stringunit: 'bytes' | 'absolute' | 'percentage'@@ -42,6 +42,7 @@ export interface CategoryMeta {attributes: CategoryAttribute[]}+// [Joshen] We need to update thisexport const USAGE_CATEGORIES: CategoryMeta[] = [{key: 'bandwidth',@@ -51,7 +52,10 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'dbEgress',key: 'db_egress',- attribute: 'total_egress_modified',+ attributes: [+ { name: 'total_egress_modified', color: 'fill-green-1000' },+ { name: 'total_storage_egress', color: 'fill-blue-1000' },+ ],name: 'Total Egress',unit: 'bytes',description:@@ -68,7 +72,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'dbSize',key: 'db_size',- attribute: 'total_db_size_bytes',+ attributes: [{ name: 'total_db_size_bytes', color: 'fill-scale-1200' }],name: 'Database size',chartPrefix: 'Average ',unit: 'bytes',@@ -150,7 +154,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'storageSize',key: 'storage_size',- attribute: 'total_storage_size_bytes',+ attributes: [{ name: 'total_storage_size_bytes', color: 'fill-scale-1200' }],name: 'Storage Size',chartPrefix: 'Max ',unit: 'bytes',@@ -167,7 +171,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'funcCount',key: 'func_count',- attribute: 'total_func_count',+ attributes: [{ name: 'total_func_count', color: 'fill-scale-1200' }],name: 'Edge Function Count',chartPrefix: 'Max ',unit: 'absolute',@@ -185,7 +189,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'mau',key: 'monthly_active_users',- attribute: 'total_auth_billing_period_mau',+ attributes: [{ name: 'total_auth_billing_period_mau', color: 'fill-scale-1200' }],name: 'Monthly Active Users',unit: 'absolute',description:@@ -202,7 +206,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'mauSso',key: 'monthly_active_sso_users',- attribute: 'total_auth_billing_period_sso_mau',+ attributes: [{ name: 'total_auth_billing_period_sso_mau', color: 'fill-scale-1200' }],name: 'Monthly Active SSO Users',unit: 'absolute',description:@@ -219,7 +223,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'storageImageTransformations',key: 'storage_image_render_count',- attribute: 'total_storage_image_render_count',+ attributes: [{ name: 'total_storage_image_render_count', color: 'fill-scale-1200' }],name: 'Storage Image Transformations',unit: 'absolute',description:@@ -236,7 +240,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'functionInvocations',key: 'func_invocations',- attribute: 'total_func_invocations',+ attributes: [{ name: 'total_func_invocations', color: 'fill-scale-1200' }],name: 'Edge Function Invocations',unit: 'absolute',description:@@ -252,7 +256,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'realtimeMessageCount',key: 'realtime_message_count',- attribute: 'total_realtime_message_count',+ attributes: [{ name: 'total_realtime_message_count', color: 'fill-scale-1200' }],name: 'Realtime Message Count',unit: 'absolute',description:@@ -268,7 +272,7 @@ export const USAGE_CATEGORIES: CategoryMeta[] = [{anchor: 'realtimePeakConnection',key: 'realtime_peak_connection',- attribute: 'total_realtime_peak_connection',+ attributes: [{ name: 'total_realtime_peak_connection', color: 'fill-scale-1200' }],name: 'Realtime Peak Connections',chartPrefix: 'Max ',unit: 'absolute',diff --git a/studio/components/interfaces/Organization/Usage/Usage.tsx b/studio/components/interfaces/Organization/Usage/Usage.tsxindex 650b0cd0582..e6123655fd5 100644--- a/studio/components/interfaces/Organization/Usage/Usage.tsx+++ b/studio/components/interfaces/Organization/Usage/Usage.tsx@@ -1,3 +1,4 @@+import clsx from 'clsx'import dayjs from 'dayjs'import { useMemo, useState } from 'react'@@ -8,13 +9,12 @@ import DateRangePicker from 'components/to-be-cleaned/DateRangePicker'import { TIME_PERIODS_BILLING, TIME_PERIODS_REPORTS } from 'lib/constants'import SizeAndCounts from './SizeAndCounts'import Activity from './Activity'+import { IconLoader } from 'ui'const Usage = () => {const { slug } = useParams()const [dateRange, setDateRange] = useState<any>()- const selectedProjectRef = 'kojplftaeiavuneadgix'-const {data: subscription,isLoading: isLoadingSubscription,@@ -22,6 +22,10 @@ const Usage = () => {isSuccess,} = useOrgSubscriptionQuery({ orgSlug: slug })+ const selectedProjectRef = 'kojplftaeiavuneadgix'+ const billingCycleStart = dayjs.unix(subscription?.current_period_start ?? 0).utc()+ const billingCycleEnd = dayjs.unix(subscription?.current_period_end ?? 0).utc()+const currentBillingCycleSelected = useMemo(() => {// Selected by defaultif (!dateRange?.period_start || !dateRange?.period_end || !subscription) return true@@ -61,16 +65,33 @@ const Usage = () => {return (<>- <DateRangePicker- id="billingCycle"- name="billingCycle"- onChange={setDateRange}- value={TIME_PERIODS_BILLING[0].key}- options={[...TIME_PERIODS_BILLING, ...TIME_PERIODS_REPORTS]}- loading={isLoadingSubscription}- currentBillingPeriodStart={subscription?.current_period_start}- className="!w-[200px]"- />+ <div className="flex items-center space-x-4 px-4 py-4 border-b">+ {!isLoadingSubscription && (+ <DateRangePicker+ id="billingCycle"+ name="billingCycle"+ onChange={setDateRange}+ value={TIME_PERIODS_BILLING[0].key}+ options={[...TIME_PERIODS_BILLING, ...TIME_PERIODS_REPORTS]}+ loading={isLoadingSubscription}+ currentBillingPeriodStart={subscription?.current_period_start}+ className="!w-[200px]"+ />+ )}++ {isLoadingSubscription ? (+ <IconLoader className="animate-spin" size={14} />+ ) : subscription !== undefined ? (+ <div className="flex flex-col xl:flex-row xl:gap-3">+ <p className={clsx('text-sm transition', isLoadingSubscription && 'opacity-50')}>+ Organization is on the {subscription.plan.name} plan+ </p>+ <p className="text-sm text-scale-1000">+ {billingCycleStart.format('DD MMM YYYY')} - {billingCycleEnd.format('DD MMM YYYY')}+ </p>+ </div>+ ) : null}+ </div><BandwidthprojectRef={selectedProjectRef}subscription={subscription}diff --git a/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx b/studio/components/interfaces/Organization/Usage/UsageBarChart.tsxindex c93733f5eb6..c5e72e29f15 100644--- a/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx+++ b/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx@@ -17,7 +17,7 @@ import dayjs from 'dayjs'export interface UsageBarChartProps {data: DataPoint[]name: string // Used within the tooltip- attribute: string+ attributes: { name: string; color: string }[]unit: 'bytes' | 'absolute' | 'percentage'yLimit?: numberyLeftMargin?: number@@ -28,18 +28,17 @@ export interface UsageBarChartProps {const UsageBarChart = ({data,name,- attribute,+ attributes,unit,yLimit,yLeftMargin = 10,yFormatter,- tooltipFormatter+ tooltipFormatter,}: UsageBarChartProps) => {const yMin = 0 // We can consider passing this as a prop if there's a use case in the futureconst yDomain = [yMin, yLimit ?? 0]-return (<div className="w-full h-[200px]"><ResponsiveContainer width="100%" height={200}>@@ -65,9 +64,6 @@ const UsageBarChart = ({return (<div className="w-[170px] border bg-scale-300 rounded-md px-2 py-2">- <p className="text-xs text-scale-1000">- {attribute === 'disk_io_budget' ? `Remaining IO budget:` : `${name}:`}- </p>{dataPeriod.startOf('day').isAfter(dayjs().startOf('day')) ? (<p className="text-scale-1000 text-lg">No data yet</p>) : (@@ -83,11 +79,13 @@ const UsageBarChart = ({} else return null}}/>- <Bar dataKey={attribute}>- {data.map((entry) => {- return <Cell key={`${entry.period_start}`} className="fill-scale-1200" />- })}- </Bar>+ {attributes?.map((attr) => (+ <Bar key={attr.name} dataKey={attr.name} stackId="a">+ {data.map((entry) => {+ return <Cell key={`${entry.period_start}`} className={attr.color} />+ })}+ </Bar>+ ))}</ComposedChart></ResponsiveContainer></div>diff --git a/studio/components/interfaces/Organization/Usage/UsageSection.tsx b/studio/components/interfaces/Organization/Usage/UsageSection.tsxindex 9b67c1fd239..300507922c7 100644--- a/studio/components/interfaces/Organization/Usage/UsageSection.tsx+++ b/studio/components/interfaces/Organization/Usage/UsageSection.tsx@@ -1,28 +1,29 @@+import * as Tooltip from '@radix-ui/react-tooltip'+import clsx from 'clsx'+import Link from 'next/link'++import { USAGE_APPROACHING_THRESHOLD } from 'components/interfaces/BillingV2/Billing.constants'+import Panel from 'components/ui/Panel'import ShimmeringLoader from 'components/ui/ShimmeringLoader'-import SectionHeader from './SectionHeader'-import { CategoryMetaKey, USAGE_CATEGORIES } from './Usage.constants'+import SparkBar from 'components/ui/SparkBar'+import { DataPoint } from 'data/analytics/constants'+import { ProjectSubscriptionResponse } from 'data/subscriptions/project-subscription-v2-query'import {ProjectUsageResponse,UsageMetric,useProjectUsageQuery,} from 'data/usage/project-usage-query'-import { DataPoint } from 'data/analytics/constants'-import SectionContent from './SectionContent'+import { formatBytes } from 'lib/helpers'import { Button, IconAlertTriangle, IconBarChart2 } from 'ui'-import { USAGE_APPROACHING_THRESHOLD } from 'components/interfaces/BillingV2/Billing.constants'-import Link from 'next/link'-import SparkBar from 'components/ui/SparkBar'-import clsx from 'clsx'-import { ProjectSubscriptionResponse } from 'data/subscriptions/project-subscription-v2-query'+import SectionContent from './SectionContent'+import SectionHeader from './SectionHeader'+import { CategoryMetaKey, USAGE_CATEGORIES } from './Usage.constants'import {ChartTooltipValueFormatter,ChartYFormatterCompactNumber,getUpgradeUrl,} from './Usage.utils'-import { formatBytes } from 'lib/helpers'import UsageBarChart from './UsageBarChart'-import Panel from 'components/ui/Panel'-import * as Tooltip from '@radix-ui/react-tooltip'interface UsageSectionProps {projectRef: string@@ -63,9 +64,12 @@ const UsageSection = ({const chartData = chartMeta[attribute.key]?.data ?? []- const notAllValuesZero = chartData.some(- (dataPoint) => Number(dataPoint[attribute.attribute]) !== 0- )+ const notAllValuesZero =+ attribute.attributes+ ?.map((attr) => {+ return chartData.some((dataPoint) => Number(dataPoint[attr.name]) !== 0)+ })+ .some((x) => !!x) ?? falsereturn (<div id={attribute.anchor} key={attribute.key}>@@ -229,7 +233,7 @@ const UsageSection = ({<UsageBarChartname={`${attribute.chartPrefix || ''}${attribute.name}`}unit={attribute.unit}- attribute={attribute.attribute}+ attributes={attribute.attributes}data={chartData}yLeftMargin={chartMeta[attribute.key].margin}yFormatter={(value) => ChartYFormatterCompactNumber(value, attribute.unit)}diff --git a/studio/components/interfaces/Organization/Usage/UsageStackedBarChart.tsx b/studio/components/interfaces/Organization/Usage/UsageStackedBarChart.tsxnew file mode 100644index 00000000000..e69de29bb2d