feat: Add 1 min and 1 hour interval selection for Today view in analytics dashboard

This commit is contained in:
Usman Baig
2026-01-19 11:00:55 +01:00
parent 5eade9f17f
commit c69b263cdc
3 changed files with 42 additions and 8 deletions

View File

@@ -33,7 +33,7 @@ interface ChartProps {
prevData?: DailyStat[]
stats: Stats
prevStats?: Stats
interval: 'hour' | 'day' | 'month'
interval: 'minute' | 'hour' | 'day' | 'month'
}
type MetricType = 'pageviews' | 'visitors' | 'bounce_rate' | 'avg_duration'
@@ -47,8 +47,18 @@ export default function Chart({ data, prevData, stats, prevStats, interval }: Ch
// * For more robustness, we could match by relative index
const prevItem = prevData && prevData[i]
// * Format date based on interval
let formattedDate: string
if (interval === 'minute') {
formattedDate = new Date(item.date).toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' })
} else if (interval === 'hour') {
formattedDate = new Date(item.date).toLocaleTimeString('en-US', { hour: 'numeric', minute: 'numeric' })
} else {
formattedDate = new Date(item.date).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })
}
return {
date: new Date(item.date).toLocaleDateString('en-US', interval === 'hour' ? { hour: 'numeric', minute: 'numeric' } : { month: 'short', day: 'numeric' }),
date: formattedDate,
originalDate: item.date,
pageviews: item.pageviews,
visitors: item.visitors,