Skip to content

Commit 0f3953c

Browse files
eschuthoclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 36daa2d commit 0f3953c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,20 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
317317

318318
const sortComparator = useCallback(
319319
(a: LabeledValue, b: LabeledValue) => {
320+
// When sortMetric is specified, the backend already sorted the data correctly
321+
// Don't override the backend's metric-based sorting with frontend alphabetical sorting
322+
if (formData.sortMetric) {
323+
return 0; // Preserve the original order from the backend
324+
}
325+
326+
// Only apply alphabetical sorting when no sortMetric is specified
320327
const labelComparator = propertyComparator('label');
321328
if (formData.sortAscending) {
322329
return labelComparator(a, b);
323330
}
324331
return labelComparator(b, a);
325332
},
326-
[formData.sortAscending],
333+
[formData.sortAscending, formData.sortMetric],
327334
);
328335

329336
// Use effect for initialisation for filter plugin

0 commit comments

Comments
 (0)