Skip to content

Commit 86bc4b4

Browse files
getFirstActiveItemFromMenu
1 parent 9bd734a commit 86bc4b4

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/components/Layout/LeftPanel/utils.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MenuGroup } from './LeftPanel.types'
1+
import { MenuGroup, MenuItem } from './LeftPanel.types'
22

33
export const parseActiveItem = (pathname: string, menuItems: MenuGroup[], matcher: any) => {
44
let ret = '-1'
@@ -7,13 +7,13 @@ export const parseActiveItem = (pathname: string, menuItems: MenuGroup[], matche
77
let subItem = undefined
88
const menuItem = group.items?.find((item) => {
99
if (item.children && item.children.length) {
10-
const f = item.children.find((subItem) => subItem.paths?.find((p) => matcher(pathname, p)))
10+
const f = item.children.find((subItem) => subItem.visibility === true && subItem.paths?.find((p) => matcher(pathname, p)))
1111
if (f) {
1212
subItem = f.id
1313
}
1414
}
1515

16-
return item.paths?.find((j) => matcher(pathname, j))
16+
return item.visibility === true && item.paths?.find((j) => matcher(pathname, j))
1717
})
1818

1919
if (subItem) {
@@ -25,3 +25,15 @@ export const parseActiveItem = (pathname: string, menuItems: MenuGroup[], matche
2525

2626
return ret
2727
}
28+
29+
export const getFirstActiveItemFromMenu = (menu: MenuGroup[]) => {
30+
let firstActivePage: any = undefined
31+
32+
menu?.forEach((group) => {
33+
if (!firstActivePage) {
34+
firstActivePage = group.items?.find((item) => item.visibility === true) as MenuItem
35+
}
36+
})
37+
38+
return firstActivePage
39+
}

0 commit comments

Comments
 (0)