Skip to content

fix(filters): preserve backend metric-based sorting#35152

Merged
sadpandajoe merged 2 commits into
masterfrom
fix/filter-value-metric-based-sorting
Nov 7, 2025
Merged

fix(filters): preserve backend metric-based sorting#35152
sadpandajoe merged 2 commits into
masterfrom
fix/filter-value-metric-based-sorting

Conversation

@eschutho
Copy link
Copy Markdown
Member

@eschutho eschutho commented Sep 15, 2025

SUMMARY

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

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

You configure a Select filter to sort by a metric like Monthly Active Users (MAU).

  • Superset’s backend correctly sorts the options: ['Google', 'Microsoft', 'Oracle'] based on MAU.

  • But the frontend says: “Oh, a list of strings! I’ll sort them alphabetically!” 😬

  • So you’d see: ['Google', 'Microsoft', 'Oracle'] — even if MAU was 1000, 900, 800.


  • After:

    • If sortMetric is set, the frontend does not override the order.

    • If sortMetric is not set, it still sorts alphabetically (fallback behavior).


    🧪 How to Manually Test This in Superset (Step-by-Step)


    🧠 You’ll need a dataset where each row has a grouping dimension (like company name or user ID) and a metric (like MAU).


    🔧 1. Create a Filter Box or Filter Select on a Dashboard

    1. Open a dashboard.

    2. Click Edit Dashboard → Add Filter.

    3. Choose the Select Filter plugin.

    4. In the filter config:

      • Set Column = dimension (e.g., company_name)

      • Set Sort Metric = metric (e.g., MAU)

    5. Save and view the dashboard.


    👀 2. Verify: Options Appear in Metric Order


    Example:

    company_name MAU
    Google 5000
    Apple 3000
    Oracle 1000

    ADDITIONAL INFORMATION

    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

    @dosubot dosubot Bot added change:frontend Requires changing the frontend explore:filter Related to filters in Explore labels Sep 15, 2025
    Copy link
    Copy Markdown

    @korbit-ai korbit-ai Bot left a comment

    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 changed the title fix(filters): preserve backend metric-based sorting with comprehensive tests fix(filters): preserve backend metric-based sorting Sep 15, 2025
    @eschutho eschutho added the 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR label Sep 15, 2025
    @github-actions github-actions Bot added preset-io 🎪 5fe1955 🚦 building and removed 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Sep 15, 2025
    @github-actions
    Copy link
    Copy Markdown
    Contributor

    🎪 Showtime is building environment on GHA for 5fe1955

    @github-actions
    Copy link
    Copy Markdown
    Contributor

    🎪 Showtime deployed environment on GHA for 5fe1955

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

    @github-actions
    Copy link
    Copy Markdown
    Contributor

    🎪 Showtime is building environment on GHA for 5fe1955

    @github-actions
    Copy link
    Copy Markdown
    Contributor

    🎪 Showtime deployed environment on GHA for 5fe1955

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

    eschutho and others added 2 commits September 29, 2025 13:28
    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 <noreply@anthropic.com>
    Adds test coverage for the sortMetric sorting behavior implemented in the
    SelectFilterPlugin component:
    
    - Tests that backend order is preserved when sortMetric is specified
    - Tests that alphabetical sorting is applied when no sortMetric is specified
    - Tests ascending and descending alphabetical sorting behavior
    - Tests that sortMetric takes precedence over sortAscending setting
    
    These tests ensure the fix for metric-based sorting works correctly across
    all scenarios while maintaining backwards compatibility with existing
    alphabetical sorting behavior.
    
    🤖 Generated with [Claude Code](https://claude.ai/code)
    
    Co-Authored-By: Claude <noreply@anthropic.com>
    @github-actions
    Copy link
    Copy Markdown
    Contributor

    github-actions Bot commented Oct 2, 2025

    🎪 Showtime is building environment on GHA for fa88e17

    @github-actions
    Copy link
    Copy Markdown
    Contributor

    github-actions Bot commented Oct 2, 2025

    🎪 Showtime deployed environment on GHA for fa88e17

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

    @github-actions
    Copy link
    Copy Markdown
    Contributor

    🎪 Showtime is building environment on GHA for fa88e17

    @github-actions
    Copy link
    Copy Markdown
    Contributor

    github-actions Bot commented Nov 1, 2025

    🎪 Showtime is building environment on GHA for fa88e17

    @github-actions
    Copy link
    Copy Markdown
    Contributor

    github-actions Bot commented Nov 1, 2025

    🎪 Showtime deployed environment on GHA for fa88e17

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

    @dosubot dosubot Bot mentioned this pull request Dec 20, 2025
    3 tasks
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels change:frontend Requires changing the frontend explore:filter Related to filters in Explore preset-io size/L v6.0 Label added by the release manager to track PRs to be included in the 6.0 branch 🍒 6.0.0 Cherry-picked to 6.0.0

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    【6.0.0-RC2】Sorting filter values by a metric doesn't work

    6 participants