DamianPendrak commented on code in PR #39894:
URL: https://github.com/apache/superset/pull/39894#discussion_r3559367347


##########
superset-frontend/src/dashboard/actions/datasources.ts:
##########


Review Comment:
   tests fail without a `datasources?.[key]` guard here



##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx:
##########
@@ -187,6 +203,35 @@ const FilterValue: FC<FilterValueProps> = ({
   const [isRefreshing, setIsRefreshing] = useState(false);
   const dispatch = useDispatch();
 
+  // When a Date Range parent filter is active, the child filter needs
+  // granularity_sqla to apply the temporal WHERE clause. Read main_dttm_col
+  // from the Redux datasource cache as a fallback.
+  //
+  // The dashboard datasets API (/api/v1/dashboard/:id/datasets) only returns
+  // datasets used by chart slices, so native-filter-only datasets are never
+  // in state.datasources. Dispatch fetchDatasourceMetadata at mount time to
+  // populate the cache explicitly for those datasets.
+  const datasourceMainDttmCol = useSelector<RootState, string | undefined>(
+    state =>
+      datasetId != null
+        ? state.datasources?.[`${datasetId}__table`]?.main_dttm_col
+        : undefined,
+  );
+
+  useEffect(() => {
+    if (datasetId != null) {
+      // Best-effort prime of the datasource cache for the granularity_sqla
+      // fallback. A failure here is non-fatal — the filter still works, just
+      // without the time-range cascade fallback — so handle the rejection
+      // explicitly to avoid an unhandled promise rejection.
+      Promise.resolve(
+        dispatch(fetchDatasourceMetadata(`${datasetId}__table`)),
+      ).catch(error =>
+        logging.warn('Failed to fetch filter datasource metadata', error),
+      );
+    }
+  }, [datasetId, dispatch]);

Review Comment:
   Non-blocking: On cache hits, `setDatasource` still fires and the reducer 
mints a new `state.datasources` reference for an unchanged value 
(datasources.ts:35-40, no equality check), re-rendering every `FiltersBadge` 
and recomputing `chartsVerboseMapSelector`. We could check the cache first and 
only fetch datasets that aren't already loaded.



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