Skip to content

Commit

Permalink
added doesRelationAlredyExists function
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelDeTena committed Jan 16, 2024
1 parent ab50afb commit c408907
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/core/providers/canvas-schema/canvas-schema.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ export const CanvasSchemaProvider: React.FC<Props> = props => {
// TODO: #90
//https://github.com/Lemoncode/mongo-modeler/issues/90
const addRelation = (relation: RelationVm) => {
setSchema(prevSchema =>
produce(prevSchema, draft => {
draft.relations.push(relation);
})
if (!doesRelationAlreadyExists(relation)) {
setSchema(prevSchema =>
produce(prevSchema, draft => {
draft.relations.push(relation);
})
);
}
};

const doesRelationAlreadyExists = (relation: RelationVm): boolean => {
return canvasSchema.relations.some(
canvasRelation => canvasRelation !== relation
);
};

Expand Down

0 comments on commit c408907

Please sign in to comment.