Skip to content

Commit

Permalink
Recover relationships after undoing table delete
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilit committed May 31, 2024
1 parent 679f6b0 commit 3988b8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/EditorHeader/ControlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion src/context/TablesContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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] }),
},
]);
Expand Down

0 comments on commit 3988b8d

Please sign in to comment.