@@ -16,6 +16,7 @@ import getPageAggregateData from "./routes/getPageAggregateData";
1616import getLiveData from "./routes/getLiveData" ;
1717
1818import type { CollectionConfig } from "payload/dist/collections/config/types" ;
19+ import type { GlobalConfig } from "payload/dist/globals/config/types" ;
1920import { getPageViewsChart } from "./components/Charts/PageViewsChart" ;
2021import { getAggregateDataWidget } from "./components/Aggregates/AggregateDataWidget" ;
2122import LiveDataWidget from "./components/Live/LiveDataWidget" ;
@@ -49,7 +50,7 @@ const PageWidgetMap: Record<
4950const payloadDashboardAnalytics =
5051 ( incomingConfig : DashboardAnalyticsConfig ) =>
5152 ( config : PayloadConfig ) : PayloadConfig => {
52- const { admin, collections } = config ;
53+ const { admin, collections, globals } = config ;
5354 const { provider, navigation } = incomingConfig ;
5455 const endpoints = config . endpoints ?? [ ] ;
5556 const apiProvider = getProvider ( provider ) ;
@@ -85,10 +86,12 @@ const payloadDashboardAnalytics =
8586 ] ,
8687 ...( collections && {
8788 collections : collections . map ( ( collection ) => {
88- const targetCollection = incomingConfig . collections ?. find ( ( col ) => {
89- if ( col . slug === collection . slug ) return true ;
90- return false ;
91- } ) ;
89+ const targetCollection = incomingConfig . collections ?. find (
90+ ( pluginCollection ) => {
91+ if ( pluginCollection . slug === collection . slug ) return true ;
92+ return false ;
93+ }
94+ ) ;
9295
9396 if ( targetCollection ) {
9497 const collectionConfigWithHooks : CollectionConfig = {
@@ -109,6 +112,32 @@ const payloadDashboardAnalytics =
109112 return collection ;
110113 } ) ,
111114 } ) ,
115+ ...( globals && {
116+ globals : globals . map ( ( global ) => {
117+ const targetGlobal = incomingConfig . globals ?. find ( ( pluginGlobal ) => {
118+ if ( pluginGlobal . slug === global . slug ) return true ;
119+ return false ;
120+ } ) ;
121+
122+ if ( targetGlobal ) {
123+ const globalConfigWithHooks : GlobalConfig = {
124+ ...global ,
125+ fields : [
126+ ...global . fields ,
127+ ...targetGlobal . widgets . map ( ( widget , index ) => {
128+ const field = PageWidgetMap [ widget . type ] ;
129+
130+ return field ( widget , index ) ;
131+ } ) ,
132+ ] ,
133+ } ;
134+
135+ return globalConfigWithHooks ;
136+ }
137+
138+ return global ;
139+ } ) ,
140+ } ) ,
112141 } ;
113142
114143 return processedConfig ;
0 commit comments