Skip to content

Commit

Permalink
[DYN-7332] Add pins to groups (#15452)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaylo-matov authored Sep 4, 2024
1 parent 755c4c9 commit b41d055
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/DynamoCore/Graph/Annotations/AnnotationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ public IEnumerable<ModelBase> Nodes
}
}

// First remove all pins from the input
var valuesWithoutPins = value
.Where(x => !(x is ConnectorPinModel));

// then recalculate which pins belongs to the
// group and add them to the nodes collection
var pinModels = GetPinsFromNodes(value.OfType<NodeModel>());
nodes = valuesWithoutPins.Concat(pinModels)
.ToHashSet<ModelBase>();
// First separate all pins from the input
var pinModels = value.OfType<ConnectorPinModel>().ToList();
var valuesWithoutPins = value.Except(pinModels);

// then recalculate which pins belong to the group based on the nodes
var pinsFromNodes = GetPinsFromNodes(valuesWithoutPins.OfType<NodeModel>());

// Combine all
nodes = valuesWithoutPins.Concat(pinModels).Concat(pinsFromNodes).ToHashSet<ModelBase>();

if (nodes != null && nodes.Any())
{
Expand Down
31 changes: 31 additions & 0 deletions test/DynamoCoreWpfTests/AnnotationViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,36 @@ public void UngroupingCollapsedGroupWillUnCollapseAllGroupContent()
// Assert
Assert.That(groupContent.All(x => x.IsCollapsed == false));
}

[Test]
public void AddConnectorPinsToGroups()
{
// Arrange
Open(@"core\annotationViewModelTests\groupsTestFile.dyn");

var groupGuid = new Guid("8324afb7-2d77-4a75-aa5e-f10e59964c2b");
var connectorGuid = new Guid("17318da5-dd19-4962-a7b7-51344001f14b");

// Act
var ws = this.Model.CurrentWorkspace;
var group1 = ws.Annotations.FirstOrDefault(annotation => annotation.GUID == groupGuid);
var connector = ws.Connectors.FirstOrDefault(connector => connector.GUID == connectorGuid);
var connectorPin = connector.ConnectorPinModels.FirstOrDefault();

// Assert
Assert.IsNotNull(group1, $"Expected to find annotation group with GUID {groupGuid}, but it was not found.");
Assert.IsNotNull(connector, $"Expected to find connector with GUID {connectorGuid}, but it was not found.");
Assert.IsNotNull(connectorPin, "Expected to find a ConnectorPinModel associated with the connector, but it was not found.");

var initialNodeCount = group1.Nodes.Count();
Assert.AreEqual(2, initialNodeCount, $"Expected the group to contain 2 nodes initially, but found {initialNodeCount}.");

// Act: Add the connectorPin to the group
group1.AddToTargetAnnotationModel(connectorPin);

// Assert
var finalNodeCount = group1.Nodes.Count();
Assert.AreEqual(3, finalNodeCount, $"Expected the group to contain 3 nodes after adding the connector pin, but found {finalNodeCount}.");
}
}
}

0 comments on commit b41d055

Please sign in to comment.