Skip to content

Commit 6d33ae7

Browse files
fix: handle empty itemKeys for sub-menus
1 parent c1c5ac8 commit 6d33ae7

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ export class LayoutMenuItemListComp extends list(LayoutMenuItemCompMigrate) {
100100
const data = this.getView();
101101
this.dispatch(
102102
this.pushAction(
103-
value || {
104-
label: trans("menuItem") + " " + (data.length + 1),
105-
itemKey: genRandomKey(),
106-
}
103+
value
104+
? {
105+
...value,
106+
itemKey: value.itemKey || genRandomKey(),
107+
} : {
108+
label: trans("menuItem") + " " + (data.length + 1),
109+
itemKey: genRandomKey(),
110+
}
107111
)
108112
);
109113
}

client/packages/lowcoder/src/comps/comps/navComp/components/DroppableMenuItem.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { useDraggable, useDroppable } from "@dnd-kit/core";
22
import { trans } from "i18n";
3-
import { Fragment } from "react";
3+
import { Fragment, useEffect } from "react";
44
import styled from "styled-components";
55
import DroppablePlaceholder from "./DroppablePlaceHolder";
66
import MenuItem, { ICommonItemProps } from "./MenuItem";
77
import { IDragData, IDropData } from "./types";
8+
import { LayoutMenuItemComp } from "comps/comps/layout/layoutMenuItemComp";
9+
import { genRandomKey } from "comps/utils/idGenerator";
810

911
const DraggableMenuItemWrapper = styled.div`
1012
position: relative;
@@ -63,6 +65,22 @@ export default function DraggableMenuItem(props: IDraggableMenuItemProps) {
6365
disabled: isDragging || disabled || disableDropIn,
6466
data: dropData,
6567
});
68+
69+
// TODO: Remove this later.
70+
// Set ItemKey for previously added sub-menus
71+
useEffect(() => {
72+
if(!items.length) return;
73+
if(!(items[0] instanceof LayoutMenuItemComp)) return;
74+
75+
return items.forEach(item => {
76+
const subItem = item as LayoutMenuItemComp;
77+
const itemKey = subItem.children.itemKey.getView();
78+
if(itemKey === '') {
79+
subItem.children.itemKey.dispatchChangeValueAction(genRandomKey())
80+
}
81+
})
82+
}, [items])
83+
6684
return (
6785
<>
6886
<DraggableMenuItemWrapper>

0 commit comments

Comments
 (0)