@@ -71,6 +71,33 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
71
71
return ! item . children . hidden . getView ( ) ;
72
72
} , [ ] ) ;
73
73
74
+ const generateItemKeyRecord = useCallback ( ( items : LayoutMenuItemComp [ ] ) => {
75
+ const result : Record < string , LayoutMenuItemComp > = { } ;
76
+ items . forEach ( ( item ) => {
77
+ const subItems = item . children . items . getView ( ) ;
78
+ if ( subItems . length > 0 ) {
79
+ Object . assign ( result , generateItemKeyRecord ( subItems ) )
80
+ }
81
+ result [ item . getItemKey ( ) ] = item ;
82
+ } ) ;
83
+ return result ;
84
+ } , [ items ] )
85
+
86
+ const itemKeyRecord = useMemo ( ( ) => {
87
+ return generateItemKeyRecord ( items )
88
+ } , [ generateItemKeyRecord , items ] ) ;
89
+
90
+ const onMenuItemClick = ( { key} : { key : string } ) => {
91
+ const itemComp = itemKeyRecord [ key ] ;
92
+ const url = [
93
+ ALL_APPLICATIONS_URL ,
94
+ pathParam . applicationId ,
95
+ pathParam . viewMode ,
96
+ itemComp . getItemKey ( ) ,
97
+ ] . join ( "/" ) ;
98
+ itemComp . children . action . act ( url ) ;
99
+ }
100
+
74
101
const getMenuItem = useCallback (
75
102
( itemComps : LayoutMenuItemComp [ ] ) : MenuProps [ "items" ] => {
76
103
return itemComps . filter ( filterItem ) . map ( ( item ) => {
@@ -81,6 +108,8 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
81
108
title : label ,
82
109
key : item . getItemKey ( ) ,
83
110
icon : < span > { item . children . icon . getView ( ) } </ span > ,
111
+ onTitleClick : onMenuItemClick ,
112
+ onClick : onMenuItemClick ,
84
113
...( subItems . length > 0 && { children : getMenuItem ( subItems ) } ) ,
85
114
} ;
86
115
} ) ;
@@ -133,25 +162,6 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
133
162
} ,
134
163
[ filterItem ]
135
164
) ;
136
-
137
- const generateItemKeyRecord = useCallback ( ( items : LayoutMenuItemComp [ ] ) => {
138
- console . log ( 'generateItemKeyRecord' , items )
139
- const result : Record < string , LayoutMenuItemComp > = { } ;
140
- items . forEach ( ( item ) => {
141
- const subItems = item . children . items . getView ( ) ;
142
- if ( subItems . length > 0 ) {
143
- Object . assign ( result , generateItemKeyRecord ( subItems ) )
144
- }
145
- else {
146
- result [ item . getItemKey ( ) ] = item ;
147
- }
148
- } ) ;
149
- return result ;
150
- } , [ items ] )
151
-
152
- const itemKeyRecord = useMemo ( ( ) => {
153
- return generateItemKeyRecord ( items )
154
- } , [ generateItemKeyRecord , items ] ) ;
155
165
156
166
const defaultOpenKeys = useMemo ( ( ) => {
157
167
let itemPath : string [ ] ;
@@ -192,16 +202,6 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
192
202
style = { { height : "100%" } }
193
203
defaultOpenKeys = { defaultOpenKeys }
194
204
selectedKeys = { [ selectedKey ] }
195
- onClick = { ( e ) => {
196
- const itemComp = itemKeyRecord [ e . key ] ;
197
- const url = [
198
- ALL_APPLICATIONS_URL ,
199
- pathParam . applicationId ,
200
- pathParam . viewMode ,
201
- itemComp . getItemKey ( ) ,
202
- ] . join ( "/" ) ;
203
- itemComp . children . action . act ( url ) ;
204
- } }
205
205
/>
206
206
</ StyledSide >
207
207
< MainContent > { pageView } </ MainContent >
0 commit comments