msyavuz commented on code in PR #40470:
URL: https://github.com/apache/superset/pull/40470#discussion_r3342834170
##########
superset-frontend/src/dataMask/reducer.ts:
##########
@@ -155,12 +197,24 @@ function updateDataMaskForFilterChanges(
// Check if targets are equal
const areTargetsEqual = isEqual(prevFilterDef?.targets, filter?.targets);
- // Preserve state only if filter exists, has enableEmptyFilter=true and
targets match
+ // For required filters, only preserve existing state when it actually has
+ // a value — otherwise the empty existing state would wipe the (possibly
+ // newly-defined) default. defaultToFirstItem filters keep the old
behavior:
+ // FilterValue re-resolves the first item at runtime, so preserving the
+ // mid-init empty state is fine.
+ const isRequired = !!filter.controlValues?.enableEmptyFilter;
+ const isFirstItem = !!filter.controlValues?.defaultToFirstItem;
+ const existingValue = existingFilter?.filterState?.value;
+ const hasExistingValue =
+ existingValue !== undefined &&
+ existingValue !== null &&
+ !(Array.isArray(existingValue) && existingValue.length === 0);
Review Comment:
[null, null] is true for this right? But we set it as such in
```
const loadedHasValue =
loadedValue !== undefined &&
loadedValue !== null &&
!(
// Treat all-null arrays (range filters use [null, null] as their
// canonical cleared value) and empty arrays as "no value".
Array.isArray(loadedValue) && loadedValue.every(v => v === null)
);
```
Is this a problem?
--
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]