How delete links without targetPort linked
Hello.
I am trying to create a series of connected nodes, but I have not been able to control when a link is created without a target.

Any help would be very useful.
@edwinjoel1984 Were you able to figure out an approach for this?
This how I make it works.
In diagramModel, I add an event listener:
diagramModel.addListener({
linksUpdated: this.removeNotValidLink,
});
When you created new link, or update targetPort of a link, linksUpdated() event should be called, and then trigger function removeNotValidLink(). On removeNotValidLink(), I map though all links and remove which have targetPort === null. For better user experience and performance, I will trigger removeNotValidLink() after 10s since the last event listener linksUpdated() call, and delete all previous setTimeout()
removeNotValidLink = () => {
if (checkValidLinkTimeout) {
clearTimeout(checkValidLinkTimeout);
}
checkValidLinkTimeout = setTimeout(() => {
const model = app.getDiagramEngine().getDiagramModel();
const listLink = Object.values(model.getLinks());
listLink.forEach(link => {
if (!link.targetPort) {
model.removeLink(link);
// console.log('invalid');
this.forceUpdate();
}
});
}, 10000);
};
I hope that work for you!
Hi there, folks in the future
link.targetPort is a protected property.
this.props.app.getModal() is :
public getModel(){
return this.diagramEngine.getModel();
}
And in your container do the following.
Here I am using @emotion to create
You can put onMouseUp in your container
<S.Body onMouseUp={() => {
const model = this.props.app.getModel();
const listLink = Object.values(model.getLinks());
listLink.forEach(link => {
if(!link.getTargetPort()){
model.removeLink(link);
}
});
}}>
That's how I did it, thanks!