Skip to content

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

Merged
icecrasher321 merged 2 commits into
stagingfrom
staging-v81
Aug 28, 2026
Merged

improvement(usage): add a period-labelled chart to the workspace drill-down#7219
icecrasher321 merged 2 commits into
stagingfrom
staging-v81

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

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)

…l-down

The Workspaces drill-down 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 its section with the selected period, 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

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

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 28, 2026 6:02pm

Request Review

@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds a period-labelled usage summary and trend chart to the workspace drill-down, carrying workspace scope consistently through the client query, API contract, use case, comparison window, and analytics queries.

  • Adds workspace-scoped headline, delta, and chart rendering.
  • Centralizes workspace filtering in the shared analytics scope.
  • Restricts retained summary placeholders to period changes within the same organization and workspace.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/hooks/queries/organization-usage.ts Restricts placeholder retention to period changes within the same organization and workspace, resolving the previously reported scope crossover.
apps/sim/hooks/queries/utils/organization-usage-keys.ts Adds workspace identity to summary keys and places the period last so placeholder comparison preserves scope boundaries.
apps/sim/ee/organization-usage/components/usage-monitoring.tsx Adds the period-labelled, workspace-scoped summary chart and propagates placeholder state to summary rendering.
apps/sim/lib/billing/application/organization-usage/get-organization-usage-summary.ts Applies the same workspace scope to current totals, time series, and comparison totals.
apps/sim/lib/billing/core/usage-analytics.ts Centralizes optional workspace narrowing alongside the existing billing-entity and time-window predicates.

Sequence Diagram

sequenceDiagram
  participant UI as Workspace drill-down
  participant Hook as Usage summary hook
  participant API as Usage summary route
  participant UseCase as Summary use case
  participant DB as Usage analytics queries
  UI->>Hook: organizationId, workspaceId, period
  Hook->>API: Scoped summary request
  API->>UseCase: Validated workspaceId and window
  UseCase->>DB: Current-window scoped reads
  UseCase->>DB: Comparison-window scoped totals
  DB-->>UseCase: Headline, trend, comparison
  UseCase-->>UI: Workspace usage summary
Loading

Reviews (2): Last reviewed commit: "fix(usage): stop a retained summary from..." | Re-trigger Greptile

Comment thread apps/sim/hooks/queries/organization-usage.ts Outdated

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 11 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/hooks/queries/organization-usage.ts Outdated
The summary key now carries a workspaceId, and keepPreviousData retains
across any key change — so moving between two drill-downs drew one
workspace's headline, delta, and chart under the other's name until the
fetch landed.

- Narrow placeholderData to a period change only, matching the breakdown's
  existing scoped predicate, and share the one key-identity helper
- Order the summary key so window is the trailing segment, making the
  scope a plain prefix as it already is on the breakdown
- Give UsageSummary the isPlaceholderData signal UsageConsumers already
  takes, so retained figures dim instead of reading as fresh ones
@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321

Copy link
Copy Markdown
Collaborator Author

@cubic

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 28, 2026

Copy link
Copy Markdown

@cubic

@icecrasher321 I have started the AI code review. It will take a few minutes to complete.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 12 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@icecrasher321
icecrasher321 merged commit b094b4d into staging Aug 28, 2026
27 checks passed
@icecrasher321
icecrasher321 deleted the staging-v81 branch August 28, 2026 18:25
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