11import { BarChart , Bar , XAxis , YAxis } from 'recharts'
22import { ChartContainer , ChartTooltip , ChartConfig } from '@/components/ui/chart'
33import { format } from 'date-fns'
4+ import { type TimeRange } from '@/components/time-range'
45
56export interface DeploymentsData {
67 period : string
@@ -19,9 +20,20 @@ const chartConfig = {
1920 } ,
2021} satisfies ChartConfig
2122
22- export function DeploymentsChart ( { data } : { data : DeploymentsData [ ] } ) {
23+ export function DeploymentsChart ( { data, timeRange } : { data : DeploymentsData [ ] ; timeRange : TimeRange } ) {
2324 if ( ! data . length ) return < div className = { `flex items-center justify-center` } > No data available</ div >
2425
26+ let dateFormat = 'yyyy-MM-dd HH:mm'
27+ if ( timeRange === 'hourly' ) {
28+ dateFormat = 'yyyy-MM-dd HH:mm'
29+ } else if ( timeRange === 'daily' ) {
30+ dateFormat = 'd MMMM'
31+ } else if ( timeRange === 'weekly' ) {
32+ dateFormat = 'd MMMM'
33+ } else if ( timeRange === 'monthly' ) {
34+ dateFormat = 'MMMM'
35+ }
36+
2537 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2638 const chartData = data . reduce ( ( acc : any [ ] , curr : DeploymentsData ) => {
2739 const existing = acc . find ( d => d . period === curr . period )
@@ -46,7 +58,7 @@ export function DeploymentsChart({ data }: { data: DeploymentsData[] }) {
4658 dataKey = "period"
4759 tickLine = { false }
4860 axisLine = { false }
49- tickFormatter = { ( value ) => format ( new Date ( value ) , 'd HH:mm' ) }
61+ tickFormatter = { ( value ) => format ( new Date ( value ) , dateFormat ) }
5062 />
5163 < YAxis
5264 tickLine = { false }
@@ -59,7 +71,7 @@ export function DeploymentsChart({ data }: { data: DeploymentsData[] }) {
5971 return (
6072 < div className = "rounded-lg border bg-background p-2 shadow-sm" >
6173 < div className = "text-xs text-muted-foreground" >
62- { format ( new Date ( data . period ) , 'd HH:mm' ) }
74+ { format ( new Date ( data . period ) , dateFormat ) }
6375 </ div >
6476 {
6577 // eslint-disable-next-line @typescript-eslint/no-explicit-any
0 commit comments