1+ import { useMemo , useState , useEffect } from 'react' ;
12import { colord } from 'colord' ;
23import BarChart from '@/components/charts/BarChart' ;
34import { useDateRange , useLocale , useWebsiteEventsSeries } from '@/components/hooks' ;
45import { renderDateLabels } from '@/lib/charts' ;
56import { CHART_COLORS } from '@/lib/constants' ;
6- import { useMemo } from 'react' ;
77
88export interface EventsChartProps {
99 websiteId : string ;
1010 className ?: string ;
11+ focusLabel ?: string ;
1112}
1213
13- export function EventsChart ( { websiteId, className } : EventsChartProps ) {
14+ export function EventsChart ( { websiteId, className, focusLabel } : EventsChartProps ) {
1415 const {
1516 dateRange : { startDate, endDate, unit, value } ,
1617 } = useDateRange ( websiteId ) ;
1718 const { locale } = useLocale ( ) ;
1819 const { data, isLoading } = useWebsiteEventsSeries ( websiteId ) ;
20+ const [ label , setLabel ] = useState < string > ( focusLabel ) ;
1921
2022 const chartData = useMemo ( ( ) => {
2123 if ( ! data ) return [ ] ;
@@ -42,8 +44,15 @@ export function EventsChart({ websiteId, className }: EventsChartProps) {
4244 borderWidth : 1 ,
4345 } ;
4446 } ) ,
47+ focusLabel,
4548 } ;
46- } , [ data , startDate , endDate , unit ] ) ;
49+ } , [ data , startDate , endDate , unit , focusLabel ] ) ;
50+
51+ useEffect ( ( ) => {
52+ if ( label !== focusLabel ) {
53+ setLabel ( focusLabel ) ;
54+ }
55+ } , [ focusLabel ] ) ;
4756
4857 return (
4958 < BarChart
0 commit comments