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

   ### SUMMARY
   
   Fixes #44008. When a parent (cascading) native filter's value changes, 
dependent child filter selections are now cleared/reset so they cannot retain 
stale values from the old parent combination (e.g. `Country=UK` with a `City` 
that is only valid under `USA`), which previously produced impossible filter 
combinations that blank charts.
   
   **Root cause:** the dashboard filter tree only resolved *ancestors* 
(`resolveTransitiveParentIds`); nothing tracked *descendants*, so no code 
cleared a dependent filter's selection when its parent changed.
   
   **Fix:**
   - Add `resolveTransitiveChildIds()` to `dependencyGraph.ts` — the inverse 
walk over `cascadeParentIds` (builds a parent→children reverse adjacency map 
and BFS-walks it downward; cycle-safe, breadth-first order).
   - In `FilterBar.handleFilterSelectionChange`, detect a parent value change 
(`prevValue !== undefined && !isEqual(prevValue, nextValue)`) and, in the 
staged `dataMaskSelected` draft, reset every transitive descendant's 
`filterState.value` to `null` and clear its `extraFormData` (marking required 
children with `validateStatus: 'error'`).
   - Signal each descendant's filter plugin via a new `cascadeClearTrigger` 
prop (threaded through `Horizontal`/`Vertical` → `FilterControls` → 
`useFilterControlFactory` → `FilterControl` → `FilterValue` → SuperChart hooks 
→ `SelectFilterPlugin`), so the plugin clears its visual selection and does 
**not** re-apply `defaultToFirstItem` defaults (the same pattern already used 
for `clearAllTrigger`). `onCascadeClearComplete` removes the trigger once the 
child acknowledges the clear.
   - Set the cleared value to `null` (not `undefined`) to match the existing 
Clear All semantics: `undefined` is treated as "uninitialized" and would 
re-apply defaults.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A
   
   ### TESTING INSTRUCTIONS
   
   **Manual:**
   1. Create a dashboard with a cascading native filter pair, e.g. `Country` 
(select) with `City` (select, dependency: `Country`), both on the same dataset.
   2. Select a `Country` (e.g. `USA`) and a `City` (e.g. `New York`), click 
**Apply**.
   3. Change **Country** to a different value (e.g. `UK`).
   4. Verify the **City** selection is cleared (no stale `New York`) 
before/after clicking **Apply**.
   
   **Automated:**
   - 
`superset-frontend/src/dashboard/components/nativeFilters/dependencyGraph.test.ts`
 (new): unit tests for `resolveTransitiveChildIds` (direct children, chained, 
diamond dedup, mid-chain, cycles, filters that don't declare the parent).
   - `FilterBar/FilterControls/state.test.ts`: tests for 
`useTransitiveChildIds`.
   - `FilterBar.test.tsx`: integration test rendering `Country → City` and 
asserting that changing `Country` to `UK` clears `City` (value `null`, empty 
`extraFormData`) when applied.
   
   Verification command:
   ```bash
   npx jest src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx 
\
     src/dashboard/components/nativeFilters/dependencyGraph.test.ts \
     
src/dashboard/components/nativeFilters/FilterBar/FilterControls/state.test.ts \
     src/filters/components/Select/
   ```
   All 114 tests pass across the 6 suites.
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: #44008
   - [ ] 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
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


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