From 476c6d827fbdbca8d8aa8535c9b6c894bb84dd1c Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Thu, 30 Apr 2026 10:32:43 -0400 Subject: [PATCH] fix(ui): improve split quota bar readability --- .../account/shared/account-quota-panel.tsx | 99 ++++++++++++------- .../shared/account-quota-panel.test.tsx | 15 +-- 2 files changed, 70 insertions(+), 44 deletions(-) diff --git a/ui/src/components/account/shared/account-quota-panel.tsx b/ui/src/components/account/shared/account-quota-panel.tsx index f35c7bf9..244fc649 100644 --- a/ui/src/components/account/shared/account-quota-panel.tsx +++ b/ui/src/components/account/shared/account-quota-panel.tsx @@ -49,6 +49,17 @@ function getQuotaColor(percentage: number): string { return 'bg-green-500'; } +function getQuotaTextColor(percentage: number): string { + const clamped = Math.max(0, Math.min(100, percentage)); + if (clamped <= 20) return 'text-red-600 dark:text-red-400'; + if (clamped <= 50) return 'text-amber-600 dark:text-amber-400'; + return 'text-emerald-600 dark:text-emerald-400'; +} + +function getDisplayQuotaValue(value: number): number { + return Number(formatQuotaPercent(value)); +} + function formatRelativeTime(dateStr: string | undefined): string { if (!dateStr) return ''; @@ -174,59 +185,66 @@ export function AccountQuotaPanel({ {mode === 'compact' ? ( -
-
- - {t('accountCard.quota')} - - 50 - ? 'text-emerald-600 dark:text-emerald-400' - : minQuotaValue > 20 - ? 'text-amber-500' - : 'text-red-500' - )} - > - {minQuotaLabel}% - -
+
{quotaRows.length > 0 ? ( -
+
{quotaRows.map((row) => (
- + {row.compactLabel} - + {formatQuotaPercent(row.value)}%
))}
) : ( - 50 - ? 'bg-emerald-500' - : minQuotaValue > 20 - ? 'bg-amber-500' - : 'bg-red-500' - } - /> +
+
+ + {t('accountCard.quota')} + + 50 + ? 'text-emerald-600 dark:text-emerald-400' + : minQuotaValue > 20 + ? 'text-amber-500' + : 'text-red-500' + )} + > + {minQuotaLabel}% + +
+ 50 + ? 'bg-emerald-500' + : minQuotaValue > 20 + ? 'bg-amber-500' + : 'bg-red-500' + } + /> +
)}
) : ( @@ -265,12 +283,17 @@ export function AccountQuotaPanel({ {row.label} - + {formatQuotaPercent(row.value)}%
{ expect(screen.getByText('5h')).toBeInTheDocument(); expect(screen.getByText('Week')).toBeInTheDocument(); expect(screen.getByText('43%')).toBeInTheDocument(); - expect(screen.getAllByText('40%').length).toBeGreaterThan(0); + expect(screen.getAllByText('45%').length).toBeGreaterThan(0); expect(screen.getByRole('progressbar', { name: '5h quota' })).toHaveAttribute( 'aria-valuenow', '43' ); expect(screen.getByRole('progressbar', { name: 'Week quota' })).toHaveAttribute( 'aria-valuenow', - '40' + '45' ); });