yuskhan opened a new pull request, #45599:
URL: https://github.com/apache/superset/pull/45599

   ### SUMMARY
   
   Adds a **Condition** native filter (`filter_condition`). Dashboard viewers 
pick an operator and a value for a column, and the condition applies to the 
scoped charts.
   
   Superset has separate Value and Numerical Range filters, but viewers can't 
build a condition like `price > 100` or `country IS NULL` themselves. This 
filter supports `=`, `!=`, `>`, `<`, `>=`, `<=`, `LIKE`, `IN`, `NOT IN`, `IS 
NULL` and `IS NOT NULL`. The proposal was discussed in apache/superset#42638.
   
   **Design decisions**
   - **Built like the Range filter.** It's a new plugin in 
`src/filters/components/Condition/`, registered next to the other native 
filters.
   - **No backend changes.** The filter emits one `{col, op, val}` clause in 
`extraFormData.filters`, the same format the other filters use. Scoping, 
cross-chart updates and SQL generation go through the existing path.
   - **Operators depend on the column's type.** The type comes from the 
filter's own query result, so it follows type changes made in the dataset 
editor or a semantic layer.
   
     | Column type | Operators offered |
     |---|---|
     | Text | `=`, `!=`, `IN`, `NOT IN`, `LIKE`, `IS NULL`, `IS NOT NULL` |
     | Number | `=`, `!=`, `>`, `<`, `>=`, `<=`, `IN`, `NOT IN`, `IS NULL`, `IS 
NOT NULL` |
     | Date/time | `=`, `!=`, `>`, `<`, `>=`, `<=`, `IS NULL`, `IS NOT NULL` |
     | True/false | `=`, `!=`, `IS NULL`, `IS NOT NULL` |
     | Array | `IS NULL`, `IS NOT NULL` |
   
   - **Invalid input is never sent to the dashboard.** This covers a 
non-numeric value on a number column, and a saved operator that no longer fits 
the column's type. The filter shows an inline error and the last valid 
condition stays in effect. The filter bar replaces a plugin's `validateStatus` 
with its own required-value check, so the error is computed and shown inside 
the plugin. Without this, Apply would become enabled and silently drop an 
already-applied filter. "Clear all" resets this local input too.
   - **Value suggestions.** `=`, `!=`, `IN` and `NOT IN` suggest the column's 
existing values, and users can also type new ones. Comparisons and `LIKE` use a 
text input.
   - **URL filters.** Rison URL filters (`?f=...`) are mapped onto Condition 
filters.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <img width="960" height="570" alt="conditions-filter-demo" 
src="https://github.com/user-attachments/assets/013842ef-60c9-4173-b5b9-1aebb237aa5d";
 />
   
   ### TESTING INSTRUCTIONS
   
   **Automated**
   - Frontend unit tests:
     ```
     npm run test -- src/filters/components/Condition 
src/dashboard/util/risonFilters
     ```
     These cover the plugin, value/operator logic, type-aware operators, 
invalid-input handling, "Clear all", and URL (rison) injection.
   - Backend:
     ```
     pytest tests/unit_tests/models/condition_filter_test.py
     ```
     Runs every operator through `get_sqla_query` against a real SQLite table 
and checks the rows returned. Also checks that `merge_extra_form_data` merges 
the clause into the chart's filters.
   
   **Manual**
   1. Open a dashboard and choose **Add/edit filters**, then **Filter type → 
Condition filter**. Pick a dataset and a numeric column and save.
   2. In the filter bar, choose `>`, type `100` and click **Apply filters**. 
The scoped charts show only rows with a value over 100.
   3. Add a second Condition filter on a text column. Its operator list offers 
`LIKE` but not `>`. Choose `IS NULL` and apply; both conditions combine.
   4. Switch the text filter to `IN`. The value picker suggests existing values.
   5. In the numeric filter, type `abc`. An inline error appears, **Apply 
filters** stays disabled, and the charts keep the previous condition.
   6. **Clear all** resets both filters and restores every row.
   
   **Already run on this branch**
   - `pre-commit run` passes, including mypy, ruff, oxlint, oxfmt and the 
frontend type check.
   - `tsc --noEmit` reports 0 errors.
   - All frontend tests in `src/filters`, `src/dashboard/util/risonFilters` and 
`src/dashboard/components/nativeFilters` pass.
   - 15 backend tests pass.
   - Steps 1–6 above were also run with a Playwright script against a live 
local Superset server.
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: 
https://github.com/apache/superset/discussions/42638
   - [ ] Required feature flags:
   - [x] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [x] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   **Known follow-ups:**
   - Replace the placeholder thumbnail, which is a copy of the Range filter's.
   - Add a Playwright spec to the repo's own suite.
   - Possibly gate the filter behind a feature flag if maintainers prefer.
   
   ---
   _Generated by [Claude 
Code](https://claude.ai/code/session_01Lt9yZSaV2MXNcWWF7bkgpb)_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to