Add sorting to detail breakdown tables

This commit is contained in:
2026-04-28 13:40:45 +08:00
parent ab915e9292
commit e8a66cf180
3 changed files with 86 additions and 8 deletions

20
lib/detail-sort.ts Normal file
View File

@@ -0,0 +1,20 @@
export interface DetailBreakdownItem {
name: string;
calls: number;
total_tokens: number;
quota: number;
}
export type DetailBreakdownSortKey = "calls" | "total_tokens" | "quota";
export function sortDetailBreakdown(
items: DetailBreakdownItem[],
sortKey: DetailBreakdownSortKey,
sortAsc: boolean
): DetailBreakdownItem[] {
return [...items].sort((a, b) => {
const diff = a[sortKey] - b[sortKey];
if (diff !== 0) return sortAsc ? diff : -diff;
return a.name.localeCompare(b.name);
});
}