Skip to content

fix(profile): move "Newest first" toggle to the Usage over time chart - #864

Merged
junhoyeo merged 1 commit into
mainfrom
fix/usage-newest-first-toggle
Jul 12, 2026
Merged

fix(profile): move "Newest first" toggle to the Usage over time chart#864
junhoyeo merged 1 commit into
mainfrom
fix/usage-newest-first-toggle

Conversation

@junhoyeo

@junhoyeo junhoyeo commented Jul 12, 2026

Copy link
Copy Markdown
Owner

#863 put the reverse-render toggle on the wrong card: it belongs on Usage over time — the card in the right-hand column of the ≥1360px dashboard grid — not the Contributions calendar.

Removed (Contributions calendar)

Added (Usage over time)

  • "Newest first" checkbox in the controls row, persisted to tokscale:usage-newest-first.
  • Default: reversed on desktop (min-width: 1360px, where the card sits on the right) and chronological on mobile; an explicit choice always wins. SSR/first paint render chronological, the resolved value applies after mount (no hydration mismatch).
  • New pure reverseUsageChartData mirrors dates, per-series values, and daily totals together, so pointer, keyboard (←/→/Home/End), tooltip, and date-range labels all follow visual order with no per-consumer mirror logic. Trailing averages stay computed on chronological data; per-provider cost rows map the visual index back into the chronological days array. Idle inspection still defaults to the newest day on either edge.

Tests

  • Dropped the calendar-mirroring tests; added reverseUsageChartData coverage (per-day arrays mirrored + index-aligned, aggregates untouched, input not mutated, double-reverse round-trips).
  • tsc clean, eslint clean, 588 tests pass, production build passes.

Summary by cubic

Moved the "Newest first" toggle from the Contributions calendar to the Usage over time chart. The calendar is chronological again; the usage chart now mirrors time with correct interactions and a responsive default.

  • Bug Fixes
    • Moved the toggle to Usage over time; removed calendar mirroring and its storage key.
    • Usage chart reverses dates, series, and totals together so hover, keyboard, and tooltips follow visual order.
    • Toggle persists to tokscale:usage-newest-first; default is reversed on desktop (≥1360px) and chronological on mobile; applied after mount to avoid hydration mismatch.
    • Provider cost rows map the visual index back to chronological days; added tests for the reversal and removed calendar mirror tests.

Written for commit 139ad4c. Summary will update on new commits.

Review in cubic

The reverse-render toggle from #863 landed on the Contributions calendar,
but the request targeted the Usage over time chart — the card that sits in
the right-hand column of the >=1360px dashboard grid. Remove the calendar
mirroring entirely and mirror the usage chart's time axis instead.

The whole per-day pipeline (dates, series values, daily totals) is reversed
once in reverseUsageChartData, so pointer hit-testing, keyboard inspection,
tooltips, and the date-range labels all follow visual order with no special
cases. Trailing averages are computed on chronological data before the
mirror; per-provider cost lookups map the visual index back into the
chronological days array.

Constraint: SSR/first paint must stay chronological (no hydration mismatch);
the resolved default applies only after mount
Constraint: 30d trailing average must be computed pre-reversal
Rejected: reversing only the SVG x-mapping | every index consumer (tooltip,
keyboard, provider costs) would need its own mirror logic
Rejected: sharing one localStorage key with the removed calendar toggle |
stale "0"/"1" from the mistaken feature would silently override the new
responsive default
Confidence: high
Scope-risk: narrow
Directive: keep chartData display-ordered; anything indexing the
chronological `days` array must go through chronologicalActiveIndex
Not-tested: manual toggling while a committed (pinned) inspection is open on
a coarse-pointer device
@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tokscale Ready Ready Preview, Comment Jul 12, 2026 3:25pm

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Re-trigger cubic

@junhoyeo
junhoyeo merged commit 97296bb into main Jul 12, 2026
7 checks passed
@junhoyeo
junhoyeo deleted the fix/usage-newest-first-toggle branch July 12, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant