(item: MenuTree)
| 47 | const routes: RouteObject[] = []; |
| 48 | |
| 49 | const processItem = (item: MenuTree) => { |
| 50 | // if group, process children |
| 51 | if (item.type === PermissionType.GROUP) { |
| 52 | for (const child of item.children || []) { |
| 53 | processItem(child); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // if catalogue, process children |
| 58 | if (item.type === PermissionType.CATALOGUE) { |
| 59 | const children = item.children || []; |
| 60 | if (children.length > 0) { |
| 61 | const firstChild = children[0]; |
| 62 | if (firstChild.path) { |
| 63 | routes.push({ |
| 64 | path: getRoutePath(item.path, parent?.path), |
| 65 | children: [ |
| 66 | { |
| 67 | index: true, |
| 68 | element: <Navigate to={getRoutePath(firstChild.path, item.path)} replace />, |
| 69 | }, |
| 70 | ...convertToRoute(children, item), |
| 71 | ], |
| 72 | }); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // if menu, create route |
| 78 | if (item.type === PermissionType.MENU) { |
| 79 | const props = generateProps(item); |
| 80 | |
| 81 | routes.push({ |
| 82 | path: getRoutePath(item.path, parent?.path), |
| 83 | element: Component(item.component, props), |
| 84 | }); |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | for (const item of items) { |
| 89 | processItem(item); |
no test coverage detected