Fix loading the diagram on open to load in types and enums

This commit is contained in:
1ilit 2024-07-08 02:17:46 +03:00
parent c907cfea47
commit c84990ca6d
2 changed files with 15 additions and 4 deletions

View File

@ -17,6 +17,7 @@ import {
useTransform,
useTypes,
useUndoRedo,
useTasks,
} from "../../../hooks";
import { saveAs } from "file-saver";
import { Parser } from "node-sql-parser";
@ -61,6 +62,7 @@ export default function Modal({
const { setTypes } = useTypes();
const { settings } = useSettings();
const { setEnums } = useEnums();
const { setTasks } = useTasks();
const { setTransform } = useTransform();
const { setUndoStack, setRedoStack } = useUndoRedo();
const [importSource, setImportSource] = useState({
@ -99,23 +101,31 @@ export default function Modal({
setDiagramId(diagram.id);
setTitle(diagram.name);
setTables(diagram.tables);
setTypes(diagram.types);
setRelationships(diagram.references);
setAreas(diagram.areas);
setNotes(diagram.notes);
setTasks(diagram.todos ?? []);
setTransform({
pan: diagram.pan,
zoom: diagram.zoom,
});
setUndoStack([]);
setRedoStack([]);
if (databases[database].hasTypes) {
setTypes(diagram.types ?? []);
}
if (databases[database].hasEnums) {
setEnums(diagram.enums ?? []);
}
window.name = `d ${diagram.id}`;
} else {
Toast.error("Oops! Something went wrong.");
window.name = "";
Toast.error(t("didnt_find_diagram"));
}
})
.catch(() => {
Toast.error("Oops! Couldn't load diagram.");
.catch((error) => {
console.log(error);
Toast.error(t("didnt_find_diagram"));
});
};

View File

@ -227,6 +227,7 @@ const en = {
no_enums_text: "Define enums here",
declare_array: "Declare array",
empty_index_name: "Declared an index with no name in table '{{tableName}}'",
didnt_find_diagram: "Oops! Didn't find the diagram.",
},
};