Skip to content

Database diagrams editor that allows you to visualize and design your DB with a single query.

fix undo delete tables

Guy Ben-Aharon363f7fd756dd
diff --git a/src/context/chartdb-context/chartdb-provider.tsx b/src/context/chartdb-context/chartdb-provider.tsx
index 990a76b9..9562e210 100644
--- a/src/context/chartdb-context/chartdb-provider.tsx
+++ b/src/context/chartdb-context/chartdb-provider.tsx
@@ -181,18 +181,27 @@ export const ChartDBProvider: React.FC<React.PropsWithChildren> = ({
) => {
const updateTables = (prevTables: DBTable[]) => {
const updatedTables = updateFn(prevTables);
- return prevTables
- .map((prevTable) => {
- const updatedTable = updatedTables.find(
- (t) => t.id === prevTable.id
- );
- return updatedTable
- ? { ...prevTable, ...updatedTable }
- : prevTable;
- })
- .filter((prevTable) =>
- updatedTables.some((t) => t.id === prevTable.id)
- );
+
+ const newTables = updatedTables.filter(
+ (t) =>
+ !prevTables.some((prevTable) => prevTable.id === t.id)
+ );
+
+ return [
+ ...newTables,
+ ...prevTables
+ .map((prevTable) => {
+ const updatedTable = updatedTables.find(
+ (t) => t.id === prevTable.id
+ );
+ return updatedTable
+ ? { ...prevTable, ...updatedTable }
+ : prevTable;
+ })
+ .filter((prevTable) =>
+ updatedTables.some((t) => t.id === prevTable.id)
+ ),
+ ];
};
const prevTables = [...tables];
diff --git a/src/context/history-context/history-provider.tsx b/src/context/history-context/history-provider.tsx
index 6cff5f59..e51fc9da 100644
--- a/src/context/history-context/history-provider.tsx
+++ b/src/context/history-context/history-provider.tsx
@@ -214,8 +214,6 @@ export const HistoryProvider: React.FC<React.PropsWithChildren> = ({
return;
}
- console.log('undo', action);
-
const handler = undoActionHandlers[action.action];
addRedoAction(action);