File tree Expand file tree Collapse file tree 3 files changed +43
-9
lines changed
analytics/src/lib/react/components
client/src/lib/utils/graphql Expand file tree Collapse file tree 3 files changed +43
-9
lines changed Original file line number Diff line number Diff line change @@ -4,15 +4,15 @@ import { render } from '@testing-library/react';
44import { DotContentAnalyticsProvider } from './DotContentAnalyticsProvider' ;
55
66import { initializeContentAnalytics } from '../../dotAnalytics/dot-content-analytics' ;
7- import { DotContentAnalyticsConfig } from '../../dotAnalytics/shared/dot-content-analytics.model' ;
7+ import { DotCMSAnalyticsConfig } from '../../dotAnalytics/shared/dot-content-analytics.model' ;
88import * as RouterTrackerHook from '../hook/useRouterTracker' ;
99
1010// Mock dependencies
1111jest . mock ( '../../dotAnalytics/dot-content-analytics' ) ;
1212jest . mock ( '../hook/useRouterTracker' ) ;
1313
1414describe ( 'DotContentAnalyticsProvider' , ( ) => {
15- const mockConfig : DotContentAnalyticsConfig = {
15+ const mockConfig : DotCMSAnalyticsConfig = {
1616 siteKey : 'test-key' ,
1717 server : 'test-server' ,
1818 debug : false
Original file line number Diff line number Diff line change @@ -247,4 +247,29 @@ describe('GraphQL Parser', () => {
247247 expectedResult . containers [ '//test/container/' ] . contentlets [ 'test-uuid' ] [ 0 ]
248248 ) ;
249249 } ) ;
250+
251+ it ( 'should merge urlContentMap keys into _map' , ( ) => {
252+ const graphqlResponse = {
253+ ...GRAPHQL_RESPONSE_MOCK ,
254+ page : {
255+ ...GRAPHQL_RESPONSE_MOCK . page ,
256+ urlContentMap : {
257+ _map : {
258+ customField : 'custom value' ,
259+ someOtherField : 'empty'
260+ } ,
261+ someOtherField : 'some other value by relationship'
262+ }
263+ }
264+ } ;
265+
266+ const pageEntity = graphqlToPageEntity (
267+ graphqlResponse as unknown as DotCMSGraphQLPageResponse
268+ ) ;
269+
270+ expect ( pageEntity ?. urlContentMap ) . toEqual ( {
271+ customField : 'custom value' ,
272+ someOtherField : 'some other value by relationship'
273+ } ) ;
274+ } ) ;
250275} ) ;
Original file line number Diff line number Diff line change 88 DotCMSPageContainerContentlets ,
99 DotCMSPage ,
1010 DotCMSPageAsset ,
11- DotCMSContainer
11+ DotCMSContainer ,
12+ DotCMSURLContentMap
1213} from '@dotcms/types' ;
1314
1415/**
@@ -48,11 +49,19 @@ export const graphqlToPageEntity = (
4849
4950 const typedPageAsset = pageAsset as unknown as DotCMSPage ;
5051
51- // To prevent type errors, we cast the urlContentMap to an object
52- const urlContentMapObject = urlContentMap ;
53-
54- // Extract the _map data from the urlContentMap object
55- const urlContentMapData = urlContentMapObject ?. [ '_map' ] ;
52+ // Merge all urlContentMap keys into _map, except _map itself
53+ const mergedUrlContentMap = {
54+ ...( urlContentMap ?. _map || { } ) ,
55+ ...Object . entries ( urlContentMap || { } ) . reduce < Record < string , unknown > > (
56+ ( acc , [ key , value ] ) => {
57+ if ( key !== '_map' ) {
58+ acc [ key ] = value ;
59+ }
60+ return acc ;
61+ } ,
62+ { }
63+ )
64+ } as DotCMSURLContentMap ;
5665
5766 return {
5867 layout,
@@ -61,7 +70,7 @@ export const graphqlToPageEntity = (
6170 vanityUrl,
6271 runningExperimentId,
6372 site : host ,
64- urlContentMap : urlContentMapData ,
73+ urlContentMap : mergedUrlContentMap ,
6574 containers : parseContainers ( containers as [ ] ) ,
6675 page : {
6776 ...data ,
You can’t perform that action at this time.
0 commit comments