Skip to content

Commit 94c1cf7

Browse files
feat(admin-ui): hide optional components from sidebar if not installed (#2091)
Make SCIM and FIDO components optional in sidebar based on server status Closes #2087
1 parent 95f3163 commit 94c1cf7

File tree

2 files changed

+91
-52
lines changed

2 files changed

+91
-52
lines changed

admin-ui/app/routes/Apps/Gluu/GluuAppSidebar.js

Lines changed: 81 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { useState, useEffect, useContext } from 'react'
1+
import React, { useState, useEffect, useContext, useMemo } from 'react'
22
import { SidebarMenu } from 'Components'
3-
import { useDispatch, useSelector } from 'react-redux'
3+
import { useSelector } from 'react-redux'
44
import { hasPermission } from 'Utils/PermChecker'
55
import { ErrorBoundary } from 'react-error-boundary'
66
import GluuErrorFallBack from './GluuErrorFallBack'
@@ -22,6 +22,7 @@ import Wave from 'Components/SVG/SidebarWave'
2222
import getThemeColor from 'Context/theme/config'
2323
import CachedIcon from '@mui/icons-material/Cached'
2424
import LockIcon from '@mui/icons-material/Lock'
25+
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
2526
import styles from './styles/GluuAppSidebar.style'
2627

2728
function GluuAppSidebar() {
@@ -38,12 +39,34 @@ function GluuAppSidebar() {
3839
const sidebarMenuActiveClass = `sidebar-menu-active-${selectedTheme}`
3940
const { classes } = styles()
4041
const themeColors = getThemeColor(selectedTheme)
41-
const dispatch = useDispatch()
4242
const navigate = useNavigate()
4343

44+
const fetchedServersLength = useMemo(
45+
() => Object.keys(health).length > 0,
46+
[health]
47+
)
48+
4449
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])
4770

4871
useEffect(() => {
4972
if (isUserLogout) {
@@ -128,54 +151,62 @@ function GluuAppSidebar() {
128151
return typeof plugin.children !== 'undefined' && plugin.children.length
129152
}
130153

131-
const filteringJansLock = pluginMenus.filter(
132-
menu => menu.path !== '/jans-lock' || health?.['jans-lock'] === 'Running'
133-
)
134-
135154
return (
136155
<ErrorBoundary FallbackComponent={GluuErrorFallBack}>
137156
<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+
>
179210
<Wave className={classes.wave} fill={themeColors.menu.background} />
180211
<div className={classes.powered}>Powered by Gluu</div>
181212
</div>

admin-ui/app/routes/Apps/Gluu/styles/GluuAppSidebar.style.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const styles = makeStyles()({
88
top: 140,
99
height: 70,
1010
borderBottomLeftRadius: 20,
11-
borderBottomRightRadius: 20,
11+
borderBottomRightRadius: 20
1212
},
1313
wave: {
1414
position: 'relative',
@@ -19,7 +19,15 @@ const styles = makeStyles()({
1919
textAlign: 'center',
2020
position: 'relative',
2121
top: -130,
22-
fontWeight: 500,
22+
fontWeight: 500
23+
},
24+
waveContainerFixed: {
25+
position: 'absolute',
26+
bottom: 0,
27+
left: 0,
28+
right: 0,
29+
zIndex: 10,
30+
background: 'inherit'
2331
}
2432
})
2533

0 commit comments

Comments
 (0)