@@ -6,9 +6,8 @@ import React, {
66 useRef ,
77 useMemo ,
88} from "react" ;
9- import type { ChartDataPoint , ChartData } from "../../types/data" ;
9+ import type { AggregateData } from "../../types/data" ;
1010import type { PageInfoWidget } from "../../types/widgets" ;
11- import type { AxisOptions } from "react-charts" ;
1211import { useDocumentInfo } from "payload/components/utilities" ;
1312import { MetricMap } from "../../providers/plausible/utilities" ;
1413import { useTheme } from "payload/dist/admin/components/utilities/Theme" ;
@@ -18,7 +17,7 @@ type Props = {
1817} ;
1918
2019const AggregateDataWidget : React . FC < Props > = ( { options } ) => {
21- const [ chartData , setChartData ] = useState < ChartData > ( [ ] ) ;
20+ const [ data , setData ] = useState < AggregateData > ( [ ] ) ;
2221 const [ isLoading , setIsLoading ] = useState < boolean > ( true ) ;
2322 const theme = useTheme ( ) ;
2423 const { publishedDoc } = useDocumentInfo ( ) ;
@@ -37,7 +36,7 @@ const AggregateDataWidget: React.FC<Props> = ({ options }) => {
3736
3837 useEffect ( ( ) => {
3938 if ( pageId ) {
40- const getChartData = fetch ( `/api/analytics/pageChartData ` , {
39+ const getAggregateData = fetch ( `/api/analytics/pageAggregateData ` , {
4140 method : "post" ,
4241 credentials : "include" ,
4342 headers : {
@@ -51,16 +50,16 @@ const AggregateDataWidget: React.FC<Props> = ({ options }) => {
5150 } ) ,
5251 } ) . then ( ( response ) => response . json ( ) ) ;
5352
54- getChartData . then ( ( data : ChartData ) => {
55- setChartData ( data ) ;
53+ getAggregateData . then ( ( data : AggregateData ) => {
54+ setData ( data ) ;
5655 setIsLoading ( false ) ;
5756 } ) ;
5857 } else {
5958 setIsLoading ( false ) ;
6059 }
6160 } , [ publishedDoc , pageId ] ) ;
6261
63- const chartLabel = useMemo ( ( ) => {
62+ const heading = useMemo ( ( ) => {
6463 if ( label ) return label ;
6564
6665 const metricValues : string [ ] = [ ] ;
@@ -77,9 +76,35 @@ const AggregateDataWidget: React.FC<Props> = ({ options }) => {
7776 < section
7877 style = { {
7978 marginBottom : "1.5rem" ,
79+ border : "1px solid" ,
80+ borderColor : "var(--theme-elevation-100)" ,
81+ padding : "0.5rem" ,
8082 } }
8183 >
82- aggr data
84+ { label !== "hidden" && (
85+ < h1 style = { { fontSize : "1.25rem" , marginBottom : "0.75rem" } } >
86+ { heading } ({ timeframeIndicator } )
87+ </ h1 >
88+ ) }
89+ < div >
90+ { isLoading ? (
91+ < > Loading...</ >
92+ ) : (
93+ < ul style = { { margin : "0" , listStyle : "none" , padding : "0" } } >
94+ { data . map ( ( item , index ) => {
95+ return (
96+ < li
97+ key = { index }
98+ style = { { display : "flex" , justifyContent : "space-between" } }
99+ >
100+ < div style = { { fontWeight : "700" } } > { item . label } </ div >
101+ < div > { item . value } </ div >
102+ </ li >
103+ ) ;
104+ } ) }
105+ </ ul >
106+ ) }
107+ </ div >
83108 </ section >
84109 ) ;
85110} ;
0 commit comments