improvement(usage): add a period-labelled chart to the workspace drill-down - #7219
Merged
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
Greptile SummaryThe 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.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| 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
Reviews (2): Last reviewed commit: "fix(usage): stop a retained summary from..." | Re-trigger Greptile
There was a problem hiding this comment.
All reported issues were addressed across 11 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
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
Collaborator
Author
Collaborator
Author
|
@icecrasher321 I have started the AI code review. It will take a few minutes to complete. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Current period,Last 30 days,Aug 1 - Aug 28), which is now the only place the drill-down states its window.workspaceIdthrough the summary contract, route, use case, query key, and hook so the chart reads one workspace.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:
workspace_idis not inusage_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
Testing
bun run test— 1,649 tests pass acrossee/,lib/api/contracts, and the usage analytics/application suites; fulllib/billingsuite (731) passesbun run type-check,bun run lint,bun run check:audits(38 audits incl.check:api-validation:strict,check:react-query,check:client-boundary) all passChecklist