improvement(usage): add a period-labelled chart to the workspace drill-down

Merged
IC
2mo ago
+206-31

Summary

  • The Workspaces drill-down in the enterprise usage panel showed two ranked lists and no chart, and stated its window nowhere — the period picker lives on the list behind it, so the carried-over window was invisible once you were inside.
  • Draw the summary's headline, delta, and trend chart at the top of the drill-down, narrowed to that workspace.
  • Label that section with the selected period (Current period, Last 30 days, Aug 1 - Aug 28), which is now the only place the drill-down states its window.
  • Carry workspaceId through the summary contract, route, use case, query key, and hook so the chart reads one workspace.
  • Move the workspace narrowing onto buildUsageAnalyticsScope, so the chart, the headline, and both lists derive it from one definition instead of the breakdown query owning a second copy.

Two details worth a look in review:

  • The comparison window takes the same narrowing, or the delta would measure one workspace against the whole organization.
  • No allowance figure, unlike the Overview: the limit is pooled across the organization and under one workspace's total would read as that workspace's own cap.

workspace_id is not in usage_log_billing_entity_created_at_cost_idx, so a narrowed read heap-fetches per row — the cost the Workspaces list already pays to rank itself, and only paid inside a drill-down.

Type of Change

  • Improvement (UI + supporting API scope)

Testing

  • bun run test — 1,649 tests pass across ee/, lib/api/contracts, and the usage analytics/application suites; full lib/billing suite (731) passes
  • Added coverage: the scope narrowing survives all three window branches, and the summary's comparison window takes the same workspace filter
  • bun run type-check, bun run lint, bun run check:audits (38 audits incl. check:api-validation:strict, check:react-query, check:client-boundary) all pass
  • Not verified against a running instance — it needs a live enterprise organization with populated usage logs

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)