Skip to content

fix: filters.single_select drops an exclude instead of showing only the excluded value - #10280

Open
nishantmonu51 wants to merge 13 commits into
mainfrom
nishant/fix-single-select-exclude
Open

nishantmonu51 wants to merge 13 commits into
mainfrom
nishant/fix-single-select-exclude

Conversation

@nishantmonu51

Copy link
Copy Markdown
Collaborator

For a dimension under filters.single_select (#10172), an exclude filter turned into an include of the excluded value. An alert or report link, bookmark, public URL or defaults.filters with country != 'US' opened showing only US. A canvas filter control with exclude: true on such a dimension (#10138) did the same.

Single-select filters now don't support exclude:

  • Frontend: a NOT IN or != on a single-select dimension is dropped wherever it comes from: url parsing, param normalization, a config that loads after the params, or YAML defaults. The dashboard opens without that filter (or asks for a value if the filter is required), never on the opposite of it. An IN of several values still keeps the last one.
  • Canvas controls: a filter control that excludes its defaults on a single-select dimension starts unset, and the control dialog no longer saves the excluded values as included ones. ValidateControls reports such a control.
  • Runtime: explore and canvas defaults.filters must give a single-select dimension one included value (dim = 'x' or dim IN ('x')), with one condition per dimension, checked through nested ANDs. Anything else fails to reconcile. single_select isn't in a release yet, so no released project starts failing.
  • History: narrowing a filter when the config loads after the params no longer notifies or pushes a history entry. It replaces the url, in Explore and Canvas.
  • Docs and AI instructions describe the rule.

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

…mensions

A single-select filter holds one value, so the frontend narrows anything else
and used to turn an exclude into an include of the excluded value.

- Explore and canvas `defaults.filters` must give a single-select dimension one value,
  `dim = 'x'` or `dim != 'x'`, and fail to reconcile otherwise.
- A canvas filter control on a single-select dimension can't set `exclude: true`;
  `ValidateControls` reports it and drops the control.
…t excludes

A single-select filter narrowed an exclude to an include of its last value,
so an alert or report link, a bookmark or a default filter with `dim != 'x'`
opened on `x` alone: the opposite of what it filtered.

The filter now keeps excluding one value, and a value picked in the chip, a
leaderboard or a chart is included as before. An exclude of several values keeps
excluding the last of them, which shows more data than the original rather than
the opposite. A canvas filter control on a single-select dimension drops a default
it excludes instead of including it.
When the dashboard config arrived after the filter params were parsed, narrowing
a single-select filter went through the same path as a viewer's change: it
reported "filter-changed" and pushed a new history entry, so Back returned to the
unnarrowed url, which narrowed again.

Narrowing now commits quietly and writes the narrowed param with
`stateChanged({ replace: true })`, which `syncToUrl` turns into `goto(..., { replaceState: true })`.
A viewer's change in the same microtask still pushes a history entry.
…d one

A filter control that excludes its default values holds one value once its
dimension is listed under `filters.single_select`. Saving it in the control
dialog wrote `exclude: false` with the first excluded value as the default,
so the control showed only the value it was meant to leave out.

The dialog still offers exclude only for a control that holds several values.
A control that excludes its default but holds one value now shows an error and
can't be saved until the builder clears the default or picks the value to
include, which matches the runtime's check in `ValidateControls`.
…filter

Explore writes its url from the explore state rather than through `syncToUrl`,
so the replace from the previous fix didn't reach it: when the spec listed a
filtered dimension under `filters.single_select` while the dashboard was open,
the narrowed filter still pushed a history entry.

`UrlParamsChangeTracker` exposes `isReplacing` while it emits "internal-change",
and `DashboardStateSync.gotoNewState`, which that event reaches synchronously
through the explore store, navigates with `replaceState` when it is set.
`metricssql.ParseFilter` builds `a AND b AND c` as `AND(AND(a, b), c)`, and the
check only looked inside the top-level AND, so a condition on a single-select
dimension anywhere but last in a filter with three or more conditions was
skipped: `country IN ('US', 'CA') AND device = 'mobile' AND os = 'ios'`
reconciled, and the frontend narrowed it to `country IN ('CA')`.

The check now flattens nested ANDs first, as the frontend's `flattenExpression`
does, and still leaves conditions under an OR alone. It also rejects a second
condition on the same single-select dimension, such as `foo != 'a' AND foo != 'b'`,
which would give the filter two values.
…alue

`filters.required` with `filters.single_select` is how a dashboard shows exactly
one value, for measures that mean nothing summed across values. An exclude
meets the requirement while showing every other value, so a default such as
`currency != 'USD'` on such a dimension now fails to reconcile, for explores and
canvases. A single-select dimension that isn't required can still exclude one value.
…r a value

An exclude counts as a value for the required filter gate, so a link, bookmark
or default that excluded one value of a dimension listed under both
`filters.required` and `filters.single_select` opened without the prompt and
showed every other value combined, which that pair of settings exists to prevent.

`narrowSingleSelectFilters` and `DimensionFilterManager.commit` now drop such an
exclude, and the required filter asks for a value. The narrowing takes the
dashboard config instead of a predicate, so it can tell whether a filter is
required. A single-select filter that isn't required keeps excluding one value.
A single-select filter holds one included value, so `defaults.filters` must give
such a dimension `dim = 'x'` or `dim IN ('x')`. A `!=` or `NOT IN` default now fails
to reconcile on every single-select dimension, so the check no longer needs the
explore's or canvas's required filters.
A single-select filter can't exclude values. An exclude from a link, bookmark,
default filter or late config is dropped: including the excluded value instead
would show the opposite. This replaces keeping one excluded value, which needed
a separate rule for required filters and extra handling when a value was picked.

The control dialog drops the defaults an exclude control holds once it holds one
value, as the canvas does, instead of blocking Save with an error.
A link that excludes values on a single-select filter opens without that filter,
and its default must include one value. The AI instructions say so too.
@nishantmonu51 nishantmonu51 added Type:Bug Something isn't working Area:Reconciler Area:Dashboard Size:M Medium change: 100-499 lines Area:Canvas Canvas dashboards labels Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area:Canvas Canvas dashboards Area:Dashboard Area:Reconciler Size:M Medium change: 100-499 lines Type:Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant