Skip to content

Commit ec22629

Browse files
committed
feat(data-usage-chart): add total usage calculation and display during selected period
1 parent b37e427 commit ec22629

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

dashboard/src/components/dashboard/data-usage-chart.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,17 @@ const DataUsageChart = ({ admin_username }: { admin_username?: string }) => {
333333
return percent
334334
}, [chartData])
335335

336+
// Calculate total usage during period
337+
const totalUsageDuringPeriod = useMemo(() => {
338+
if (!chartData || chartData.length === 0) return 0
339+
const totalBytes = chartData.reduce((sum, dataPoint) => {
340+
const traffic = (dataPoint as { traffic: number })?.traffic || 0
341+
return sum + traffic
342+
}, 0)
343+
// Convert bytes to GB
344+
return totalBytes / (1024 * 1024 * 1024)
345+
}, [chartData])
346+
336347
const xAxisInterval = useMemo(() => {
337348
// For hours (24h), show approximately 8 labels
338349
if (periodOption.hours) {
@@ -478,6 +489,11 @@ const DataUsageChart = ({ admin_username }: { admin_username?: string }) => {
478489
{t('usersTable.trendingDown', { defaultValue: 'Trending down by' })} {Math.abs(trend).toFixed(1)}% <TrendingDown className="h-4 w-4" />
479490
</div>
480491
)}
492+
{chartData.length > 0 && (
493+
<div className="leading-none text-muted-foreground">
494+
{t('statistics.usageDuringPeriod', { defaultValue: 'Usage During Period' })}: <span dir="ltr" className="font-mono">{totalUsageDuringPeriod.toFixed(2)} GB</span>
495+
</div>
496+
)}
481497
<div className="leading-none text-muted-foreground">{t('statistics.trafficUsageDescription', { defaultValue: 'Total traffic usage across all servers' })}</div>
482498
</CardFooter>
483499
</Card>

0 commit comments

Comments
 (0)