Recover relationships after undoing table delete
This commit is contained in:
parent
679f6b05e5
commit
3988b8d990
@ -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) {
|
||||
|
@ -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] }),
|
||||
},
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user