Skip to content

Under the Hood: let users open a bounded range of past monthly reports - #234

Open
aunysillyme wants to merge 6 commits into
xai-org:mainfrom
aunysillyme:uth-report-history
Open

aunysillyme wants to merge 6 commits into
xai-org:mainfrom
aunysillyme:uth-report-history

Conversation

@aunysillyme

Copy link
Copy Markdown

Addresses the "pick a past month" ask in #232. Builds on #233 (merge that first; this branch contains its commits).

Problem

Only one month is ever reachable. Monthly aggregates are already stored keyed by (userId, monthBucket), but the serving column's view is Unit, so there is no way to ask for an earlier month, and a download always refetches the default month.

Change (behind under_the_hood_report_history_months, default 0 = off)

  • The serving column and its wrapper accept an optional requested month (YYYYMM, the existing monthBucket encoding), passed from an optional GraphQL $month variable.
  • Server-side validation. A request is honoured only when it meets all three conditions:
    • the switch value N > 0;
    • the month is at or before the default served month, so the one-month lag and the max-month cap are never bypassed;
    • the month is no more than N months before the default served month. N is clamped to 12, so the selector and the validation never reach further back than a year.
  • No substitution. An out-of-range month, or a month with incomplete data, returns the existing missing shape. It never silently substitutes another month.
  • No request means today's behaviour exactly.
  • UnderTheHoodReportInfo.availableMonths (new optional field) lists the selectable months; it is empty when history is off, and the selector renders only when it is non-empty.
  • A historical report says "Showing historical report for ." and omits the next-report date, which would already be in the past.
  • The month query parameter is carried through the landing page, the report page, the shared URL helper and the download route, so a historical report downloads the same month it shows.

Safety

With the switch at 0 the view is ignored, the GraphQL variable is undefined, and responses match the status branch.

Verification

Static, as in #233:

  • Range checks covered: disabled switch, inclusive bounds, invalid and future months, and year rollover.
  • Loader and URL month round-trip checked.
  • tsc --strict clean on _lib/report.ts.

Needs X's internal build: the non-Unit view syntax, ctx.view and the generated alias arguments. I followed the nearest in-repo precedent but could not compile them.

Mock states added: a historical month and an out-of-range request.

🤖 Generated with Claude Code

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