Skip to content

Commit

Permalink
Show import failed error
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilit committed Nov 3, 2024
1 parent 28ec12b commit 3207bb9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
71 changes: 39 additions & 32 deletions src/components/EditorHeader/Modal/Modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,44 +147,51 @@ export default function Modal({
ast = parser.astify(importSource.src, {
database: database === DB.GENERIC ? importDb : database,
});
} catch (err) {
let message = err.message;
if (err.location) {
message = err.name + " [Ln " + err.location.start.line + ", Col " + err.location.start.column + "]: " + err.message;
}

setError({
type: STATUS.ERROR,
message
});
} catch (error) {
const message = error.location
? `${error.name} [Ln ${error.location.start.line}, Col ${error.location.start.column}]: ${error.message}`
: error.message;

setError({ type: STATUS.ERROR, message });
return;
}

const d = importSQL(
ast,
database === DB.GENERIC ? importDb : database,
database,
);
if (importSource.overwrite) {
setTables(d.tables);
setRelationships(d.relationships);
setTransform((prev) => ({ ...prev, pan: { x: 0, y: 0 } }));
setNotes([]);
setAreas([]);
if (databases[database].hasTypes) setTypes(d.types ?? []);
if (databases[database].hasEnums) setEnums(d.enums ?? []);
setUndoStack([]);
setRedoStack([]);
} else {
setTables((prev) =>
[...prev, ...d.tables].map((t, i) => ({ ...t, id: i })),
);
setRelationships((prev) =>
[...prev, ...d.relationships].map((r, i) => ({ ...r, id: i })),
try {
const diagramData = importSQL(
ast,
database === DB.GENERIC ? importDb : database,
database,
);

if (importSource.overwrite) {
setTables(diagramData.tables);
setRelationships(diagramData.relationships);
setTransform((prev) => ({ ...prev, pan: { x: 0, y: 0 } }));
setNotes([]);
setAreas([]);
if (databases[database].hasTypes) setTypes(diagramData.types ?? []);
if (databases[database].hasEnums) setEnums(diagramData.enums ?? []);
setUndoStack([]);
setRedoStack([]);
} else {
setTables((prev) =>
[...prev, ...diagramData.tables].map((t, i) => ({ ...t, id: i })),
);
setRelationships((prev) =>
[...prev, ...diagramData.relationships].map((r, i) => ({
...r,
id: i,
})),
);
}

setModal(MODAL.NONE);
} catch (error) {
setError({
type: STATUS.ERROR,
message: `${error.message}. Please check for syntax errors or let us know about the error.`,
});
}
setModal(MODAL.NONE);
};

const createNewDiagram = (id) => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/importSQL/sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function fromSQLite(ast, diagramDb = DB.GENERIC) {
if (d.primary_key) field.primary = true;
field.default = "";
if (d.default_val) {
console.log(d.default_val);
let defaultValue = "";
if (d.default_val.value.type === "function") {
defaultValue = d.default_val.value.name.name[0].value;
Expand Down

0 comments on commit 3207bb9

Please sign in to comment.