Fix field delete

This commit is contained in:
1ilit 2023-12-27 04:45:23 +02:00
parent 2395a334bb
commit f44b5fd388
3 changed files with 149 additions and 16 deletions

View File

@ -207,6 +207,27 @@ export default function ControlPanel({
if (a.component === "field") {
updateField(a.tid, a.fid, a.undo);
} else if (a.component === "field_delete") {
setRelationships((prev) => {
return prev.map((e) => {
if (e.startTableId === a.tid && e.startFieldId > a.data.id) {
return {
...e,
startFieldId: e.startFieldId + 1,
startX: tables[a.tid].x + 15,
startY: tables[a.tid].y + (e.startFieldId + 1) * 36 + 50 + 19,
};
}
if (e.endTableId === a.tid && e.endFieldId > a.data.id) {
return {
...e,
endFieldId: e.endFieldId + 1,
endX: tables[a.tid].x + 15,
endY: tables[a.tid].y + (e.endFieldId + 1) * 36 + 50 + 19,
};
}
return e;
});
});
setTables((prev) =>
prev.map((t) => {
if (t.id === a.tid) {
@ -358,6 +379,27 @@ export default function ControlPanel({
if (a.component === "field") {
updateField(a.tid, a.fid, a.redo);
} else if (a.component === "field_delete") {
setRelationships((prev) => {
return prev.map((e) => {
if (e.startTableId === a.tid && e.startFieldId > a.data.id) {
return {
...e,
startFieldId: e.startFieldId - 1,
startX: tables[a.tid].x + 15,
startY: tables[a.tid].y + (e.startFieldId - 1) * 36 + 50 + 19,
};
}
if (e.endTableId === a.tid && e.endFieldId > a.data.id) {
return {
...e,
endFieldId: e.endFieldId - 1,
endX: tables[a.tid].x + 15,
endY: tables[a.tid].y + (e.endFieldId - 1) * 36 + 50 + 19,
};
}
return e;
});
});
updateTable(a.tid, {
fields: tables[a.tid].fields
.filter((field) => field.id !== a.data.id)
@ -1391,7 +1433,7 @@ export default function ControlPanel({
case MODAL.OPEN:
return (
<div>
{diagrams.length === 0 ? (
{diagrams?.length === 0 ? (
<Banner
fullMode={false}
type="info"

View File

@ -671,6 +671,41 @@ export default function TableOverview() {
)
.map((e, i) => ({ ...e, id: i }))
);
setRelationships((prev) => {
return prev.map((e) => {
if (
e.startTableId === t.id &&
e.startFieldId > f.id
) {
return {
...e,
startFieldId: e.startFieldId - 1,
startX: t.x + 15,
startY:
t.y +
(e.startFieldId - 1) * 36 +
50 +
19,
};
}
if (
e.endTableId === t.id &&
e.endFieldId > f.id
) {
return {
...e,
endFieldId: e.endFieldId - 1,
endX: t.x + 15,
endY:
t.y +
(e.endFieldId - 1) * 36 +
50 +
19,
};
}
return e;
});
});
updateTable(i, {
fields: t.fields
.filter((field) => field.id !== j)

View File

@ -803,23 +803,45 @@ export default function Table(props) {
},
]);
setRedoStack([]);
setRelationships((prev) =>
prev
.filter(
(e) =>
!(
(e.startTableId === props.tableData.id &&
e.startFieldId === j) ||
(e.endTableId === props.tableData.id &&
e.endFieldId === j)
)
)
.map((e, i) => ({ ...e, id: i }))
);
setRelationships((prev) => {
return prev.map((e) => {
if (
e.startTableId === props.tableData.id &&
e.startFieldId > f.id
) {
return {
...e,
startFieldId: e.startFieldId - 1,
startX: props.tableData.x + 15,
startY:
props.tableData.y +
(e.startFieldId - 1) * 36 +
50 +
19,
};
}
if (
e.endTableId === props.tableData.id &&
e.endFieldId > f.id
) {
return {
...e,
endFieldId: e.endFieldId - 1,
endX: props.tableData.x + 15,
endY:
props.tableData.y +
(e.endFieldId - 1) * 36 +
50 +
19,
};
}
return e;
});
});
updateTable(props.tableData.id, {
fields: props.tableData.fields
.filter((field) => field.id !== j)
.map((e, i) => ({ ...e, id: i })),
.map((e, k) => ({ ...e, id: k })),
});
}}
>
@ -1285,10 +1307,44 @@ export default function Table(props) {
)
.map((e, i) => ({ ...e, id: i }))
);
setRelationships((prev) => {
return prev.map((e) => {
if (
e.startTableId === props.tableData.id &&
e.startFieldId > fieldData.id
) {
return {
...e,
startFieldId: e.startFieldId - 1,
startX: props.tableData.x + 15,
startY:
props.tableData.y +
(e.startFieldId - 1) * 36 +
50 +
19,
};
}
if (
e.endTableId === props.tableData.id &&
e.endFieldId > fieldData.id
) {
return {
...e,
endFieldId: e.endFieldId - 1,
endX: props.tableData.x + 15,
endY:
props.tableData.y + (e.endFieldId - 1) * 36 + 50 + 19,
};
}
return e;
});
});
updateTable(props.tableData.id, {
fields: props.tableData.fields
.filter((e) => e.id !== fieldData.id)
.map((t, i) => ({ ...t, id: i })),
.map((t, i) => {
return { ...t, id: i };
}),
});
}}
onCancel={() => {}}