Skip to content

Commit

Permalink
Check for invalid references on import
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilit committed Aug 2, 2024
1 parent ed12e3b commit 52b4477
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/components/EditorHeader/Modal/ImportDiagram.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@ export default function ImportDiagram({ setImportData, error, setError }) {
return;
}

let ok = true;
jsonObject.relationships.forEach((rel) => {
if (
!jsonObject.tables[rel.startTableId] ||
!jsonObject.tables[rel.endTableId]
) {
setError({
type: STATUS.ERROR,
message: `Relationship ${rel.name} references a table that does not exist.`,
});
ok = false;
return;
}

if (
!jsonObject.tables[rel.startTableId].fields[rel.startFieldId] ||
!jsonObject.tables[rel.endTableId].fields[rel.endFieldId]
) {
setError({
type: STATUS.ERROR,
message: `Relationship ${rel.name} references a field that does not exist.`,
});
ok = false;
return;
}
});

if (!ok) return;

setImportData(jsonObject);
if (diagramIsEmpty()) {
setError({
Expand Down

0 comments on commit 52b4477

Please sign in to comment.