bito-code-review[bot] commented on code in PR #36927:
URL: https://github.com/apache/superset/pull/36927#discussion_r2668232395
##########
superset-frontend/src/dashboard/components/FiltersBadge/index.tsx:
##########
@@ -201,30 +201,29 @@ export const FiltersBadge = ({ chartId }:
FiltersBadgeProps) => {
const prevChartConfig = usePrevious(chartConfiguration);
useEffect(() => {
- if (!showIndicators && nativeIndicators.length > 0) {
+ const shouldRecalculate =
+ prevChartStatus !== 'success' ||
+ dataMask !== prevDataMask ||
+ chart?.queriesResponse?.[0]?.rejected_filters !==
+ prevChart?.queriesResponse?.[0]?.rejected_filters ||
+ chart?.queriesResponse?.[0]?.applied_filters !==
+ prevChart?.queriesResponse?.[0]?.applied_filters ||
+ nativeFilters !== prevNativeFilters ||
+ chartLayoutItems !== prevChartLayoutItems ||
+ prevChartConfig !== chartConfiguration;
+
+ if (shouldRecalculate) {
+ const newIndicators = selectNativeIndicatorsForChart(
+ nativeFilters,
+ dataMask,
+ chartId,
+ chart,
+ chartLayoutItems,
+ chartConfiguration,
+ );
+ setNativeIndicators(newIndicators);
+ } else if (!showIndicators && nativeIndicators.length > 0) {
setNativeIndicators(indicatorsInitialState);
- } else if (prevChartStatus !== 'success') {
- if (
- chart?.queriesResponse?.[0]?.rejected_filters !==
- prevChart?.queriesResponse?.[0]?.rejected_filters ||
- chart?.queriesResponse?.[0]?.applied_filters !==
- prevChart?.queriesResponse?.[0]?.applied_filters ||
- nativeFilters !== prevNativeFilters ||
- chartLayoutItems !== prevChartLayoutItems ||
- dataMask !== prevDataMask ||
- prevChartConfig !== chartConfiguration
- ) {
- setNativeIndicators(
- selectNativeIndicatorsForChart(
- nativeFilters,
- dataMask,
- chartId,
- chart,
- chartLayoutItems,
- chartConfiguration,
- ),
- );
- }
}
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Logic Error in useEffect</b></div>
<div id="fix">
The reset logic for nativeIndicators when showIndicators is false should
take precedence over recalculating. Currently, if shouldRecalculate evaluates
to true but showIndicators is false, the code will set new indicators instead
of resetting them, leading to incorrect state where indicators are shown when
they shouldn't be.
</div>
</div>
<small><i>Code Review Run #a0652c</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]