Recover relationships after undoing table delete

This commit is contained in:
1ilit 2024-05-31 20:17:21 +03:00
parent 679f6b05e5
commit 3988b8d990
2 changed files with 10 additions and 3 deletions

View File

@ -146,7 +146,8 @@ export default function ControlPanel({
}
} else if (a.action === Action.DELETE) {
if (a.element === ObjectType.TABLE) {
addTable(a.data, false);
a.data.relationship.forEach((x) => addRelationship(x, false));
addTable(a.data.table, false);
} else if (a.element === ObjectType.RELATIONSHIP) {
addRelationship(a.data, false);
} else if (a.element === ObjectType.NOTE) {
@ -337,7 +338,7 @@ export default function ControlPanel({
}
} else if (a.action === Action.DELETE) {
if (a.element === ObjectType.TABLE) {
deleteTable(a.data.id, false);
deleteTable(a.data.table.id, false);
} else if (a.element === ObjectType.RELATIONSHIP) {
deleteRelationship(a.data.id, false);
} else if (a.element === ObjectType.NOTE) {

View File

@ -68,12 +68,18 @@ export default function TablesContextProvider({ children }) {
const deleteTable = (id, addToHistory = true) => {
if (addToHistory) {
Toast.success(t("table_deleted"));
const rels = relationships.reduce((acc, r) => {
if (r.startTableId === id || r.endTableId === id) {
acc.push(r);
}
return acc;
}, []);
setUndoStack((prev) => [
...prev,
{
action: Action.DELETE,
element: ObjectType.TABLE,
data: tables[id],
data: { table: tables[id], relationship: rels },
message: t("delete_table", { tableName: tables[id] }),
},
]);