Kairo-Jinkendo/frontend/src/config/appNav.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

import {
Gauge,
LayoutDashboard,
Map,
Play,
Users,
FolderKanban,
} from 'lucide-react'
import { getNavViews } from '../registry/viewRegistry.js'
/** @typedef {{ key: string, to: string, label: string, shortLabel: string, end?: boolean, Icon: import('react').ForwardRefExoticComponent, matchPrefix?: string, objectPrefixes?: string[] }} AppNavItem */
const ICON_BY_KEY = {
'kairo.cockpit': LayoutDashboard,
'kairo.work': Play,
'kairo.plan': Map,
'kairo.control': Gauge,
'kairo.team': Users,
'kairo.initiatives': FolderKanban,
}
/**
* @param {Set<string>|string[]} capabilities
* @returns {AppNavItem[]}
*/
export function getAppNavItems(capabilities) {
return getNavViews(capabilities).map((view) => ({
key: view.key,
to: view.path,
label: view.navLabel || view.title,
shortLabel: view.shortLabel || view.title,
end: view.path === '/cockpit' || view.path === '/team',
Icon: ICON_BY_KEY[view.key] || LayoutDashboard,
matchPrefix: view.matchPrefix,
objectPrefixes: view.objectPrefixes,
}))
}
/**
* @param {string} pathname
* @param {AppNavItem} item
* @param {boolean} routerIsActive
*/
export function isNavItemActive(pathname, item, routerIsActive) {
if (item.matchPrefix && pathname.startsWith(item.matchPrefix)) {
return true
}
if (item.objectPrefixes?.some((prefix) => pathname.startsWith(prefix))) {
return true
}
if (item.key === 'kairo.initiatives' && pathname.startsWith('/initiatives')) {
return true
}
return routerIsActive
}