Skip to content

Commit

Permalink
Handle null values in watch node/preview bubble (#13855)
Browse files Browse the repository at this point in the history
* Handle null values in watch node/preview bubble

* Add test

* Update WatchNodeTests.cs

(cherry picked from commit b1bc7c2)

# Conflicts:
#	test/DynamoCoreWpfTests/WatchNodeTests.cs
  • Loading branch information
reddyashish authored and twastvedt committed Sep 30, 2024
1 parent b311a23 commit 650228d
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ public WatchViewModel(string label, string path, Action<string> tagGeometry, boo

private static string GetStringFromObject(object obj)
{
if (obj == null)
return Resources.NullString;

TypeCode type = Type.GetTypeCode(obj.GetType());
switch (type)
{
Expand Down Expand Up @@ -285,6 +288,9 @@ private static string ObjectToLabelString(object obj)

private string GetDisplayType(object obj)
{
if (obj == null)
return Resources.NullString;

TypeCode typeCode = Type.GetTypeCode(obj.GetType());
// returning a customized user friendly string instead of just returning the name of the type
switch (typeCode)
Expand Down
23 changes: 23 additions & 0 deletions test/DynamoCoreWpfTests/WatchNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,29 @@ public void WatchNestedDictionary()
Assert.AreEqual(2, watchVM.NumberOfItems);
}

[Test]
public void WatchDictionary()
{
string openPath = Path.Combine(TestDirectory, @"core\watch\WatchDictionary.dyn");
ViewModel.OpenCommand.Execute(openPath);
ViewModel.HomeSpace.Run();

var watchNode = ViewModel.Model.CurrentWorkspace.NodeFromWorkspace("daa19ed1-36b0-4586-ae11-6470e7c196bd") as Watch;

var watchVM = GetWatchViewModel(watchNode);

Assert.AreEqual(3, watchVM.Children.Count);

Assert.AreEqual("1", watchVM.Children.ElementAt(0).NodeLabel);
Assert.AreEqual("Int64", watchVM.Children.ElementAt(0).ValueType);

Assert.AreEqual("null", watchVM.Children.ElementAt(1).NodeLabel);
Assert.AreEqual("null", watchVM.Children.ElementAt(1).ValueType);

Assert.AreEqual("null", watchVM.Children.ElementAt(2).NodeLabel);
Assert.AreEqual("String", watchVM.Children.ElementAt(2).ValueType);
}

[Test]
public void WatchNumber()
{
Expand Down
144 changes: 144 additions & 0 deletions test/core/watch/WatchDictionary.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"Uuid": "b3971a38-9e42-4229-9ebd-7fa012a6ac9b",
"IsCustomNode": false,
"Description": "",
"Name": "WatchDictionary",
"ElementResolver": {
"ResolutionMap": {
"DesignScript.Builtin.Dictionary": {
"Key": "DesignScript.Builtin.Dictionary",
"Value": "DesignScriptBuiltin.dll"
}
}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"Id": "275d5ff387254cfa9ff92fac8f2d0e11",
"NodeType": "CodeBlockNode",
"Inputs": [],
"Outputs": [
{
"Id": "1b7713c8f66d4e38933b4fb97acc7a28",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly",
"Code": "{\"a\":1, \"b\": \"null\", \"c\": null};"
},
{
"ConcreteType": "CoreNodeModels.Watch, CoreNodeModels",
"Id": "daa19ed136b04586ae116470e7c196bd",
"NodeType": "ExtensionNode",
"Inputs": [
{
"Id": "7ce251e0efc946ce85c17be979c34247",
"Name": "",
"Description": "Node to show output from",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "7cbf667c84fa4df3a7d6983d5a2e5825",
"Name": "",
"Description": "Node output",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Visualizes a node's output"
}
],
"Connectors": [
{
"Start": "1b7713c8f66d4e38933b4fb97acc7a28",
"End": "7ce251e0efc946ce85c17be979c34247",
"Id": "b903a06b6a534010862862dc48bd30b8",
"IsHidden": "False"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [],
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "2.18",
"Data": {}
}
],
"Author": "",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.18.0.2986",
"RunType": "Automatic",
"RunPeriod": "1000"
},
"Camera": {
"Name": "_Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"ConnectorPins": [],
"NodeViews": [
{
"Id": "275d5ff387254cfa9ff92fac8f2d0e11",
"Name": "Code Block",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"ShowGeometry": true,
"X": 220.5,
"Y": 325.0
},
{
"Id": "daa19ed136b04586ae116470e7c196bd",
"Name": "Watch",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"ShowGeometry": true,
"X": 656.5,
"Y": 399.0
}
],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}

0 comments on commit 650228d

Please sign in to comment.