You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2025/09/15 21:58:53 UTC
(superset) 01/02: fix(filters): preserve backend metric-based sorting in select filters
This is an automated email from the ASF dual-hosted git repository.
elizabeth pushed a commit to branch fix/filter-value-metric-based-sorting
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 4fa205a16ddb5b56a516cdd9d506ab455d76a382
Author: Elizabeth Thompson <es...@gmail.com>
AuthorDate: Fri Sep 12 18:59:29 2025 -0700
fix(filters): preserve backend metric-based sorting in select filters
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 <no...@anthropic.com>
---
.../src/filters/components/Select/SelectFilterPlugin.tsx | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx b/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx
index b792360786..a76bf8af1e 100644
--- a/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx
+++ b/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx
@@ -317,13 +317,20 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
const sortComparator = useCallback(
(a: LabeledValue, b: LabeledValue) => {
+ // When sortMetric is specified, the backend already sorted the data correctly
+ // Don't override the backend's metric-based sorting with frontend alphabetical sorting
+ if (formData.sortMetric) {
+ return 0; // Preserve the original order from the backend
+ }
+
+ // Only apply alphabetical sorting when no sortMetric is specified
const labelComparator = propertyComparator('label');
if (formData.sortAscending) {
return labelComparator(a, b);
}
return labelComparator(b, a);
},
- [formData.sortAscending],
+ [formData.sortAscending, formData.sortMetric],
);
// Use effect for initialisation for filter plugin