fix: Update service to use display_index as the main sort order (#60)

* fix: Update service to use display_index as the main sort order

* chore: auto-fix linting and formatting issues

* Update src/types/nezha-api.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: huYang <306061454@qq.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
胡说丷刂
2026-02-25 17:20:42 +08:00
committed by GitHub
parent b030cd45d6
commit eceadb6bff
4 changed files with 222 additions and 216 deletions
+15 -10
View File
@@ -177,18 +177,23 @@ export function NetworkChart({
const formattedData = formatData(monitorData.data);
const monitorIdByName = new Map(
monitorData.data.map((item) => [item.monitor_name, item.monitor_id]),
const monitorInfoByName = new Map(
monitorData.data.map((item) => [
item.monitor_name,
{ id: item.monitor_id, displayIndex: item.display_index },
]),
);
const chartDataKey = Object.keys(transformedData).sort((a, b) => {
const aId = monitorIdByName.get(a);
const bId = monitorIdByName.get(b);
if (aId === undefined && bId === undefined) {
return a.localeCompare(b);
}
if (aId === undefined) return 1;
if (bId === undefined) return -1;
return aId - bId;
const aInfo = monitorInfoByName.get(a);
const bInfo = monitorInfoByName.get(b);
if (!aInfo && !bInfo) return a.localeCompare(b);
if (!aInfo) return 1;
if (!bInfo) return -1;
const indexDiff = (bInfo.displayIndex ?? 0) - (aInfo.displayIndex ?? 0);
if (indexDiff !== 0) return indexDiff;
return aInfo.id - bInfo.id;
});
const initChartConfig = {