-
Notifications
You must be signed in to change notification settings - Fork 16.5k
fix(Dashboard): Auto-apply filters with default values when extraForm… #36927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
✅ Deploy Preview for superset-docs-preview canceled.
|
Code Review Agent Run #e29eb6Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Nitpicks 🔍
|
| const isFirstTimeInitialization = | ||
| !initializedFilters.has(filter.id) && | ||
| dataMaskSelectedRef.current[filter.id]?.filterState?.value === | ||
| undefined; | ||
| existingDataMask?.filterState?.value === undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The isFirstTimeInitialization flag currently also depends on existingDataMask?.filterState?.value === undefined, which means that if a filter ever gets a value in dataMaskSelected before it has been marked as initialized (for example via a default/permalink value without extraFormData), it will permanently stop being treated as "first time" and required-first auto-apply logic may never fire even though initializedFilters was never updated; using only the explicit initializedFilters tracking avoids this inconsistent state. [logic error]
Severity Level: Minor
| const isFirstTimeInitialization = | |
| !initializedFilters.has(filter.id) && | |
| dataMaskSelectedRef.current[filter.id]?.filterState?.value === | |
| undefined; | |
| existingDataMask?.filterState?.value === undefined; | |
| const isFirstTimeInitialization = !initializedFilters.has(filter.id); |
Why it matters? ⭐
The current check couples "first-time" to the presence of an existing value in the selected mask. That can create a surprising state where a filter receives a value (e.g. from permalink/default) before initializedFilters is ever updated, which makes isFirstTimeInitialization false even though we never actually marked this filter as initialized. For requiredFirst handling we only care whether the filter was recorded in initializedFilters; using the explicit flag (!initializedFilters.has(filter.id)) is a clearer and more robust signal and will restore expected required-first auto-apply behavior. This is a functional fix, not just a cosmetic change.
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx
**Line:** 209:211
**Comment:**
*Logic Error: The `isFirstTimeInitialization` flag currently also depends on `existingDataMask?.filterState?.value === undefined`, which means that if a filter ever gets a value in `dataMaskSelected` before it has been marked as initialized (for example via a default/permalink value without `extraFormData`), it will permanently stop being treated as "first time" and required-first auto-apply logic may never fire even though `initializedFilters` was never updated; using only the explicit `initializedFilters` tracking avoids this inconsistent state.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems relevant?
|
CodeAnt AI finished reviewing your PR. |
msyavuz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's the bot comment about permalinks that might need checking. Otherwise LGTM
d14e068 to
23c5ad6
Compare
|
CodeAnt AI is running Incremental review Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
🎪 Showtime deployed environment on GHA for 23c5ad6 • Environment: http://54.244.145.45:8080 (admin/admin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review Agent Run #a0652c
Actionable Suggestions - 1
-
superset-frontend/src/dashboard/components/FiltersBadge/index.tsx - 1
- Logic Error in useEffect · Line 204-227
Additional Suggestions - 1
-
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx - 1
-
Missing test assertion · Line 355-410The test 'auto-applies filter when extraFormData is empty in applied state' sets up a spy on `updateDataMask` but lacks an assertion to confirm the auto-apply behavior. Without checking if the spy was invoked, the test doesn't validate the claimed functionality and could pass incorrectly. Consider adding an expect statement to assert the call, or clarify if the test intent is only rendering verification.
-
Review Details
-
Files reviewed - 3 · Commit Range:
23c5ad6..23c5ad6- superset-frontend/src/dashboard/components/FiltersBadge/index.tsx
- superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx
- superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx
-
Files skipped - 0
-
Tools
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers a full AI review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].
Documentation & Help
| 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, | ||
| ), | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Code Review Run #a0652c
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
SUMMARY
Fixes an issue where dashboard filters with default values were not automatically applied on dashboard load when
extraFormDatawas set to empty. Previously, filters would show default values selected but require users to manually click the Apply button. The fix automatically applies filters when they have default values but emptyextraFormData, ensuring charts load with filters applied from the start.AFTER
531449025-2a09ba78-5d55-44e9-992e-69914e15dd43.mp4
TESTING INSTRUCTIONS
extraFormDatavalue to empty.ADDITIONAL INFORMATION