Skip to content

Commit 904a0ed

Browse files
committed
[Dashboard] Sort usage categories by total amount in descending order
1 parent e742929 commit 904a0ed

File tree

1 file changed

+14
-1
lines changed
  • apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/usage

1 file changed

+14
-1
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/usage/page.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ export default async function Page(props: {
6161
return total + categoryTotal;
6262
}, 0);
6363

64+
// sort the categories by their sub-total
65+
const sortedCategories = usagePreview.data.result.sort((a, b) => {
66+
const aTotal = a.lineItems.reduce(
67+
(sum, item) => sum + item.amountUsdCents,
68+
0,
69+
);
70+
const bTotal = b.lineItems.reduce(
71+
(sum, item) => sum + item.amountUsdCents,
72+
0,
73+
);
74+
return bTotal - aTotal;
75+
});
76+
6477
return (
6578
<div className="flex flex-col gap-8">
6679
{usagePreview.data.planVersion < 5 && (
@@ -112,7 +125,7 @@ export default async function Page(props: {
112125
</Card>
113126

114127
<div className="space-y-6">
115-
{usagePreview.data.result.map((category, index) => (
128+
{sortedCategories.map((category, index) => (
116129
<UsageCategoryDetails
117130
key={`${category.category}_${index}`}
118131
category={category}

0 commit comments

Comments
 (0)