Skip to content

fix(filters): preserve backend metric-based sorting in select filters - #35130

Merged
msyavuz merged 1 commit into
6.0-bug-fixesfrom
fix/filter-value-metric-based-sorting
Sep 13, 2025
Merged

msyavuz merged 1 commit into
6.0-bug-fixesfrom
fix/filter-value-metric-based-sorting

Conversation

@eschutho

Copy link
Copy Markdown
Member

Summary

  • Fixes broken metric-based sorting in select filter components
  • Preserves backend sort order when sortMetric is specified (e.g., sort by MAU)
  • Maintains alphabetical sorting as fallback when no metric is configured

Problem

Select filters with metric-based sorting were not working correctly:

Expected behavior:

  • Configure filter with "Sort by MAU"
  • Backend returns data sorted by MAU values: [high MAU, medium MAU, low MAU]
  • Filter options should display in that metric-based order

Actual behavior:

  • ❌ Backend correctly sorted by MAU and returned proper order
  • ❌ Frontend sortComparator was applying alphabetical sorting on labels
  • ❌ This completely overrode the intended metric-based sort order
  • ❌ Users saw alphabetically sorted options instead of metric-sorted ones

Root Cause

The sortComparator in SelectFilterPlugin.tsx was always applying alphabetical sorting based on formData.sortAscending, without considering whether formData.sortMetric was specified. This meant metric-based backend sorting was being ignored.

Solution

1. Check for metric-based sorting:

if (formData.sortMetric) {
  return 0; // Preserve the original order from the backend
}

2. Preserve backend order when sortMetric exists:

  • When sortMetric is specified, return 0 from comparator
  • This maintains the exact order returned by the backend
  • Backend has already done the complex metric-based sorting

3. Fallback to alphabetical sorting:

  • Only apply alphabetical sorting when no sortMetric is configured
  • Maintains existing behavior for non-metric sorts

4. Update dependencies:

  • Added formData.sortMetric to useCallback dependency array
  • Ensures proper re-rendering when sortMetric configuration changes

Impact

  • ✅ Metric-based sorting now works correctly (e.g., sort by MAU, revenue, etc.)
  • ✅ Alphabetical sorting still works when no metric is specified
  • ✅ No breaking changes to existing functionality
  • ✅ Backend sort order is properly respected

Files Changed

  • superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx

Testing

  • Create filter with "Sort by MAU" configuration
  • Verify filter options appear in MAU order (not alphabetical)
  • Test filters without sortMetric still sort alphabetically
  • Confirm sortAscending toggle still works for both cases

🤖 Generated with Claude Code

Fixes broken metric-based sorting (e.g., sort by MAU) in select filter components
by preventing frontend alphabetical sorting from overriding backend sort order.

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

This ensures that metric-based sorting (like "sort by MAU") works correctly
while maintaining alphabetical sorting as a fallback for other cases.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@dosubot dosubot Bot added the change:frontend Requires changing the frontend label Sep 13, 2025

@korbit-ai korbit-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've completed my review and didn't find any issues.

Files scanned ​
File Path Reviewed
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx ✅

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

@eschutho eschutho added the 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR label Sep 13, 2025
@github-actions github-actions Bot added 🎪 0f3953c 🚦 building and removed 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Sep 13, 2025
@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 0f3953c

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for 0f3953c

• Environment: http://44.252.104.2:8080 (admin/admin)
• Lifetime: 24h auto-cleanup
• Updates: New commits create fresh environments automatically

@msyavuz
msyavuz merged commit 7c00f55 into 6.0-bug-fixes Sep 13, 2025
@msyavuz
msyavuz deleted the fix/filter-value-metric-based-sorting branch September 13, 2025 10:34
@dosubot dosubot Bot mentioned this pull request Dec 20, 2025
2 of 3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:frontend Requires changing the frontend size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants