diff --git a/.betterer.results b/.betterer.results index a695cf94129..061a3280b21 100644 --- a/.betterer.results +++ b/.betterer.results @@ -923,12 +923,6 @@ exports[`better eslint`] = { "packages/grafana-ui/src/components/VizLegend/VizLegendListItem.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] ], - "packages/grafana-ui/src/components/VizLegend/VizLegendTable.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"] - ], "packages/grafana-ui/src/components/VizLegend/types.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] diff --git a/packages/grafana-ui/src/components/VizLegend/VizLegendTable.tsx b/packages/grafana-ui/src/components/VizLegend/VizLegendTable.tsx index 3a97ed9dfa0..6d289dd1cc7 100644 --- a/packages/grafana-ui/src/components/VizLegend/VizLegendTable.tsx +++ b/packages/grafana-ui/src/components/VizLegend/VizLegendTable.tsx @@ -44,12 +44,10 @@ export const VizLegendTable = ({ } if (sortKey != null) { - let itemVals = new Map(); + let itemVals = new Map(); items.forEach((item) => { - if (sortKey === nameSortKey) { - itemVals.set(item, item.label); - } else if (item.getDisplayValues) { + if (sortKey !== nameSortKey && item.getDisplayValues) { const stat = item.getDisplayValues().find((stat) => stat.title === sortKey); const val = stat == null || Number.isNaN(stat.numeric) ? -Infinity : stat.numeric; itemVals.set(item, val); @@ -61,16 +59,13 @@ export const VizLegendTable = ({ if (sortKey === nameSortKey) { // string sort items.sort((a, b) => { - let aVal = itemVals.get(a) as string; - let bVal = itemVals.get(b) as string; - - return sortMult * naturalCompare(aVal, bVal); + return sortMult * naturalCompare(a.label, b.label); }); } else { // numeric sort items.sort((a, b) => { - let aVal = itemVals.get(a) as number; - let bVal = itemVals.get(b) as number; + const aVal = itemVals.get(a) ?? 0; + const bVal = itemVals.get(b) ?? 0; return sortMult * (aVal - bVal); });