The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
A bit of clean up
Joshen Lim71592b814a2c
diff --git a/studio/components/interfaces/Organization/Usage/Bandwidth.tsx b/studio/components/interfaces/Organization/Usage/Bandwidth.tsxindex ac8aa48591e..36635299f93 100644--- a/studio/components/interfaces/Organization/Usage/Bandwidth.tsx+++ b/studio/components/interfaces/Organization/Usage/Bandwidth.tsx@@ -95,6 +95,7 @@ export interface BandwidthProps {currentBillingCycleSelected: boolean}+// [Joshen TODO] Needs to take in org slug and eventually use daily stats org queryconst Bandwidth = ({projectRef,subscription,diff --git a/studio/components/interfaces/Organization/Usage/Usage.constants.tsx b/studio/components/interfaces/Organization/Usage/Usage.constants.tsxindex e70df805f7f..533dc73cffc 100644--- a/studio/components/interfaces/Organization/Usage/Usage.constants.tsx+++ b/studio/components/interfaces/Organization/Usage/Usage.constants.tsx@@ -5,6 +5,12 @@ import { ProjectSubscriptionResponse } from 'data/subscriptions/project-subscripimport { ProjectUsageData } from 'data/usage/project-usage-query'import { Alert, Badge, Button, IconExternalLink } from 'ui'+export 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 const Y_DOMAIN_CEILING_MULTIPLIER = 4 / 3export const USAGE_STATUS = {@@ -13,10 +19,15 @@ export const USAGE_STATUS = {EXCEEDED: 'EXCEEDED',}+export interface Attribute {+ key: string+ name?: string+ color: 'white' | 'blue' | 'green'+}export interface CategoryAttribute {anchor: stringkey: string // Property from project usage- attributes: { key: string; name?: string; color: 'white' | 'blue' | 'green' }[] // For querying against stats-daily / infra-monitoring, maybe can type the color+ attributes: Attribute[] // For querying against stats-daily / infra-monitoringname: stringchartPrefix?: stringunit: 'bytes' | 'absolute' | 'percentage'@@ -42,7 +53,7 @@ export interface CategoryMeta {attributes: CategoryAttribute[]}-// [Joshen] We need to update this+// [Joshen TODO] We need to update thisexport const USAGE_CATEGORIES: CategoryMeta[] = [{key: 'bandwidth',diff --git a/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx b/studio/components/interfaces/Organization/Usage/UsageBarChart.tsxindex 834442651c6..337f43e6edd 100644--- a/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx+++ b/studio/components/interfaces/Organization/Usage/UsageBarChart.tsx@@ -11,23 +11,16 @@ import {} from 'recharts'import dayjs from 'dayjs'import clsx from 'clsx'+import { COLOR_MAP, Attribute } from './Usage.constants'+import { MultiAttributeTooltipContent, SingleAttributeTooltipContent } from './UsageChartTooltips'// [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: { key: string; name?: string; color: 'white' | 'blue' | 'green' }[] // [JOSHEN TODO] Extract as type with Usage.constants+ attributes: Attribute[]unit: 'bytes' | 'absolute' | 'percentage'yLimit?: numberyLeftMargin?: number@@ -46,7 +39,6 @@ const UsageBarChart = ({tooltipFormatter,}: UsageBarChartProps) => {const yMin = 0 // We can consider passing this as a prop if there's a use case in the future-const yDomain = [yMin, yLimit ?? 0]return (@@ -65,71 +57,31 @@ const UsageBarChart = ({<Tooltipcontent={(props) => {const { active, payload } = props-- // [JOSHEN TODO] Refactor this, please do away with single attribute logicsif (active && payload && payload.length) {const dataPeriod = dayjs(payload[0].payload.period_start)- const value =- unit === 'percentage'- ? Number(payload[0].value).toFixed(2)- : Number(payload[0].value)-+ const isAfterToday = dataPeriod.startOf('day').isAfter(dayjs().startOf('day'))return (<divclassName={clsx('border bg-scale-300 rounded-md px-2 py-2',- attributes.length > 1 ? 'w-[250px]' : 'w-[170px]'+ attributes.length > 1 && !isAfterToday ? '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>- )}- </>+ <MultiAttributeTooltipContent+ attributes={attributes}+ values={payload}+ isAfterToday={isAfterToday}+ tooltipFormatter={tooltipFormatter}+ />) : (- <>- <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>- )}- </>+ <SingleAttributeTooltipContent+ name={name}+ unit={unit}+ value={payload[0].value}+ tooltipFormatter={tooltipFormatter}+ isAfterToday={isAfterToday}+ />)}<p className="text-xs text-scale-1100 mt-1">{dataPeriod.format('DD MMM YYYY')}diff --git a/studio/components/interfaces/Organization/Usage/UsageChartTooltips.tsx b/studio/components/interfaces/Organization/Usage/UsageChartTooltips.tsxnew file mode 100644index 00000000000..3bddb5f962e--- /dev/null+++ b/studio/components/interfaces/Organization/Usage/UsageChartTooltips.tsx@@ -0,0 +1,80 @@+import clsx from 'clsx'+import { Payload, ValueType } from 'recharts/types/component/DefaultTooltipContent'+import { Attribute, COLOR_MAP } from './Usage.constants'++export interface SingleAttributeTooltipContentProps {+ name: string+ unit: 'bytes' | 'percentage' | 'absolute'+ value: any+ isAfterToday: boolean+ tooltipFormatter?: (value: any) => any+}++export const SingleAttributeTooltipContent = ({+ name,+ unit,+ value,+ isAfterToday,+ tooltipFormatter,+}: SingleAttributeTooltipContentProps) => {+ const formattedValue = unit === 'percentage' ? Number(value).toFixed(2) : Number(value)+ return (+ <>+ <p className="text-xs text-scale-1000">{name}</p>+ {isAfterToday ? (+ <p className="text-scale-1000 text-lg">No data yet</p>+ ) : (+ <p className="text-xl">+ {tooltipFormatter !== undefined ? tooltipFormatter(formattedValue) : formattedValue}+ </p>+ )}+ </>+ )+}++export interface MultiAttributeTooltipContentProps {+ attributes: Attribute[]+ values: Payload<ValueType, string | number>[]+ isAfterToday: boolean+ tooltipFormatter?: (value: any) => any+}++export const MultiAttributeTooltipContent = ({+ attributes,+ values,+ isAfterToday,+ tooltipFormatter,+}: MultiAttributeTooltipContentProps) => {+ return (+ <>+ {isAfterToday ? (+ <p className="text-scale-1000 text-lg">No data yet</p>+ ) : (+ <div className="space-y-1 pb-1">+ {attributes.map((attr) => {+ const attrMeta = values.find((x) => x.dataKey === attr.key)+ const attrValue = Number(attrMeta?.value ?? 0)+ const sumValue = values.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>+ )}+ </>+ )+}diff --git a/studio/components/interfaces/Organization/Usage/UsageSection.tsx b/studio/components/interfaces/Organization/Usage/UsageSection.tsxindex b8e4295bc67..65b67783c21 100644--- a/studio/components/interfaces/Organization/Usage/UsageSection.tsx+++ b/studio/components/interfaces/Organization/Usage/UsageSection.tsx@@ -35,6 +35,7 @@ interface UsageSectionProps {currentBillingCycleSelected: boolean}+// [Joshen TODO] Needs to change to use org slug, and eventually call useOrganizationUsageQueryconst UsageSection = ({projectRef,categoryKey,diff --git a/studio/pages/org/[slug]/billing.tsx b/studio/pages/org/[slug]/billing.tsxindex c91ad14096b..6ffb53b753b 100644--- a/studio/pages/org/[slug]/billing.tsx+++ b/studio/pages/org/[slug]/billing.tsx@@ -17,8 +17,6 @@ const OrgBillingSettings: NextPageWithLayout = () => {const { isLoading: isLoadingPermissions } = usePermissionsQuery()const showOAuthApps = useFlag('oauthApps')- const orgCreationV2 = useFlag('orgcreationv2')-const isOrgBilling = !!selectedOrganization?.subscription_idreturn (@@ -43,7 +41,7 @@ const OrgBillingSettings: NextPageWithLayout = () => {<Tabs.Panel id="general" label="General" /><Tabs.Panel id="team" label="Team" /><Tabs.Panel id="billing" label="Billing" className="!m-0" />- {orgCreationV2 && <Tabs.Panel id="usage" label="Usage" />}+ {isOrgBilling && <Tabs.Panel id="usage" label="Usage" />}<Tabs.Panel id="invoices" label="Invoices" />{showOAuthApps && <Tabs.Panel id="apps" label="OAuth Apps" />}</Tabs>