Add sorting to detail breakdown tables
This commit is contained in:
20
lib/detail-sort.ts
Normal file
20
lib/detail-sort.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user