23 lines
733 B
TypeScript
23 lines
733 B
TypeScript
import { BX_MENU_CATALOG, BX_MENU_CURRENT_PHASE, type BxMenuEntry } from '@/constants/bxMenuCatalog'
|
|
|
|
export function canAccess(
|
|
menuCode: string,
|
|
opts: { isSuperAdmin: boolean; all: boolean; menuCodes: string[] },
|
|
): boolean {
|
|
if (opts.isSuperAdmin || opts.all) return true
|
|
return opts.menuCodes.includes(menuCode)
|
|
}
|
|
|
|
export function filterVisibleEntries(
|
|
opts: { isSuperAdmin: boolean; all: boolean; menuCodes: string[] },
|
|
phase: number = BX_MENU_CURRENT_PHASE,
|
|
): BxMenuEntry[] {
|
|
return BX_MENU_CATALOG.filter(
|
|
(e) => !e.hidden && e.phase <= phase && canAccess(e.menuCode, opts),
|
|
)
|
|
}
|
|
|
|
export function entryByPath(path: string): BxMenuEntry | undefined {
|
|
return BX_MENU_CATALOG.find((e) => e.path === path)
|
|
}
|