1
- import React , { useState , useEffect , useContext } from 'react'
1
+ import React , { useState , useEffect , useContext , useMemo } from 'react'
2
2
import { SidebarMenu } from 'Components'
3
- import { useDispatch , useSelector } from 'react-redux'
3
+ import { useSelector } from 'react-redux'
4
4
import { hasPermission } from 'Utils/PermChecker'
5
5
import { ErrorBoundary } from 'react-error-boundary'
6
6
import GluuErrorFallBack from './GluuErrorFallBack'
@@ -22,6 +22,7 @@ import Wave from 'Components/SVG/SidebarWave'
22
22
import getThemeColor from 'Context/theme/config'
23
23
import CachedIcon from '@mui/icons-material/Cached'
24
24
import LockIcon from '@mui/icons-material/Lock'
25
+ import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
25
26
import styles from './styles/GluuAppSidebar.style'
26
27
27
28
function GluuAppSidebar ( ) {
@@ -38,12 +39,34 @@ function GluuAppSidebar() {
38
39
const sidebarMenuActiveClass = `sidebar-menu-active-${ selectedTheme } `
39
40
const { classes } = styles ( )
40
41
const themeColors = getThemeColor ( selectedTheme )
41
- const dispatch = useDispatch ( )
42
42
const navigate = useNavigate ( )
43
43
44
+ const fetchedServersLength = useMemo (
45
+ ( ) => Object . keys ( health ) . length > 0 ,
46
+ [ health ]
47
+ )
48
+
44
49
useEffect ( ( ) => {
45
- setPluginMenus ( processMenus ( ) )
46
- } , [ ] )
50
+ const menus = processMenus ( )
51
+
52
+ if ( fetchedServersLength ) {
53
+ const visibilityConditions = {
54
+ '/jans-lock' : 'jans-lock' ,
55
+ '/fido/fidomanagement' : 'jans-fido2' ,
56
+ '/scim' : 'jans-scim'
57
+ }
58
+
59
+ const filtered = menus . filter ( menu => {
60
+ const healthKey = visibilityConditions [ menu . path ]
61
+ if ( healthKey ) {
62
+ return health ?. [ healthKey ] === 'Running'
63
+ }
64
+ return true
65
+ } )
66
+
67
+ setPluginMenus ( filtered )
68
+ }
69
+ } , [ health ] )
47
70
48
71
useEffect ( ( ) => {
49
72
if ( isUserLogout ) {
@@ -128,54 +151,62 @@ function GluuAppSidebar() {
128
151
return typeof plugin . children !== 'undefined' && plugin . children . length
129
152
}
130
153
131
- const filteringJansLock = pluginMenus . filter (
132
- menu => menu . path !== '/jans-lock' || health ?. [ 'jans-lock' ] === 'Running'
133
- )
134
-
135
154
return (
136
155
< ErrorBoundary FallbackComponent = { GluuErrorFallBack } >
137
156
< SidebarMenu >
138
- { filteringJansLock . map ( ( plugin , key ) => (
139
- < SidebarMenu . Item
140
- key = { key }
141
- icon = { getMenuIcon ( plugin . icon ) }
142
- to = { getMenuPath ( plugin ) }
143
- title = { t ( `${ plugin . title } ` ) }
144
- textStyle = { { fontSize : '18px' } }
145
- sidebarMenuActiveClass = { sidebarMenuActiveClass }
146
- >
147
- { hasChildren ( plugin ) &&
148
- plugin . children . map ( ( item , idx ) => (
149
- < SidebarMenu . Item
150
- key = { idx }
151
- title = { t ( `${ item . title } ` ) }
152
- isEmptyNode = {
153
- ! hasPermission ( scopes , item . permission ) &&
154
- ! hasChildren ( item )
155
- }
156
- to = { getMenuPath ( item ) }
157
- icon = { getMenuIcon ( item . icon ) }
158
- textStyle = { { fontSize : '15px' } }
159
- exact
160
- >
161
- { hasChildren ( item ) &&
162
- item . children . map ( ( sub , id ) => (
163
- < SidebarMenu . Item
164
- key = { id }
165
- title = { t ( `${ sub . title } ` ) }
166
- to = { getMenuPath ( sub ) }
167
- isEmptyNode = { ! hasPermission ( scopes , sub . permission ) }
168
- icon = { getMenuIcon ( sub . icon ) }
169
- textStyle = { { fontSize : '15px' } }
170
- exact
171
- > </ SidebarMenu . Item >
172
- ) ) }
173
- </ SidebarMenu . Item >
174
- ) ) }
175
- </ SidebarMenu . Item >
176
- ) ) }
177
-
178
- < div className = { classes . waveContainer } >
157
+ { fetchedServersLength ? (
158
+ pluginMenus . map ( ( plugin , key ) => (
159
+ < SidebarMenu . Item
160
+ key = { key }
161
+ icon = { getMenuIcon ( plugin . icon ) }
162
+ to = { getMenuPath ( plugin ) }
163
+ title = { t ( `${ plugin . title } ` ) }
164
+ textStyle = { { fontSize : '18px' } }
165
+ sidebarMenuActiveClass = { sidebarMenuActiveClass }
166
+ >
167
+ { hasChildren ( plugin ) &&
168
+ plugin . children . map ( ( item , idx ) => (
169
+ < SidebarMenu . Item
170
+ key = { idx }
171
+ title = { t ( `${ item . title } ` ) }
172
+ isEmptyNode = {
173
+ ! hasPermission ( scopes , item . permission ) &&
174
+ ! hasChildren ( item )
175
+ }
176
+ to = { getMenuPath ( item ) }
177
+ icon = { getMenuIcon ( item . icon ) }
178
+ textStyle = { { fontSize : '15px' } }
179
+ exact
180
+ >
181
+ { hasChildren ( item ) &&
182
+ item . children . map ( ( sub , id ) => (
183
+ < SidebarMenu . Item
184
+ key = { id }
185
+ title = { t ( `${ sub . title } ` ) }
186
+ to = { getMenuPath ( sub ) }
187
+ isEmptyNode = { ! hasPermission ( scopes , sub . permission ) }
188
+ icon = { getMenuIcon ( sub . icon ) }
189
+ textStyle = { { fontSize : '15px' } }
190
+ exact
191
+ > </ SidebarMenu . Item >
192
+ ) ) }
193
+ </ SidebarMenu . Item >
194
+ ) ) }
195
+ </ SidebarMenu . Item >
196
+ ) )
197
+ ) : (
198
+ < div style = { { marginTop : '20vh' } } >
199
+ < GluuLoader blocking = { ! fetchedServersLength } />
200
+ </ div >
201
+ ) }
202
+
203
+ < div
204
+ className = {
205
+ fetchedServersLength
206
+ ? classes . waveContainer
207
+ : classes . waveContainerFixed
208
+ }
209
+ >
179
210
< Wave className = { classes . wave } fill = { themeColors . menu . background } />
180
211
< div className = { classes . powered } > Powered by Gluu</ div >
181
212
</ div >
0 commit comments