Skip to content

Commit 0ead55c

Browse files
authored
Fix crash on copy and duplicate table (#679)
* Fix crash on copy * Fix duplicatte
1 parent e6d29ed commit 0ead55c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/components/EditorHeader/ControlPanel.jsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,12 @@ export default function ControlPanel({
647647
case ObjectType.TABLE: {
648648
const copiedTable = tables.find((t) => t.id === selectedElement.id);
649649
addTable({
650-
...copiedTable,
651-
x: copiedTable.x + 20,
652-
y: copiedTable.y + 20,
653-
id: nanoid(),
650+
table: {
651+
...copiedTable,
652+
x: copiedTable.x + 20,
653+
y: copiedTable.y + 20,
654+
id: nanoid(),
655+
},
654656
});
655657
break;
656658
}
@@ -709,12 +711,15 @@ export default function ControlPanel({
709711
return;
710712
}
711713
const v = new Validator();
714+
console.log(obj);
712715
if (v.validate(obj, tableSchema).valid) {
713716
addTable({
714-
...obj,
715-
x: obj.x + 20,
716-
y: obj.y + 20,
717-
id: nanoid(),
717+
table: {
718+
...obj,
719+
x: obj.x + 20,
720+
y: obj.y + 20,
721+
id: nanoid(),
722+
},
718723
});
719724
} else if (v.validate(obj, areaSchema).valid) {
720725
addArea({

src/context/DiagramContext.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function DiagramContextProvider({ children }) {
4545
if (data) {
4646
setTables((prev) => {
4747
const temp = prev.slice();
48-
temp.splice(data.index, 0, data.table);
48+
temp.splice(data.index || tables.length, 0, data.table);
4949
return temp;
5050
});
5151
} else {

0 commit comments

Comments
 (0)