1- import { useState } from 'react' ;
2- import { Grid , Row , Text } from '@umami/react-zen' ;
3- import classNames from 'classnames' ;
4- import { colord } from 'colord' ;
51import { BarChart } from '@/components/charts/BarChart' ;
2+ import { LoadingPanel } from '@/components/common/LoadingPanel' ;
3+ import { Panel } from '@/components/common/Panel' ;
64import { TypeIcon } from '@/components/common/TypeIcon' ;
75import { useCountryNames , useLocale , useMessages , useResultQuery } from '@/components/hooks' ;
6+ import { CurrencySelect } from '@/components/input/CurrencySelect' ;
87import { ListTable } from '@/components/metrics/ListTable' ;
98import { MetricCard } from '@/components/metrics/MetricCard' ;
109import { MetricsBar } from '@/components/metrics/MetricsBar' ;
1110import { renderDateLabels } from '@/lib/charts' ;
1211import { CHART_COLORS } from '@/lib/constants' ;
12+ import { generateTimeSeries } from '@/lib/date' ;
1313import { formatLongCurrency , formatLongNumber } from '@/lib/format' ;
14- import { useCallback , useMemo } from 'react' ;
15- import { Panel } from '@/components/common/Panel' ;
16- import { Column } from '@umami/react-zen' ;
17- import { LoadingPanel } from '@/components/common/LoadingPanel' ;
18- import { getMinimumUnit } from '@/lib/date' ;
19- import { CurrencySelect } from '@/components/input/CurrencySelect' ;
14+ import { Column , Grid , Row , Text } from '@umami/react-zen' ;
15+ import classNames from 'classnames' ;
16+ import { colord } from 'colord' ;
17+ import { useCallback , useMemo , useState } from 'react' ;
2018
2119export interface RevenueProps {
2220 websiteId : string ;
23- startDate : Date ;
24- endDate : Date ;
21+ minDate : Date ;
22+ maxDate : Date ;
23+ unit : string ;
2524}
2625
27- export function Revenue ( { websiteId, startDate , endDate } : RevenueProps ) {
26+ export function Revenue ( { websiteId, minDate , maxDate , unit } : RevenueProps ) {
2827 const [ currency , setCurrency ] = useState ( 'USD' ) ;
2928 const { formatMessage, labels } = useMessages ( ) ;
30- const { locale } = useLocale ( ) ;
29+ const { locale, dateLocale } = useLocale ( ) ;
3130 const { countryNames } = useCountryNames ( locale ) ;
32- const unit = getMinimumUnit ( startDate , endDate ) ;
3331 const { data, error, isLoading } = useResultQuery < any > ( 'revenue' , {
3432 websiteId,
35- startDate ,
36- endDate ,
33+ minDate ,
34+ maxDate ,
3735 currency,
3836 } ) ;
3937
@@ -65,15 +63,15 @@ export function Revenue({ websiteId, startDate, endDate }: RevenueProps) {
6563 const color = colord ( CHART_COLORS [ index % CHART_COLORS . length ] ) ;
6664 return {
6765 label : key ,
68- data : map [ key ] ,
66+ data : generateTimeSeries ( map [ key ] , minDate , maxDate , unit , dateLocale ) ,
6967 lineTension : 0 ,
7068 backgroundColor : color . alpha ( 0.6 ) . toRgbString ( ) ,
7169 borderColor : color . alpha ( 0.7 ) . toRgbString ( ) ,
7270 borderWidth : 1 ,
7371 } ;
7472 } ) ,
7573 } ;
76- } , [ data , startDate , endDate , unit ] ) ;
74+ } , [ data , minDate , maxDate , unit ] ) ;
7775
7876 const metrics = useMemo ( ( ) => {
7977 if ( ! data ) return [ ] ;
@@ -104,6 +102,8 @@ export function Revenue({ websiteId, startDate, endDate }: RevenueProps) {
104102 ] as any ;
105103 } , [ data , locale ] ) ;
106104
105+ const renderXLabel = useCallback ( renderDateLabels ( unit , locale ) , [ unit , locale ] ) ;
106+
107107 return (
108108 < Column gap >
109109 < Grid columns = "280px" gap >
@@ -122,12 +122,12 @@ export function Revenue({ websiteId, startDate, endDate }: RevenueProps) {
122122 < Panel >
123123 < BarChart
124124 chartData = { chartData }
125- minDate = { startDate }
126- maxDate = { endDate }
125+ minDate = { minDate }
126+ maxDate = { maxDate }
127127 unit = { unit }
128128 stacked = { true }
129129 currency = { currency }
130- renderXLabel = { renderDateLabels ( unit , locale ) }
130+ renderXLabel = { renderXLabel }
131131 height = "400px"
132132 />
133133 </ Panel >
0 commit comments