Skip to content

Commit 8ae6487

Browse files
talissoncostaclaude
andcommitted
refactor(usage): inline the explore section
UsageExplorer rendered no DOM of its own and forwarded four of its seven props straight to UsageOverTime. It was added to stop the page and the stories spelling out the same ordering twice, which was worth less than it looked: the stories never passed its loading state, and they already recompute every derived value the page does. The scoped loading branch moves into the page. It is still needed, and is not the page loader: only the filtered half reloads when the period or project changes, so the plan meter above it stays put. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 5876f13 commit 8ae6487

3 files changed

Lines changed: 48 additions & 84 deletions

File tree

frontend/documentation/components/UsageDashboard.stories.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import SectionHeading from 'components/pages/usage/components/SectionHeading'
66
import UsageBreakdown, {
77
useUsageBreakdown,
88
} from 'components/pages/usage/components/UsageBreakdown'
9-
import UsageExplorer from 'components/pages/usage/components/UsageExplorer'
109
import UsageMeter from 'components/pages/usage/components/UsageMeter'
10+
import UsageOverTime from 'components/pages/usage/components/UsageOverTime'
1111
import { overLimitNote, overLimitOf } from 'components/pages/usage/overLimit'
1212
import {
1313
allowanceWindow,
@@ -145,16 +145,10 @@ const UsagePage: FC<HarnessProps> = ({
145145
note={exceeded ? overLimitNote(exceeded) : contribution}
146146
/>
147147

148-
<UsageExplorer
149-
data={scoped}
150-
limit={
151-
showsPlanCeiling(billingPeriod, filtered ? 1 : undefined)
152-
? limit
153-
: undefined
154-
}
155-
isBillingPeriod={isBillingPeriodSelected(billingPeriod)}
156-
periodLabel={periodLabel(periods, billingPeriod)}
157-
filters={
148+
<SectionHeading
149+
title='Explore usage'
150+
hint='Narrow the chart and the breakdown by period or project.'
151+
action={
158152
<Row className='gap-2'>
159153
<div className='usage-filters__field'>
160154
<Select
@@ -178,13 +172,23 @@ const UsagePage: FC<HarnessProps> = ({
178172
</div>
179173
</Row>
180174
}
181-
breakdown={
182-
<UsageBreakdown
183-
{...breakdown}
184-
onChangeDimension={setDimension}
185-
scope={scope}
186-
/>
175+
/>
176+
177+
<UsageOverTime
178+
data={scoped}
179+
limit={
180+
showsPlanCeiling(billingPeriod, filtered ? 1 : undefined)
181+
? limit
182+
: undefined
187183
}
184+
isBillingPeriod={isBillingPeriodSelected(billingPeriod)}
185+
periodLabel={periodLabel(periods, billingPeriod)}
186+
/>
187+
188+
<UsageBreakdown
189+
{...breakdown}
190+
onChangeDimension={setDimension}
191+
scope={scope}
188192
/>
189193
</UsagePageLayout>
190194
)

frontend/web/components/pages/usage/UsageDashboardPage.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { useGetSubscriptionMetadataQuery } from 'common/services/useSubscription
66
import OverLimitBanner from './components/OverLimitBanner'
77
import SectionHeading from './components/SectionHeading'
88
import UsageBreakdown, { useUsageBreakdown } from './components/UsageBreakdown'
9-
import UsageExplorer from './components/UsageExplorer'
109
import UsageFilters from './components/UsageFilters'
1110
import UsageMeter from './components/UsageMeter'
11+
import UsageOverTime from './components/UsageOverTime'
1212
import UsagePageLayout from './components/UsagePageLayout'
1313
import { useUsageData } from './useUsageData'
1414
import { overLimitNote, overLimitOf } from './overLimit'
@@ -128,15 +128,10 @@ const UsageDashboardPage: FC<UsageDashboardPageProps> = ({
128128

129129
<UsageMeter total={allowanceTotal} limit={limit} note={meterNote} />
130130

131-
<UsageExplorer
132-
data={usage.scoped}
133-
limit={
134-
showsPlanCeiling(billingPeriod, selectedProjectId) ? limit : undefined
135-
}
136-
isBillingPeriod={isBillingPeriodSelected(billingPeriod)}
137-
periodLabel={periodLabel(periods, billingPeriod)}
138-
isLoading={usage.isLoadingScoped}
139-
filters={
131+
<SectionHeading
132+
title='Explore usage'
133+
hint='Narrow the chart and the breakdown by period or project.'
134+
action={
140135
<UsageFilters
141136
organisationId={organisationId}
142137
periods={periods}
@@ -149,14 +144,33 @@ const UsageDashboardPage: FC<UsageDashboardPageProps> = ({
149144
}}
150145
/>
151146
}
152-
breakdown={
147+
/>
148+
149+
{/* Only the filtered half reloads, so the meter above stays put. */}
150+
{usage.isLoadingScoped ? (
151+
<div className='text-center py-5'>
152+
<Loader />
153+
</div>
154+
) : (
155+
<>
156+
<UsageOverTime
157+
data={usage.scoped}
158+
limit={
159+
showsPlanCeiling(billingPeriod, selectedProjectId)
160+
? limit
161+
: undefined
162+
}
163+
isBillingPeriod={isBillingPeriodSelected(billingPeriod)}
164+
periodLabel={periodLabel(periods, billingPeriod)}
165+
/>
166+
153167
<UsageBreakdown
154168
{...breakdown}
155169
onChangeDimension={setDimension}
156170
scope={scope}
157171
/>
158-
}
159-
/>
172+
</>
173+
)}
160174
</UsagePageLayout>
161175
)
162176
}

frontend/web/components/pages/usage/components/UsageExplorer.tsx

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)