erp-platform/ui/src/utils/navigation.ts

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-05-06 06:45:49 +00:00
import { NavigationTree } from '@/@types/navigation'
import {
NAV_ITEM_TYPE_COLLAPSE,
NAV_ITEM_TYPE_ITEM,
NAV_ITEM_TYPE_TITLE,
} from '@/constants/navigation.constant'
2025-08-13 20:29:27 +00:00
import { MenuDto } from '@/proxy/menus/models'
2025-05-06 06:45:49 +00:00
export default function getChildren(menu: MenuDto[], parentCode: string | null): NavigationTree[] {
const menus: NavigationTree[] = []
for (const child of menu.filter((a) => a.parentCode === parentCode)) {
const item: NavigationTree = {
2025-08-13 20:29:27 +00:00
key: child.url?.length ? child.url : child.code ?? '',
2025-05-06 06:45:49 +00:00
path: child.url ?? '',
title: child.displayName ?? '',
icon: child.icon ?? '',
type: NAV_ITEM_TYPE_TITLE,
translateKey: child.displayName ?? '',
authority: [child.requiredPermissionName ?? ''],
subMenu: [],
}
2025-08-13 20:29:27 +00:00
2025-05-06 06:45:49 +00:00
if (child.code) {
const subMenu = getChildren(menu, child.code)
if (subMenu.length) {
item.subMenu = subMenu
item.type = child.parentCode ? NAV_ITEM_TYPE_COLLAPSE : NAV_ITEM_TYPE_TITLE
} else {
item.type = NAV_ITEM_TYPE_ITEM
}
//Eğer submenu veya path varsa menude gösterilmeli.
//Yani submenüde biri gösterilecekse ana menüsü gösterilmeli
if (item.subMenu.length > 0 || item.path !== '') {
menus.push(item)
}
}
}
return menus
}