Repository navigation
feat: add groundwork for an "All" option on dashboard filters - #3830
karl-power wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Review process: Full human review — logic, architecture, edge cases. Stats
|
0b6cbdd to
21db794
Compare
|
E2E Test Results✅ All tests passed • 491 passed • 1 skipped • 1076s
Tests ran across 4 shards in parallel. |
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
| if (values?.type === 'variable') { | ||
| return { | ||
| included: new Set<string | boolean>(values.values), | ||
| included: new Set<string | boolean>(values.all ? [] : values.values), |
There was a problem hiding this comment.
🟡 P2 — resolveFilterSelection turns an all: true entry into an empty selection, so the app drops "All" whenever any filter changes
rebuildEntries in packages/app/src/hooks/useDashboardFilters.tsx:101-110 re-derives every declared variable's entry from resolveFilterSelection and only writes one back when included.size > 0. An all: true entry now resolves to included(), so it gets dropped. Steps: load ?filters=[{"type":"variable","name":"env","values":[],"all":true}] (the URL parser accepts this because DashboardFilterValueSchema now allows all), then change any other filter, and env's "All" disappears. The new serializer test never covers this path. Fix: carry the all flag through resolveFilterSelection or rebuildEntries, for example by copying parsed.byVariable's all entry over as-is, and add a test that setFilterValue on a sibling filter keeps the all entry.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Nothing sets all yet, so only a hand-written URL can reach this. The UI follow-up that adds the "All" option has to change useDashboardFilters.tsx anyway. I'll carry all through rebuildEntries there, with a test that changing a sibling filter keeps the entry.
PR Review
4 finding(s): 🔴 0 P0/P1 · 🟡 3 P2 · 🔵 1 P3 1 posted as inline comment(s) on the changed lines. 2 listed below. 1 P3 folded at the bottom. Findings outside the changed lines
🔵 1 P3 — no action needed before merge
Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. This is additive, intentionally-dormant groundwork: no UI or API path can set 🟡 P2 -- recommended
🔵 P3 nitpicks (3)
Reviewers (11): correctness, adversarial, security, testing, maintainability, api-contract, project-standards, agent-native, previous-comments, kieran-typescript, learnings-researcher. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
pulpdrew
left a comment
There was a problem hiding this comment.
LGTM, but one question about the intent / approach
| const sqlAllNoOp = (name: string) => | ||
| `(1=1 /** all values selected for variable '${name}' */)`; |
There was a problem hiding this comment.
OOC will this be configurable? Because for a filter that is dependent on another, "all values shown in the drop down" may not match "all values in the table" (1=1). Grafana compatibility makes sense though.
I am also wondering - what's the difference here between "No selection" and an "All selection" in this case? Both would get 1=1, right? I might not see the utility of a 1=1 all selection when we're not broadcasting an actual list of values.
There was a problem hiding this comment.
will this be configurable?
Depending on what you choose in the query, you can get the desired result: $__filter(whatever, $var) and $var use the narrowed dropdown's options, and $__conditionalAll gives 1=1 (so the whole set, not narrowed)
what's the difference here between "No selection" and an "All selection" in this case
For $__conditionalAll they're both 1=1. For $__filter, no selection is 1=1 and All is IN every option
21db794 to
a0b639c
Compare
a0b639c to
24e89e5
Compare
| if (values?.type === 'variable') { | ||
| return { | ||
| included: new Set<string | boolean>(values.values), | ||
| included: new Set<string | boolean>(values.all ? [] : values.values), |
There was a problem hiding this comment.
🟡 P2 — resolveFilterSelection turns an "all" entry into an empty selection, so callers can't tell "All" from "nothing selected"
FilterSelection has no way to carry "all", and the callers in packages/app/src/hooks/useDashboardFilters.tsx treat an empty included set as no selection. Two things break. First, rebuildEntries (line 105) only writes a variable back when selection.included.size > 0, so changing any sibling filter quietly removes another filter's {all: true} entry from the URL. Second, getUnsatisfiedRequiredFilters (line 400) counts a required filter with "All" selected as unsatisfied and blocks its tiles. parseDashboardFilterValues already accepts all: true from the filters= URL param today, so both paths can be hit now. Fix: carry an all flag through FilterSelection, or have resolveFilterSelection return the selection in a form that keeps it. Then update rebuildEntries and getUnsatisfiedRequiredFilters to keep "all" and count it as satisfying the filter. The new test at dashboardFilterValues.test.ts:458 locks in the current flattening, so it needs to change with the fix.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| name: z.string().min(1).max(1024), | ||
| values: z.array(z.string().max(10000)).max(1000), | ||
| /** When true, represents a selection of "all available values", and `values` is ignored. */ | ||
| all: z.literal(true).optional(), |
There was a problem hiding this comment.
🟡 P2 — Persisted variable entry accepts all: true together with non-empty values, which are then silently dropped
VariableFilterValueSchema lets {all: true, values: ['prod']} pass validation, and both serializeDashboardFilterValues and resolveFilterSelection throw values away. Because this format is stored in savedFilterValues and in filters= URLs, any shape accepted now has to stay valid forever. Make the invalid state unrepresentable before it ships: either a discriminated variant {type:'variable', name, all: true} with no values, or a refinement that requires values to be empty when all is set.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
- Add `allowAll` to static list and SQL query filters, and `all: true` to saved variable selections and chart variables - `$__conditionalAll` expands to `1=1` when "All" is selected, matching Grafana; `$__filter` and bare references keep the expanded options - Add `filterSupportsAllValue`, "all" selection helpers, `expandAllSelections` and validation for `allowAll` and saved "all" values - The external API and MCP reject `allowAll` and `all` until the dashboard UI offers "All"
24e89e5 to
f8f36ed
Compare
| if (values?.type === 'variable') { | ||
| return { | ||
| included: new Set<string | boolean>(values.values), | ||
| included: new Set<string | boolean>(values.all ? [] : values.values), |
There was a problem hiding this comment.
🟡 P2 — An "all" selection resolves to an empty selection, so the app's rebuild drops it and required filters count it as unselected
FilterSelection has no way to say "all", so an "all" entry becomes included: new Set(). Three things follow. (1) rebuildEntries in packages/app/src/hooks/useDashboardFilters.tsx:101-110 writes nothing for an empty included set. The name is declared, so the pass-through loop doesn't keep the entry either. Changing any sibling filter therefore deletes {all: true} from the filters= URL, and the schema already accepts that entry today. (2) getUnsatisfiedRequiredFilters sees size 0 and treats a required filter set to "All" as unsatisfied, which blocks its tiles. (3) The ChartVariables built at useDashboardFilters.tsx:336-350 never carry all, so $__conditionalAll gets no "all" signal. Fix: return an "all" marker from resolveFilterSelection (or a separate lookup), and have rebuildEntries, the required-filter check and ChartVariable construction keep it. The new test that pins the empty-set result locks in the lossy behaviour.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f8f36ed. Configure here.
| // offers "All". | ||
| const externalStaticListFilterShape = StaticListDashboardFilterSchema.omit({ | ||
| allowAll: true, | ||
| }).extend({ |
There was a problem hiding this comment.
GET responses leak held-back All fields
Low Severity
Omitting allowAll and all from the external request schemas does not strip them from GET responses. translateFilterToExternalFilter forwards the stored filter, and convertToExternalDashboard copies savedFilterValues as-is. The internal schema already persists these fields, so a GET body PUT back fails .strict() validation.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit f8f36ed. Configure here.


Summary
Adds the data model, macro behaviour, helpers and validation for an "All" option on static list and SQL query dashboard filters. Nothing can turn it on yet: there's no UI, and the external API and MCP reject the new fields. Follow-ups add the dropdown option, then enable it for each filter type.
allowAllon static list and SQL query filters opts a filter into offering "All". Multi-select filters only.all: trueon a saved variable selection (savedFilterValuesand thefilters=URL state) records that "All" is selected. Serialization keeps the entry even though it has no values.all: trueonChartVariablemarks "All" for template expansion.expandAllSelectionsfills such a variable'svalueswith its filter's options.$__conditionalAll(cond, $var)expands to1=1when "All" is selected, matching Grafana's ClickHouse plugin.$__filterand bare$varuse the expanded options, ascol IN ($var)does in Grafana.filterSupportsAllValuelimits "All" to filters whose option list the author controls. Query expression and Prometheus label options are capped and scoped to the time range, so "All" could miss values there.validateDashboardFilterFieldGatingrejectsallowAllon a single-select filter.validateDashboardSavedFilterValuesrejectsall: trueon a filter that doesn't offer "All"; it gets wired into the APIs with the UI.allowAllandallfrom its schemas until the dashboard UI offers "All".filterSupportsAllValuemirror the existing source-filter "All" support in EE, so EE can switch to these after the next upstream merge.How to test
cd packages/common-utils && yarn ci:unitmake dev-int FILE='src/routers/external-api/__tests__/dashboards.int.test.ts --testNamePattern=filter.validation'How to test on Vercel preview
N/A — non-UI change
References
Note
Medium Risk
Touches dashboard filter validation, saved state serialization, and SQL variable macro expansion, but external API rejects new fields until the UI ships.
Overview
Adds backend support for an "All" dashboard filter selection on multi-select static list and SQL query filters, without exposing it through the external API or UI yet.
Filters can define
allowAll; saved state andChartVariablecan carryall: true, with serialization, parsing, andexpandAllSelectionsto fill options for query templates. SQL macros$__conditionalAlland$__filtertreat "All" like Grafana (no-op / full IN list). NewfilterSupportsAllValueandvalidateDashboardSavedFilterValuesgate where "All" is allowed;validateDashboardFilterFieldGatingrejectsallowAllon single-select filters.The external API Zod schemas omit
allowAlland saved-valuealluntil the dashboard UI ships, with integration tests asserting 400 on those payloads.Reviewed by Cursor Bugbot for commit f8f36ed. Bugbot is set up for automated code reviews on this repo. Configure here.