codeant-ai-for-open-source[bot] commented on code in PR #44880:
URL: https://github.com/apache/superset/pull/44880#discussion_r4162826760
##########
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx:
##########
@@ -564,32 +608,27 @@ export default function PluginFilterSelect(props:
PluginFilterSelectProps) {
updateDataMaskRef.current = updateDataMask;
}, [updateDataMask]);
- const debouncedLikeChange = useMemo(
- () =>
- debounce((text: string) => {
- if (text) {
- updateDataMaskRef.current([text]);
- } else {
- updateDataMaskRef.current(null);
- }
- }, Constants.SLOW_DEBOUNCE),
- [],
- );
-
useEffect(() => {
- if (!isLikeOperator || clearAllTrigger) {
- debouncedLikeChange.cancel();
+ if (
+ deferredPendingLikeValue === null ||
+ !isLikeOperator ||
+ clearAllTrigger
+ ) {
+ return;
}
- }, [clearAllTrigger, debouncedLikeChange, isLikeOperator]);
-
- useEffect(() => () => debouncedLikeChange.cancel(), [debouncedLikeChange]);
+ if (deferredPendingLikeValue) {
+ updateDataMaskRef.current([deferredPendingLikeValue]);
+ } else {
+ updateDataMaskRef.current(null);
+ }
+ }, [deferredPendingLikeValue, isLikeOperator, clearAllTrigger]);
Review Comment:
Yes, this is a valid stale-state issue. The guard prevents dispatch while
the operator is `Exact`, but `pendingLikeValue` remains populated. When
switching back to a LIKE operator, the deferred value can settle again and
reapply the previous text without a new edit.
Clear the pending value whenever LIKE mode is exited:
```tsx
useEffect(() => {
if (!isLikeOperator) {
setPendingLikeValue(null);
}
}, [isLikeOperator]);
useEffect(() => {
if (
deferredPendingLikeValue === null ||
!isLikeOperator ||
clearAllTrigger
) {
return;
}
if (deferredPendingLikeValue) {
updateDataMaskRef.current([deferredPendingLikeValue]);
} else {
updateDataMaskRef.current(null);
}
}, [deferredPendingLikeValue, isLikeOperator, clearAllTrigger]);
```
This preserves the current cancellation behavior while ensuring that
returning to `Contains`, `StartsWith`, or `EndsWith` does not restore an edit
that was made under the previous LIKE mode.
--
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]