@@ -24,10 +24,50 @@ const dashboardAnalytics =
2424 ( incomingConfig : DashboardAnalyticsConfig ) =>
2525 ( config : PayloadConfig ) : PayloadConfig => {
2626 const { admin, collections, globals } = config ;
27- const { provider, navigation, dashboard, access } = incomingConfig ;
27+ const { provider, navigation, dashboard, access, cache } = incomingConfig ;
2828 const endpoints = config . endpoints ?? [ ] ;
2929 const apiProvider = getProvider ( provider ) ;
3030
31+ const cacheSlug =
32+ typeof cache === "object"
33+ ? cache ?. slug ?? "analyticsData"
34+ : "analyticsData" ;
35+
36+ const cacheCollection : CollectionConfig = {
37+ slug : cacheSlug ,
38+ admin : {
39+ defaultColumns : [ "id" , "cacheTimestamp" , "cacheKey" ] ,
40+ } ,
41+ access : {
42+ read : ( ) => true ,
43+ update : ( ) => true ,
44+ create : ( ) => true ,
45+ delete : ( ) => true ,
46+ } ,
47+ fields : [
48+ {
49+ type : "text" ,
50+ name : "cacheKey" ,
51+ } ,
52+ {
53+ type : "text" ,
54+ name : "cacheTimestamp" ,
55+ } ,
56+ {
57+ type : "json" ,
58+ name : "data" ,
59+ } ,
60+ ] ,
61+ } ;
62+
63+ const routeOptions = {
64+ access : access ,
65+ cache : {
66+ ...( typeof cache === "object" ? cache : { } ) ,
67+ slug : cacheSlug ,
68+ } ,
69+ } ;
70+
3171 const processedConfig : PayloadConfig = {
3272 ...config ,
3373 admin : {
@@ -71,41 +111,45 @@ const dashboardAnalytics =
71111 } ,
72112 endpoints : [
73113 ...endpoints ,
74- getGlobalAggregate ( apiProvider , access ) ,
75- getGlobalChart ( apiProvider , access ) ,
76- getPageChart ( apiProvider , access ) ,
77- getPageAggregate ( apiProvider , access ) ,
78- getLive ( apiProvider , access ) ,
79- getReport ( apiProvider , access ) ,
114+ getGlobalAggregate ( apiProvider , routeOptions ) ,
115+ getGlobalChart ( apiProvider , routeOptions ) ,
116+ getPageChart ( apiProvider , routeOptions ) ,
117+ getPageAggregate ( apiProvider , routeOptions ) ,
118+ getLive ( apiProvider , routeOptions ) ,
119+ getReport ( apiProvider , routeOptions ) ,
80120 ] ,
81- ...( collections && {
82- collections : collections . map ( ( collection ) => {
83- const targetCollection = incomingConfig . collections ?. find (
84- ( pluginCollection ) => {
85- if ( pluginCollection . slug === collection . slug ) return true ;
86- return false ;
87- }
88- ) ;
89-
90- if ( targetCollection ) {
91- const collectionConfigWithHooks : CollectionConfig = {
92- ...collection ,
93- fields : [
94- ...collection . fields ,
95- ...targetCollection . widgets . map ( ( widget , index ) => {
96- const field = PageWidgetMap [ widget . type ] ;
97-
98- return field ( widget , index , apiProvider . metricsMap ) ;
99- } ) ,
100- ] ,
101- } ;
102-
103- return collectionConfigWithHooks ;
104- }
105121
106- return collection ;
107- } ) ,
108- } ) ,
122+ collections : [
123+ ...( collections
124+ ? collections . map ( ( collection ) => {
125+ const targetCollection = incomingConfig . collections ?. find (
126+ ( pluginCollection ) => {
127+ if ( pluginCollection . slug === collection . slug ) return true ;
128+ return false ;
129+ }
130+ ) ;
131+
132+ if ( targetCollection ) {
133+ const collectionConfigWithHooks : CollectionConfig = {
134+ ...collection ,
135+ fields : [
136+ ...collection . fields ,
137+ ...targetCollection . widgets . map ( ( widget , index ) => {
138+ const field = PageWidgetMap [ widget . type ] ;
139+
140+ return field ( widget , index , apiProvider . metricsMap ) ;
141+ } ) ,
142+ ] ,
143+ } ;
144+
145+ return collectionConfigWithHooks ;
146+ }
147+
148+ return collection ;
149+ } )
150+ : [ ] ) ,
151+ ...( cache ? [ cacheCollection ] : [ ] ) ,
152+ ] ,
109153 ...( globals && {
110154 globals : globals . map ( ( global ) => {
111155 const targetGlobal = incomingConfig . globals ?. find ( ( pluginGlobal ) => {
0 commit comments