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

   ### SUMMARY
   
   When a native Date Range filter is configured as the parent of a Select 
(Value)
   filter, the child filter's dropdown values should be constrained to the 
selected
   date range. This has never worked correctly due to three bugs in 
`FilterValue.tsx`:
   
   **Bug 1 — Missing `granularity_sqla`:** `getFormData` sends the parent's
   `time_range` via `extra_form_data` to the child's column-values API request, 
but
   sends no `granularity_sqla`. The backend receives the temporal constraint 
but has
   no column to apply it to and silently returns all values. Upstream PR #34137 
fixed
   the timing (child requests now wait for parent values) but did not address 
the
   missing column.
   
   **Bug 2 — Datasource not in Redux cache:** The fix for Bug 1 reads 
`main_dttm_col`
   from `state.datasources`, but `/api/v1/dashboard/:id/datasets` only returns 
datasets
   used by chart *slices*. Native-filter-only datasets are never in 
`state.datasources`.
   `fetchDatasourceMetadata` is now dispatched at mount time to populate the 
cache for
   those datasets.
   
   **Bug 3 — Stale React closure:** `datasourceMainDttmCol` was not in the main
   `useEffect` dependency array. Filters with a default date range would fire 
their
   effect before the async fetch completed and never re-run once the datasource 
loaded.
   
   ### Changes
   
   - `FilterValue.tsx`: import `fetchDatasourceMetadata`
   - `FilterValue.tsx`: dispatch `fetchDatasourceMetadata` at mount when 
`datasetId` is
     set, populating `state.datasources` for filter-only datasets
   - `FilterValue.tsx`: read `main_dttm_col` from the cache via `useSelector` 
and use it
     as a fallback `granularity_sqla` when `dependencies.time_range` is set
   - `FilterValue.tsx`: add `datasourceMainDttmCol` to the main `useEffect` dep 
array
   
   ### TESTING INSTRUCTIONS
   
   1. Create a dashboard with **no charts** (so no datasets are loaded via the 
slice API)
   2. Add a **Time range** native filter (parent)
   3. Add a **Value** native filter targeting a dataset that has a 
`main_dttm_col` (e.g.
      `birth_names`), with the Time range filter set as its parent
   4. Without a date range set: the Value filter shows all options
   5. Set a date range that contains no data in the dataset: Value filter shows 
"No data"
   6. Set a date range that contains a subset of the data: Value filter shows 
only the
      matching options
   7. Clear the date range: Value filter restores all options
   
   ### ADDITIONAL INFORMATION
   
   - Related issues: #24340 (time-range dependent filter cascading limitation)
   - No feature flags needed
   - No database migrations
   - No UI-visible changes (behaviour fix only)


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