Skip to content

Commit 56d27d4

Browse files
committed
[Dashboard] Sort usage categories by total amount in descending order (#7314)
# Sort usage categories by total amount This PR sorts the usage categories displayed on the team usage page by their total amount in descending order. Categories with higher total costs will now appear at the top of the list, making it easier for users to identify their most significant expenses at a glance. The implementation: - Creates a `sortedCategories` array by sorting the usage preview data - Sorts based on the sum of `amountUsdCents` for each category's line items - Uses the sorted array in the render function instead of the original data <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Enhancements** - Usage categories are now displayed in descending order based on their subtotal amounts, making it easier to identify the highest usage categories at a glance. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e742929 commit 56d27d4

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)