Skip to content

Commit

Permalink
Merge pull request #19 from WiseTechGlobal/AN9/WI00692027/NCN-BufferN…
Browse files Browse the repository at this point in the history
…ode-Relationship-implementation

An9/wi00692027/ncn-Introduced Enabled property to handle the dragNewLinkBehaviour
  • Loading branch information
AarthiNarayanan authored Jan 17, 2024
2 parents 81a7838 + 4e993c0 commit b76d767
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Blazor.Diagrams.Core/Behaviors/DragNewLinkBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void OnPointerDown(Model? model, MouseEventArgs e)

if (model is PortModel port)
{
if (port.Locked)
if (port.Locked || !port.Enabled)
return;

_targetPositionAnchor = new PositionAnchor(CalculateTargetPosition(e.ClientX, e.ClientY));
Expand Down
1 change: 1 addition & 0 deletions src/Blazor.Diagrams.Core/Models/Base/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected Model(string id)

public string Id { get; }
public bool Locked { get; set; }
public bool Enabled { get; set; } = true;
public bool Visible
{
get => _visible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,27 @@ public void Behavior_ShouldTriggerLinkTargetAttached_WhenLinkSnappedToPortAndMou
// Assert
targetAttachedTriggers.Should().Be(1);
}

[Fact]
public void Behavior_ShouldNotCreateLinkWithSinglePortAnchorSource_WhenMouseDownOnPort()
{
// Arrange
var diagram = new TestDiagram();
diagram.SetContainer(new Rectangle(0, 0, 1000, 400));
var node = new NodeModel(position: new Point(100, 50));
var port = node.AddPort(new PortModel(node)
{
Initialized = true,
Position = new Point(110, 60),
Size = new Size(10, 20),
Enabled = false
});

// Act
diagram.TriggerPointerDown(port,
new PointerEventArgs(100, 100, 0, 0, false, false, false, 0, 0, 0, 0, 0, 0, string.Empty, true));

// Assert
diagram.Links.Count.Should().Be(0);
}
}

0 comments on commit b76d767

Please sign in to comment.