Skip to content

fix(webapp): resolve env name & skip empty panels in usage breakdown#6704

Draft
macko911 wants to merge 2 commits into
masterfrom
matej/nan-6168-usage-breakdown-raw-env-id-leaks-into-apply-to-all-fan-out
Draft

fix(webapp): resolve env name & skip empty panels in usage breakdown#6704
macko911 wants to merge 2 commits into
masterfrom
matej/nan-6168-usage-breakdown-raw-env-id-leaks-into-apply-to-all-fan-out

Conversation

@macko911

@macko911 macko911 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

On the billing usage dashboard, "Apply to all" fanned an environment (or other fully-enumerated) filter onto every metric panel, including ones with no data for that value — those rendered the raw env id with a "No data" chart instead of staying unfiltered. Separately, the chart legend showed the raw environment id (e.g. 105) even though the filter chip resolved it to the name (e.g. dev).

Solution

  • "Apply to all" only sets an enumerated-dimension filter (environment, status) on panels that actually hold the value, and clears it on the rest so empty panels fall back to their unfiltered chart.
  • The "Apply to all" button dismisses itself once applied, instead of persisting against panels that can never match.
  • Resolve environment ids to names in the chart legend for both the filtered single-series and grouped-by-environment cases, reusing the top-dimension-values query the filter chip already warms; the raw id is kept on the series for drill-in.
  • Open-ended dimensions (integration, connection, model, …) keep the previous fan-out, since a value's absence from the fetched top-N there doesn't reliably mean "no data".

Fixes NAN-6168

Testing

  • Verified live against remote dev and prod: filtering a panel by environment and clicking Apply to all leaves no-data panels unfiltered while data-bearing panels get the filter, and the button disappears after applying.
  • Confirmed the legend shows the environment name (not the id) on interactive, grouped, and direct deep-link loads.
  • Added unit tests for isFullyEnumeratedDimension and the toChartSeries label resolver.

@linear-code

linear-code Bot commented Jul 7, 2026

Copy link
Copy Markdown

NAN-6168

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Preview Deploy

Status URL Deploy Logs Last Updated
✅ Ready Preview URL Deploy Logs 9 Jul 2026, 12:37 UTC

@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.

1 issue found across 8 files

Confidence score: 3/5

  • In packages/webapp/src/hooks/usePlan.tsx, the “Apply to all” flow can read top-dimension-values cached from a previous environment, so it may clear/apply panel filters using the wrong value set after an environment switch; this risks incorrect filter state for users until refreshed. Update the availability/cache lookup to include env (and invalidate old entries) before merging.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/webapp/src/hooks/usePlan.tsx">

<violation number="1" location="packages/webapp/src/hooks/usePlan.tsx:293">
P2: After switching environments, “Apply to all” can reuse `top-dimension-values` cached for the previous environment and clear/apply panel filters from the wrong value set. The new availability lookup should include `env` in the query key used by both `cachedHasValue` and `ensureHasValue` (and the existing top-dimension-values callers) so the cache is scoped to the request.</violation>
</file>

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

Re-trigger cubic

Comment thread packages/webapp/src/hooks/usePlan.tsx Outdated
async (metric: UsageMetric, dimension: string, value: string): Promise<boolean> => {
const data = await queryClient.ensureQueryData({
staleTime: TOP_DIMENSION_VALUES_STALE_TIME,
queryKey: topDimensionValuesQueryKey(timeframe, metric, dimension, limit),

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.

P2: After switching environments, “Apply to all” can reuse top-dimension-values cached for the previous environment and clear/apply panel filters from the wrong value set. The new availability lookup should include env in the query key used by both cachedHasValue and ensureHasValue (and the existing top-dimension-values callers) so the cache is scoped to the request.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/webapp/src/hooks/usePlan.tsx, line 293:

<comment>After switching environments, “Apply to all” can reuse `top-dimension-values` cached for the previous environment and clear/apply panel filters from the wrong value set. The new availability lookup should include `env` in the query key used by both `cachedHasValue` and `ensureHasValue` (and the existing top-dimension-values callers) so the cache is scoped to the request.</comment>

<file context>
@@ -266,6 +266,40 @@ export function useApiGetBillingUsageTopDimensionValues<M extends UsageMetric>(
+        async (metric: UsageMetric, dimension: string, value: string): Promise<boolean> => {
+            const data = await queryClient.ensureQueryData({
+                staleTime: TOP_DIMENSION_VALUES_STALE_TIME,
+                queryKey: topDimensionValuesQueryKey(timeframe, metric, dimension, limit),
+                queryFn: fetchTopDimensionValues(env, metric, dimension, timeframe, limit)
+            });
</file context>

@macko911 macko911 force-pushed the matej/nan-6168-usage-breakdown-raw-env-id-leaks-into-apply-to-all-fan-out branch from 12ce39b to f91e214 Compare July 8, 2026 08:32
@macko911 macko911 changed the base branch from master to matej/nan-6038-reach-any-value-when-filtering-usage-not-just-the-top-n July 8, 2026 08:32
Base automatically changed from matej/nan-6038-reach-any-value-when-filtering-usage-not-just-the-top-n to master July 9, 2026 10:18
macko911 added 2 commits July 9, 2026 14:32
Applying an environment (or other fully-enumerated) filter to all panels
fanned it onto every metric, including those with no data for the value.
Those panels rendered the raw env id with a "No data" chart instead of
staying unfiltered.

Apply to all now only sets an enumerated-dimension filter on panels that
actually hold the value and clears it on the rest, so panels without data
fall back to their unfiltered chart. The button also dismisses itself once
applied instead of persisting against panels that can never match.
Open-ended dimensions keep the previous fan-out, since a value being absent
from the fetched top-N there does not reliably mean "no data".
The usage chart legend showed the raw environment id (e.g. "105") while
the filter chip correctly resolved it to the name (e.g. "dev"). Environment
values are stored and returned as ids; only top-dimension-values carries the
display name.

Resolve env ids to names in the chart layer too, reusing the same
top-dimension-values query the chip already warms, for both the filtered
single-series and grouped-by-environment cases. The raw id is preserved on
the series so a drill-in still builds a valid filter param.
@macko911 macko911 force-pushed the matej/nan-6168-usage-breakdown-raw-env-id-leaks-into-apply-to-all-fan-out branch from f91e214 to c4d5437 Compare July 9, 2026 12:34
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