Skip to content

Commit cac6f19

Browse files
feat: make parent menu items clickable
1 parent 9ac9dee commit cac6f19

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

client/packages/lowcoder/src/comps/comps/layout/layoutMenuItemComp.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ export class LayoutMenuItemComp extends MultiBaseComp<ChildrenType> {
3838
}
3939

4040
override getPropertyView(): ReactNode {
41-
const isLeaf = this.children.items.getView().length === 0;
4241
return (
4342
<>
44-
{isLeaf &&
45-
this.children.action.propertyView({
46-
onAppChange: (label) => {
47-
label && this.children.label.dispatchChangeValueAction(label);
48-
},
49-
})}
43+
{this.children.action.propertyView({
44+
onAppChange: (label) => {
45+
label && this.children.label.dispatchChangeValueAction(label);
46+
},
47+
})}
5048
{this.children.label.propertyView({ label: trans("label") })}
5149
{this.children.icon.propertyView({
5250
label: trans("icon"),

client/packages/lowcoder/src/comps/comps/layout/navLayout.tsx

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
7171
return !item.children.hidden.getView();
7272
}, []);
7373

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+
74101
const getMenuItem = useCallback(
75102
(itemComps: LayoutMenuItemComp[]): MenuProps["items"] => {
76103
return itemComps.filter(filterItem).map((item) => {
@@ -81,6 +108,8 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
81108
title: label,
82109
key: item.getItemKey(),
83110
icon: <span>{item.children.icon.getView()}</span>,
111+
onTitleClick: onMenuItemClick,
112+
onClick: onMenuItemClick,
84113
...(subItems.length > 0 && { children: getMenuItem(subItems) }),
85114
};
86115
});
@@ -133,25 +162,6 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
133162
},
134163
[filterItem]
135164
);
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]);
155165

156166
const defaultOpenKeys = useMemo(() => {
157167
let itemPath: string[];
@@ -192,16 +202,6 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
192202
style={{ height: "100%" }}
193203
defaultOpenKeys={defaultOpenKeys}
194204
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-
}}
205205
/>
206206
</StyledSide>
207207
<MainContent>{pageView}</MainContent>

0 commit comments

Comments
 (0)