Filter out invalid links and sublinks

This commit is contained in:
Andrew Kingston 2024-03-28 18:22:27 +00:00
parent 75d4be94b5
commit 98c91a005d
1 changed files with 9 additions and 4 deletions

View File

@ -117,21 +117,26 @@
return []
}
return navItems
.filter(navitem => {
.filter(navItem => {
// Strip nav items without text
if (!navitem.text) {
if (!navItem.text) {
return false
}
// Strip out links without URLs
if (navItem.type !== "sublinks" && !navItem.url) {
return false
}
// Filter to only links allowed by the current role
const role = navitem.roleId || Constants.Roles.BASIC
const role = navItem.roleId || Constants.Roles.BASIC
return userRoleHierarchy?.find(roleId => roleId === role)
})
.map(navItem => {
const enrichedNavItem = enrichNavItem(navItem)
if (navItem.type === "sublinks" && navItem.subLinks?.length) {
enrichedNavItem.subLinks = navItem.subLinks
.filter(subLink => subLink.text)
.filter(subLink => subLink.text && subLink.url)
.map(enrichNavItem)
}
return enrichedNavItem