Remove type assertions in VizLegendTable (#78742)

no type assertions
This commit is contained in:
Ashley Harrison
2023-11-28 15:15:27 +00:00
committed by GitHub
parent 98da1fa0b3
commit 9789c0cc79
2 changed files with 5 additions and 16 deletions

View File

@@ -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"]

View File

@@ -44,12 +44,10 @@ export const VizLegendTable = <T extends unknown>({
}
if (sortKey != null) {
let itemVals = new Map<VizLegendItem, string | number>();
let itemVals = new Map<VizLegendItem, number>();
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 = <T extends unknown>({
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);
});