feat: scope billing usage card to the selected time range - #4789
Merged
Conversation
🦋 Changeset detectedLatest commit: f7a85a5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Author
Contributor
Author
Demo: usage card follows the selected range
Demo: bar-click drill-down
|
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
daviddanialy
force-pushed
the
feat/billing-range-scoped-usage-card
branch
from
July 31, 2026 19:20
43455e9 to
56af5cd
Compare
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
danielkov
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


What
The billing page's usage card previously always showed the full billing cycle's position, even when the page was scoped to a custom date range (typed, calendar-picked, or bar-click drill-down). It now follows the selected range:
Jul 10 – Jul 20 · July Billing Cycle, or the picker's parse label like "Last 7 days"; the cycle suffix drops when the range spans cycles). Tokens Managed is the range's billed total, Overage is time-attributed — tokens recorded after the cycle's cumulative billed usage crossed the allowance, crossing day prorated — with an info tooltip. The per-unit average uses the range window. Allowance, percentage, and meter hide: they're cycle-level concepts and comparing days of traffic against a monthly number would mislead.—for overage with an explanatory tooltip.The details table's Overage column adopts the same attribution for custom ranges (it previously showed
—), and its Total row pins to the usage card's figure exactly, so the two surfaces always agree to the token.Code organization
The TUM billing module is split by responsibility so this is easier to extend:
billing-cycles.ts— pure domain logic: cycle/period types, billed-daily-series normalization (billedDaysFromCycles), the allowance-crossing overage walk (overageDaysFromBilled, shared by card and table), coverage checks, label formatting.use-billing-period.ts— new hook owning all period-selection state (cycle pick, range override, bar drill-down, reset).tum-token-breakdown.tsx/tum-admin-section.tsx— extracted from the section file.tum-usage-card.tsx— the card view plus its data-resolvingPeriodUsageCardwrapper.tum-section.tsx— thin composition only (~160 lines, was ~520).Seed
seed.mtsnow boosts days inside the active billing cycle so the current cycle lands clearly past the seeded 50M allowance (~190% of allowance), making the overage rendering visible in local dev regardless of when the seed runs.Testing
pnpm -F dashboard type-check,lint, andlint:formatpass.🤖 Generated with Claude Code
Summary by cubic
Scopes the billing usage card and details table to the selected time range so tokens and overage reflect the view; full-cycle behavior is unchanged. All surfaces (card, chart headline, table) now resolve shared billed figures and overage consistently, with clear fallbacks and failure states.
New Features
Refactors
PeriodUsageCard,use-billing-period.ts(DST-safe range parsing, drill‑down, reset), and new helpers inbilling-cycles.ts(billedDaysFromCycles,overageDaysFromBilled,resolvePeriodFigures,formatPeriodLabel). Extractedtum-token-breakdown.tsxandtum-admin-section.tsx;tum-section.tsxsimplified.TokenUsagePanelacceptsfailedto distinguish outages from empty ranges. Seed script boosts active-cycle usage with a weekend-aware multiplier to reliably surface overage in local dev.Written for commit f7a85a5. Summary will update on new commits.