react-diagrams icon indicating copy to clipboard operation
react-diagrams copied to clipboard

Rules when create links

Open mathiasbaldissera opened this issue 7 years ago • 2 comments

Is there any way to put rules when connecting 2 nodes? For Example: I Have 3 Node X, 3 node Y and 2 node Z, When I try to connect one of the Node X to one of Node Z, show an alert and then deny the connection?

mathiasbaldissera avatar Aug 01 '19 05:08 mathiasbaldissera

Hello,

Well there is a property for DiagramWidget called allowLooseLinks <DiagramWidget className="srd-demo-canvas" diagramEngine={engine} allowLooseLinks={false} />

This enables code snippet in DiagramWidget Line 353 //check for / remove any loose links in any models which have been moved 353: if (!this.props.allowLooseLinks && this.state.wasMoved) {

If you notice line 379 there is condition: if (!sourcePort.canLinkToPort(targetPort))

So this means that you have to create own PortModel or inherit from it and override function canLinkToPort(port: PortModel): boolean { return true; } Notice that you can use port.getParent() to get node and then you can check if nodes can be connected or not. :) hope this will help

DanieLazarLDAPPS avatar Aug 07 '19 15:08 DanieLazarLDAPPS

Oh, it's easier than I imagined. Thank You very much. I was doing this inside the render() function of the linkWidget (a little of workaround)

mathiasbaldissera avatar Aug 08 '19 15:08 mathiasbaldissera