Skip to content

Commit

Permalink
Cherry-pick: Display input port type specific default suggestions only (
Browse files Browse the repository at this point in the history
#11268) AND Node AutoComplete suggestions sorted alphabetically within the same group (#11280) (#11290)

* Display input port type specific default suggestions only (#11268)

* input port type specific default suggestions

* test fix

* Node AutoComplete suggestions sorted alphabetically within the same group (#11280)


* add/update tests
  • Loading branch information
zeusongit authored Nov 30, 2020
1 parent cb0fbc3 commit 9b39afa
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,25 @@ internal void PopulateAutoCompleteCandidates()
// If node match searchElements found, use default suggestions
if (!searchElementsCache.Any())
{
searchElementsCache = DefaultResults.Select(e => e.Model).ToList();
FilteredResults = DefaultResults;
searchElementsCache = DefaultResults.Select(e => e.Model).ToList();
switch (PortViewModel.PortModel.GetInputPortType())
{
case "int":
FilteredResults = DefaultResults.Where(e => e.Name == "Number Slider" || e.Name == "Integer Slider").ToList();
break;
case "double":
FilteredResults = DefaultResults.Where(e => e.Name == "Number Slider" || e.Name == "Integer Slider").ToList();
break;
case "string":
FilteredResults = DefaultResults.Where(e => e.Name == "String").ToList();
break;
case "bool":
FilteredResults = DefaultResults.Where(e => e.Name == "Boolean").ToList();
break;
default:
FilteredResults = DefaultResults;
break;
}
}
else
{
Expand Down Expand Up @@ -172,8 +189,8 @@ internal IEnumerable<NodeSearchElement> GetMatchingSearchElements()
//first sort by type distance to input port type
elements.Sort(comparer);
//then sort by node library group (create, action, or query node)
//this results in a list of elements with 3 major groups(create,action,query), each group is sub sorted into types.
return elements.OrderBy(x => x.Group);
//this results in a list of elements with 3 major groups(create,action,query), each group is sub sorted into types and then sorted by name.
return elements.OrderBy(x => x.Group).ThenBy(x => x.Name);


}
Expand Down
49 changes: 38 additions & 11 deletions test/DynamoCoreWpfTests/NodeAutoCompleteSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected override void GetLibrariesToPreload(List<string> libraries)
libraries.Add("BuiltIn.ds");
libraries.Add("FFITarget.dll");
libraries.Add("ProtoGeometry.dll");
libraries.Add("DSCoreNodes.dll");
}

public override void Open(string path)
Expand Down Expand Up @@ -130,10 +131,7 @@ public void NodeSuggestions_InputPortZeroTouchNodeForProperty_AreCorrect()
"FFITarget.FFITarget.ClassFunctionality.ClassFunctionality",
"FFITarget.FFITarget.ClassFunctionality.Instance" };
var expectedNodes = nodes.OrderBy(s => s);
for (int i = 0; i < 4; i++)
{
Assert.AreEqual(expectedNodes.ElementAt(i), suggestedNodes.ElementAt(i));
}
Assert.IsTrue(expectedNodes.SequenceEqual(suggestedNodes));
}

[Test]
Expand All @@ -152,7 +150,6 @@ public void NodeSuggestions_GeometryNodes_SortedBy_NodeGroup_CreateActionQuery()
Assert.AreEqual(SearchElementGroup.Create, suggestions.FirstOrDefault().Group);
Assert.AreEqual(SearchElementGroup.Action, suggestions.ElementAt(suggestions.Count()/2).Group);
Assert.AreEqual(SearchElementGroup.Query, suggestions.LastOrDefault().Group);

}

[Test]
Expand Down Expand Up @@ -239,7 +236,7 @@ public void NodeSearchElementComparerSortsBasedOnTypeDistance_MultiReturnNodeMod
}

[Test]
public void NodeSuggestions_DefaultSuggestions()
public void NodeSuggestionsAreSortedBasedOnGroupAndAlphabetically()
{
Open(@"UI\builtin_inputport_suggestion.dyn");

Expand All @@ -255,6 +252,38 @@ public void NodeSuggestions_DefaultSuggestions()
var searchViewModel = ViewModel.CurrentSpaceViewModel.NodeAutoCompleteSearchViewModel;
searchViewModel.PortViewModel = inPorts[0];

var suggestions = searchViewModel.GetMatchingSearchElements();
Assert.AreEqual(6, suggestions.Count());

var suggestedNodes = suggestions.Select(s => s.FullName);
var expectedNodes = new[] { "DSCoreNodes.DSCore.Color.Add",
"DSCoreNodes.DSCore.Color.ByARGB",
"DSCoreNodes.DSCore.Color.Divide",
"DSCoreNodes.DSCore.Color.Multiply",
"DSCoreNodes.DSCore.ColorRange.GetColorAtParameter",
"DSCoreNodes.DSCore.IO.Image.Pixels"};

Assert.IsTrue(expectedNodes.SequenceEqual(suggestedNodes));

}

[Test]
public void NodeSuggestions_DefaultSuggestions()
{
Open(@"UI\builtin_inputport_suggestion.dyn");

// Get the node view for a specific node in the graph
NodeView nodeView = NodeViewWithGuid(Guid.Parse("b6cb6ceb21df4c7fb6b186e6ff399afc").ToString());

var inPorts = nodeView.ViewModel.InPorts;
Assert.AreEqual(2, inPorts.Count());
var port = inPorts[0].PortModel;
var type = port.GetInputPortType();
Assert.AreEqual("var[]..[]", type);

var searchViewModel = ViewModel.CurrentSpaceViewModel.NodeAutoCompleteSearchViewModel;
searchViewModel.PortViewModel = inPorts[0];

// Running the default algorithm should return no suggestions
var suggestions = searchViewModel.GetMatchingSearchElements();
Assert.AreEqual(0, suggestions.Count());
Expand Down Expand Up @@ -282,13 +311,11 @@ public void SearchNodeAutocompletionSuggestions()
var searchViewModel = (ViewModel.CurrentSpaceViewModel.NodeAutoCompleteSearchViewModel as NodeAutoCompleteSearchViewModel);
searchViewModel.PortViewModel = inPorts[0];

var suggestions = searchViewModel.GetMatchingSearchElements();

// Get the matching node elements for the specific node port.
searchViewModel.PopulateAutoCompleteCandidates();

// Filter the node elements using the search field.
searchViewModel.SearchAutoCompleteCandidates("der");
searchViewModel.SearchAutoCompleteCandidates("ar");
Assert.AreEqual(2 , searchViewModel.FilteredResults.Count());
}

Expand All @@ -315,8 +342,8 @@ public void NodeSuggestions_SkippedSuggestions()

// The initial list will fill the FilteredResults with a list of default options
searchViewModel.PopulateAutoCompleteCandidates();
Assert.AreEqual(5, searchViewModel.FilteredResults.Count());
Assert.AreEqual("String", searchViewModel.FilteredResults.FirstOrDefault().Name);
Assert.AreEqual(2, searchViewModel.FilteredResults.Count());
Assert.AreEqual("Number Slider", searchViewModel.FilteredResults.FirstOrDefault().Name);
}
}
}

0 comments on commit 9b39afa

Please sign in to comment.