@@ -10,6 +10,7 @@ import PT from 'prop-types';
10
10
import React from 'react' ;
11
11
import { removeTrailingSlash } from 'utils/url' ;
12
12
import { isActive , target } from 'utils/contentful' ;
13
+ import { isomorphy } from 'topcoder-react-utils' ;
13
14
14
15
import NavMenu from './Menu' ;
15
16
@@ -66,23 +67,93 @@ function MenuItemsLoader(props) {
66
67
</ div >
67
68
) ;
68
69
}
69
- if ( menuItem . fields . childRoutes && menuItem . fields . excludeFromNavigationMenus !== true && isActive ( baseUrl , menuItem , 'childRoutes' ) ) {
70
- return (
71
- < div className = { themeToUse . submenu } key = { menuItem . sys . id } >
72
- < MenuItemsLoader
73
- menuId = { menuItem . sys . id }
74
- ids = { _ . map ( menuItem . fields . childRoutes , 'sys.id' ) }
70
+ if ( menuItem . fields . childRoutes && menuItem . fields . excludeFromNavigationMenus !== true ) {
71
+ if ( menuItem . fields . url && menuItem . fields . url !== '/' && isActive ( baseUrl , menuItem , 'childRoutes' ) ) {
72
+ return (
73
+ < div className = { themeToUse . submenu } key = { menuItem . sys . id } >
74
+ < MenuItemsLoader
75
+ menuId = { menuItem . sys . id }
76
+ ids = { _ . map ( menuItem . fields . childRoutes , 'sys.id' ) }
77
+ preview = { preview }
78
+ themeName = { themeName }
79
+ theme = { themeToUse }
80
+ baseUrl = { target ( baseUrl , menuItem ) }
81
+ parentBaseUrl = { baseUrl }
82
+ parentItems = { _ . values ( data . entries . items ) }
83
+ activeParentItem = { menuItem }
84
+ level = { level + 1 }
85
+ />
86
+ </ div >
87
+ ) ;
88
+ }
89
+ if ( ! menuItem . fields . url || menuItem . fields . url === '/' ) {
90
+ // need to load the submenu to see if it matches for the location
91
+ // this is special case when we have sub menus under root "/"" path
92
+ // all other cases are covered by above rule.
93
+
94
+ // get the current location 1st
95
+ let location = '' ;
96
+ if ( isomorphy . isClientSide ( ) ) {
97
+ location = window . location . pathname ;
98
+ location = location . toLowerCase ( ) ;
99
+ location = _ . replace ( location , '/__community__/tco19' , '' ) ;
100
+ } else {
101
+ // TODO: should probably get the current URL from the web framework
102
+ }
103
+ // When we are at home/root just load the menu directly
104
+ if ( ! location || location === '/' ) {
105
+ return (
106
+ < div className = { themeToUse . submenu } key = { menuItem . sys . id } >
107
+ < MenuItemsLoader
108
+ menuId = { menuItem . sys . id }
109
+ ids = { _ . map ( menuItem . fields . childRoutes , 'sys.id' ) }
110
+ preview = { preview }
111
+ themeName = { themeName }
112
+ theme = { themeToUse }
113
+ baseUrl = { target ( baseUrl , menuItem ) }
114
+ parentBaseUrl = { baseUrl }
115
+ parentItems = { _ . values ( data . entries . items ) }
116
+ activeParentItem = { menuItem }
117
+ level = { level + 1 }
118
+ />
119
+ </ div >
120
+ ) ;
121
+ }
122
+ // In all other cases we need to load the menu items
123
+ // to check if some matches against location path
124
+ return (
125
+ < ContentfulLoader
126
+ entryIds = { _ . map ( menuItem . fields . childRoutes , 'sys.id' ) }
75
127
preview = { preview }
76
- themeName = { themeName }
77
- theme = { themeToUse }
78
- baseUrl = { target ( baseUrl , menuItem ) }
79
- parentBaseUrl = { baseUrl }
80
- parentItems = { _ . values ( data . entries . items ) }
81
- activeParentItem = { menuItem }
82
- level = { level + 1 }
128
+ spaceName = { spaceName }
129
+ environment = { environment }
130
+ key = { menuItem . sys . id }
131
+ render = { ( childRoutesData ) => {
132
+ const links = _ . values ( childRoutesData . entries . items ) . map ( childItem => `/${ childItem . fields . url } ` ) ;
133
+ if ( links . some ( link => location . startsWith ( link ) ) ) {
134
+ return (
135
+ < div className = { themeToUse . submenu } key = { menuItem . sys . id } >
136
+ < MenuItemsLoader
137
+ menuId = { menuItem . sys . id }
138
+ ids = { _ . map ( menuItem . fields . childRoutes , 'sys.id' ) }
139
+ preview = { preview }
140
+ themeName = { themeName }
141
+ theme = { themeToUse }
142
+ baseUrl = { target ( baseUrl , menuItem ) }
143
+ parentBaseUrl = { baseUrl }
144
+ parentItems = { _ . values ( data . entries . items ) }
145
+ activeParentItem = { menuItem }
146
+ level = { level + 1 }
147
+ />
148
+ </ div >
149
+ ) ;
150
+ }
151
+ return null ;
152
+ } }
153
+ renderPlaceholder = { LoadingIndicator }
83
154
/>
84
- </ div >
85
- ) ;
155
+ ) ;
156
+ }
86
157
}
87
158
return null ;
88
159
} ) ) ;
0 commit comments