diff --git a/src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs b/src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs index 9d4b692b4b4..19f8e2bdbed 100644 --- a/src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs @@ -153,7 +153,6 @@ public bool IsOneRowContent } } - /// /// Number of items in the overall list if node output is a list /// @@ -256,13 +255,17 @@ private Tuple GetMaximumDepthAndItemNumber(WatchViewModel wvm) { return GetMaximumDepthAndItemNumber(wvm.Children[0]); } - else + + // if it's a list, recurse + if (wvm.NodeLabel == LIST) { var depthAndNumbers = wvm.Children.Select(GetMaximumDepthAndItemNumber); var maxDepth = depthAndNumbers.Select(t => t.Item1).DefaultIfEmpty(1).Max() + 1; var itemNumber = depthAndNumbers.Select(t => t.Item2).Sum(); return new Tuple(maxDepth, itemNumber); } + + return new Tuple(1,1); } /// diff --git a/test/DynamoCoreWpfTests/WatchNodeTests.cs b/test/DynamoCoreWpfTests/WatchNodeTests.cs index 5059ade3e3d..f49abdbd314 100644 --- a/test/DynamoCoreWpfTests/WatchNodeTests.cs +++ b/test/DynamoCoreWpfTests/WatchNodeTests.cs @@ -230,5 +230,25 @@ public void WatchFunctionObject_collection_5033() Assert.AreEqual("Function", watchVM.NodeLabel); } + + [Test] + public void WatchNestedDictionary() + { + string openPath = Path.Combine(TestDirectory, @"core\watch\watchNestedDictionaryList.dyn"); + ViewModel.OpenCommand.Execute(openPath); + ViewModel.HomeSpace.Run(); + + var watchNode = ViewModel.Model.CurrentWorkspace.FirstNodeFromWorkspace(); + var watchVM = ViewModel.WatchHandler.GenerateWatchViewModelForData( + watchNode.CachedValue, + ViewModel.Model.EngineController.LiveRunnerRuntimeCore, + watchNode.AstIdentifierForPreview.Name); + + watchVM.CountNumberOfItems(); + watchVM.CountLevels(); + + Assert.AreEqual(3, watchVM.Levels.ElementAt(0)); + Assert.AreEqual(2, watchVM.NumberOfItems); + } } } diff --git a/test/core/watch/watchNestedDictionaryList.dyn b/test/core/watch/watchNestedDictionaryList.dyn new file mode 100644 index 00000000000..79152c51424 --- /dev/null +++ b/test/core/watch/watchNestedDictionaryList.dyn @@ -0,0 +1,76 @@ +{ + "Uuid": "b3971a38-9e42-4229-9ebd-7fa012a6ac9b", + "IsCustomNode": false, + "Description": null, + "Name": "watchNestedDictionaryList", + "ElementResolver": { + "ResolutionMap": { + "DesignScript.Builtin.Dictionary": { + "Key": "DesignScript.Builtin.Dictionary", + "Value": "Builtin.dll" + } + } + }, + "Inputs": [], + "Nodes": [ + { + "ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore", + "NodeType": "CodeBlockNode", + "Code": "[[{\"foo\": [1,2]}, {\"bar\": [1,2,3,4], \"baz\": 1}]];", + "Id": "937132ee84a64220b496e9f7d86f477a", + "Inputs": [], + "Outputs": [ + { + "Id": "65eb03b27fd64885a55e921c23592d61", + "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" + } + ], + "Connectors": [], + "Dependencies": [], + "Bindings": [], + "View": { + "Dynamo": { + "ScaleFactor": 1.0, + "HasRunWithoutCrash": true, + "IsVisibleInDynamoLibrary": true, + "Version": "2.0.0.2821", + "RunType": "Automatic", + "RunPeriod": "1000" + }, + "Camera": { + "Name": "Default Camera", + "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 + }, + "NodeViews": [ + { + "ShowGeometry": true, + "Name": "Code Block", + "Id": "937132ee84a64220b496e9f7d86f477a", + "Excluded": false, + "X": 119.0, + "Y": 213.0 + } + ], + "Annotations": [], + "X": 0.0, + "Y": 0.0, + "Zoom": 1.0 + } +} \ No newline at end of file