eschutho opened a new pull request, #35152:
URL: https://github.com/apache/superset/pull/35152
## SUMMARY
<!--- Describe the change below, including rationale and design decisions -->
Fixes broken metric-based sorting (e.g., sort by MAU) in select filter
components by preventing frontend alphabetical sorting from overriding backend
sort order. Also adds comprehensive test coverage for this functionality.
**Problem:**
- When `sortMetric` was specified in filter configuration, the backend would
correctly sort data by the specified metric (e.g., MAU, revenue, etc.)
- However, the frontend `sortComparator` was then applying alphabetical
sorting on the labels, completely overriding the intended metric-based order
- This resulted in filters showing values sorted alphabetically instead of
by their actual metric values
**Solution:**
- Check if `formData.sortMetric` is specified before applying sort logic
- When `sortMetric` exists, return 0 to preserve the original backend order
- Only apply alphabetical sorting when no `sortMetric` is configured
- Add `sortMetric` to useCallback dependency array for proper re-rendering
- Add comprehensive test coverage for all sorting scenarios
This ensures that metric-based sorting (like "sort by MAU") works correctly
while maintaining alphabetical sorting as a fallback for other cases.
## BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
<!--- Skip this if not applicable -->
**Before:** Select filter options sorted alphabetically regardless of
sortMetric setting
**After:** Select filter options preserve backend metric-based order when
sortMetric is specified
## TESTING INSTRUCTIONS
<!--- Required! What steps can be taken to manually verify the changes? -->
1. Run the test suite: `npm test -- SelectFilterPlugin.test.tsx`
2. Verify all tests pass, including 4 new comprehensive sortMetric tests
3. Manual testing:
- Create a select filter with `sortMetric` specified
- Verify options appear in metric order, not alphabetical order
- Test fallback: create filter without `sortMetric`, verify alphabetical
sorting still works
## ADDITIONAL INFORMATION
<!--- Check any relevant boxes with "x" -->
- [x] Has associated issue: Fixes metric-based sorting in select filters
- [ ] Required feature flags:
- [x] Changes UI (sorting behavior)
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
**Test Coverage Added:**
- ✅ Backend order preservation when `sortMetric` is specified
- ✅ Alphabetical sorting fallback when no `sortMetric` is specified
- ✅ Ascending and descending alphabetical sorting behavior
- ✅ `sortMetric` precedence over `sortAscending` setting
**Commits:**
1. `fix(filters): preserve backend metric-based sorting in select filters` -
The core fix
2. `test(filters): add comprehensive tests for sortMetric functionality` -
Test coverage
🤖 Generated with [Claude Code](https://claude.ai/code)
--
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]