Skip to content

Commit 2bfcbef

Browse files
1ilitewqazxc
authored andcommitted
Fix crash on copy and duplicate table (drawdb-io#679)
* Fix crash on copy * Fix duplicatte
1 parent 795fba5 commit 2bfcbef

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
@@ -683,10 +683,12 @@ export default function ControlPanel({
683683
case ObjectType.TABLE: {
684684
const copiedTable = tables.find((t) => t.id === selectedElement.id);
685685
addTable({
686-
...copiedTable,
687-
x: copiedTable.x + 20,
688-
y: copiedTable.y + 20,
689-
id: nanoid(),
686+
table: {
687+
...copiedTable,
688+
x: copiedTable.x + 20,
689+
y: copiedTable.y + 20,
690+
id: nanoid(),
691+
},
690692
});
691693
break;
692694
}
@@ -749,12 +751,15 @@ export default function ControlPanel({
749751
return;
750752
}
751753
const v = new Validator();
754+
console.log(obj);
752755
if (v.validate(obj, tableSchema).valid) {
753756
addTable({
754-
...obj,
755-
x: obj.x + 20,
756-
y: obj.y + 20,
757-
id: nanoid(),
757+
table: {
758+
...obj,
759+
x: obj.x + 20,
760+
y: obj.y + 20,
761+
id: nanoid(),
762+
},
758763
});
759764
} else if (v.validate(obj, areaSchema).valid) {
760765
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)