Files
a578708231 feat(studio): usage area brush up (#38408)
* fix: date range picker dropdown width

This fixes the date range pickers width on the Usage section. No more crumpled up menu items.

* chore: remove AI slop empty classes

* feat: get rid of legacy scaffold header on usage page

* chore: remove legacy scaffold from no permissions layout on usage

* feat: improve styling for sticky header area

* nit: small uppercase for a p

* fix: padding for no permission banner

Was missing the ScaffoldHeader wrapper

* feat: update loading skeleton for header area

* style: same breakpoints for header loading skeletons

* feat: remove ListBox in favour or Select_Shadcn_ for our project dropdown

* fix: logic for admonition when project is selected

* fix: remove rogue border from total usage grid

* fix: use proper background colour for sticky bar

* fix: more info link click area

* fix: reduce width of hover card on compute metrics

* feat: remove separator from usage section headers

* fix: revert width of hover cards for compute and billing metric

* fix type size and chevron tint

* only wrap anchored metrics in Link

otherwise non-anchored metrics get #undefined Link and unnecessary pointer

* style: shore up sections with headers

* fix: reset select state to undefined

The setSelectedProjectRef was causing our rings not to show on the usage table.

* Fixy

* Nit refactors and fixes

---------

Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-09-08 11:11:51 +01:00

100 lines
2.9 KiB
TypeScript

import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
import { DataPoint } from 'data/analytics/constants'
import type { OrgSubscription } from 'data/subscriptions/types'
import { useOrgUsageQuery } from 'data/usage/org-usage-query'
import SectionHeader from '../SectionHeader'
import { CategoryMetaKey, USAGE_CATEGORIES } from '../Usage.constants'
import AttributeUsage from './AttributeUsage'
import DiskUsage from './DiskUsage'
import { PricingMetric } from 'data/analytics/org-daily-stats-query'
import DatabaseSizeUsage from './DatabaseSizeUsage'
export interface ChartMeta {
[key: string]: { data: DataPoint[]; margin: number; isLoading: boolean }
}
export interface UsageSectionProps {
orgSlug: string
projectRef?: string
categoryKey: CategoryMetaKey
subscription?: OrgSubscription
chartMeta: ChartMeta
currentBillingCycleSelected: boolean
}
const UsageSection = ({
orgSlug,
projectRef,
categoryKey,
chartMeta,
subscription,
currentBillingCycleSelected,
}: UsageSectionProps) => {
const {
data: usage,
error: usageError,
isLoading: isLoadingUsage,
isError: isErrorUsage,
isSuccess: isSuccessUsage,
} = useOrgUsageQuery({ orgSlug })
const categoryMeta = USAGE_CATEGORIES(subscription).find(
(category) => category.key === categoryKey
)
if (!categoryMeta) return null
return (
<>
<ScaffoldContainer>
<SectionHeader
title={categoryMeta.name}
description={categoryMeta.description}
className="pb-0"
/>
</ScaffoldContainer>
{categoryMeta.attributes.map((attribute) =>
attribute.key === 'diskSize' ? (
<DiskUsage
key={attribute.name}
slug={orgSlug}
projectRef={projectRef}
attribute={attribute}
subscription={subscription}
currentBillingCycleSelected={currentBillingCycleSelected}
usage={usage}
/>
) : attribute.key === PricingMetric.DATABASE_SIZE ? (
<DatabaseSizeUsage
key={attribute.name}
slug={orgSlug}
projectRef={projectRef}
attribute={attribute}
subscription={subscription}
currentBillingCycleSelected={currentBillingCycleSelected}
usage={usage}
/>
) : (
<AttributeUsage
key={attribute.name}
slug={orgSlug}
projectRef={projectRef}
attribute={attribute}
usage={usage}
usageMeta={usage?.usages.find((x) => x.metric === attribute.key)}
chartMeta={chartMeta}
subscription={subscription}
error={usageError}
isLoading={isLoadingUsage}
isError={isErrorUsage}
isSuccess={isSuccessUsage}
currentBillingCycleSelected={currentBillingCycleSelected}
/>
)
)}
</>
)
}
export default UsageSection