@@ -6,15 +6,15 @@ import React, {
66 useRef ,
77 useMemo ,
88} from "react" ;
9- import type { ChartDataPoint , ChartData } from "../../types/data" ;
10- import type { PageChartWidget , Metrics } from "../../types/widgets" ;
9+ import type { ChartDataPoint , ChartData , MetricsMap } from "../../types/data" ;
10+ import type { PageChartWidget } from "../../types/widgets" ;
1111import type { AxisOptions } from "react-charts" ;
1212import { useDocumentInfo } from "payload/components/utilities" ;
13- import { MetricMap } from "../../providers/plausible/utilities" ;
1413import { useTheme } from "payload/dist/admin/components/utilities/Theme" ;
1514
1615type Props = {
1716 options : PageChartWidget ;
17+ metricsMap : MetricsMap ;
1818} ;
1919
2020const ChartComponent = lazy ( ( ) =>
@@ -23,7 +23,7 @@ const ChartComponent = lazy(() =>
2323 } )
2424) ;
2525
26- const PageViewsChart : React . FC < Props > = ( { options } ) => {
26+ const PageViewsChart : React . FC < Props > = ( { options, metricsMap } ) => {
2727 const [ chartData , setChartData ] = useState < ChartData > ( [ ] ) ;
2828 const [ isLoading , setIsLoading ] = useState < boolean > ( true ) ;
2929 const theme = useTheme ( ) ;
@@ -44,7 +44,7 @@ const PageViewsChart: React.FC<Props> = ({ options }) => {
4444
4545 useEffect ( ( ) => {
4646 if ( pageId ) {
47- const getChartData = fetch ( `/api/analytics/pageChartData ` , {
47+ const getChartData = fetch ( `/api/analytics/pageChart ` , {
4848 method : "post" ,
4949 credentials : "include" ,
5050 headers : {
@@ -73,7 +73,7 @@ const PageViewsChart: React.FC<Props> = ({ options }) => {
7373 if ( metrics ) {
7474 const metricValues : string [ ] = [ ] ;
7575
76- Object . entries ( MetricMap ) . forEach ( ( [ key , value ] ) => {
76+ Object . entries ( metricsMap ) . forEach ( ( [ key , value ] ) => {
7777 // @ts -ignore
7878 if ( metrics . includes ( key ) ) metricValues . push ( value . label ) ;
7979 } ) ;
@@ -82,7 +82,7 @@ const PageViewsChart: React.FC<Props> = ({ options }) => {
8282 } else {
8383 return "No metrics defined for this widget" ;
8484 }
85- } , [ label , metrics ] ) ;
85+ } , [ label , metrics , metricsMap ] ) ;
8686
8787 const primaryAxis = React . useMemo < AxisOptions < ChartDataPoint > > ( ( ) => {
8888 return {
@@ -140,7 +140,11 @@ const PageViewsChart: React.FC<Props> = ({ options }) => {
140140 ) ;
141141} ;
142142
143- export const getPageViewsChart = ( props ?: any , options ?: PageChartWidget ) => {
143+ export const getPageViewsChart = (
144+ metricsMap : MetricsMap ,
145+ props ?: any ,
146+ options ?: PageChartWidget
147+ ) => {
144148 const combinedProps : Props = {
145149 ...props ,
146150 options,
0 commit comments