korbit-ai[bot] commented on code in PR #34137:
URL: https://github.com/apache/superset/pull/34137#discussion_r2204059679
##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx:
##########
@@ -368,6 +372,47 @@
inverseSelection,
]);
+ useEffect(() => {
+ const prev = prevDataRef.current;
+ const curr = data;
+
+ const prevFirst = prev?.[0]?.[col];
+ const currFirst = curr?.[0]?.[col];
+
+ // If data actually changed (e.g., due to parent filter), reset flag
+ if (prevFirst !== currFirst) {
+ isChangedByUser.current = false;
+ prevDataRef.current = data;
+ }
+ }, [data, col]);
+
+ useEffect(() => {
+ if (isChangedByUser.current) return;
+
+ const firstItem: SelectValue = data[0]
+ ? (groupby.map(col => data[0][col]) as string[])
+ : null;
+
+ if (
+ defaultToFirstItem &&
+ Object.keys(formData?.extraFormData || {}).length &&
+ filterState.value !== undefined &&
+ firstItem !== null &&
+ filterState.value !== firstItem
+ ) {
+ if (firstItem?.[0] !== undefined) {
+ updateDataMask(firstItem);
+ }
+ }
+ }, [
+ defaultToFirstItem,
+ updateDataMask,
+ formData,
+ data,
+ JSON.stringify(filterState.value),
+ isChangedByUser.current,
+ ]);
+
useEffect(() => {
setDataMask(dataMask);
}, [JSON.stringify(dataMask)]);
Review Comment:
Understood, you're right - this optimization is outside the PR's focus on
dependent filters fixes. Let's keep the review centered on the core
functionality changes.
--
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]