mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-05-06 05:48:41 +00:00
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:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user