Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dyn 5008 watch node height 4 dictionary #12989

Merged
merged 3 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/DynamoCoreWpf/Views/Preview/WatchTree.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public WatchTree()
internal double ExtratWidthSize { get { return extraWidthSize; } }
internal double WidthPerCharacter { get { return widthPerCharacter; } }
internal double MaxWidthSize { get { return defaultWidthSize * 2; } }
internal string NodeLabel { get { return _vm.Children[0].NodeLabel; } }

private void WatchTree_Unloaded(object sender, RoutedEventArgs e)
{
Expand All @@ -59,7 +60,7 @@ private void _vm_PropertyChanged(object sender, System.ComponentModel.PropertyCh
this.Height = minHeightSize;
if (_vm.Children.Count !=0)
{
if (_vm.Children[0].NodeLabel.Contains(Environment.NewLine))
if (_vm.Children[0].NodeLabel.Contains(Environment.NewLine) || _vm.Children[0].NodeLabel.ToUpper() == nameof(WatchViewModel.DICTIONARY))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could Children[0] ever be null?

Copy link
Contributor

@reddyashish reddyashish Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If just a null value is passed to the watch node, i think the watch node doesn't consider it a child and children could be zero. Can you verify?

Copy link
Contributor Author

@jesusalvino jesusalvino Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could Children[0] ever be null?

After a lot of debugging at least in the more common scenarios of the WatchNode, In this section of the code when we are dealing with the Iscollection property, no.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If just a null value is passed to the watch node, i think the watch node doesn't consider it a child and children could be zero. Can you verify?

The only way that I found to assign a null value to the WatchNode is being explicit from a Code Block. Per my understanding all the data types that a WatchNode receives always is handled in the first Child[0].

WatchNode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QilongTang reddyashish Please your thoughts/worries, Maybe I'm missing something like others scenarios, complex data types or whatever, It will be nice to test it in order to be on the same page and prevent Dynamo crashes or unexpected behaviors.

Copy link
Contributor

@reddyashish reddyashish Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be hard to tell accurately considering all cases. To be on the safe side, you can just add a additional check before that like:
if(_vm.Children.Count > 0 && ....)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be hard to tell accurately considering all cases. To be on the safe side, you can just add a additional check before that like: if(_vm.Children.Count > 0 && ....)

What do you think about the highlighted line ?
imagen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I did not see that. Looks good to be merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 63, you can just use the variable NodeLabel you created instead of _vm.Children[0].NodeLabel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
this.Height = defaultHeightSize;
}
Expand Down
26 changes: 26 additions & 0 deletions test/DynamoCoreWpfTests/PreviewBubbleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,32 @@ public void Watch_MultilineString()
Assert.AreEqual(rawMultiLineStringtWatchNode.DefaultHeightSize, rawMultiLineStringtWatchNode.Height);
}

[Test]
public void Watch_Dictionary()
{
OpenAndRun(@"core\WatchTree.dyn");

string watchNodeGuid = "a3b57ebd-5fff-413d-a6c5-ecee20e80e4e";
var dictionaryWatchNode = NodeViewWithGuid(watchNodeGuid);
WatchTree rawDictionaryWatchNode = dictionaryWatchNode.ChildOfType<WatchTree>();

bool isDictionary = rawDictionaryWatchNode.NodeLabel.ToUpper() == nameof(Dynamo.ViewModels.WatchViewModel.DICTIONARY);

// Fire transition on dynamo main ui thread.
View.Dispatcher.Invoke(() =>
{
dictionaryWatchNode.PreviewControl.BindToDataSource();
dictionaryWatchNode.PreviewControl.TransitionToState(Dynamo.UI.Controls.PreviewControl.State.Condensed);
dictionaryWatchNode.PreviewControl.TransitionToState(Dynamo.UI.Controls.PreviewControl.State.Expanded);
});

DispatcherUtil.DoEvents();

Assert.NotNull(dictionaryWatchNode);
Assert.IsTrue(isDictionary);
Assert.AreEqual(rawDictionaryWatchNode.DefaultHeightSize, rawDictionaryWatchNode.Height);
}

#endregion

[Test]
Expand Down
81 changes: 80 additions & 1 deletion test/core/WatchTree.dyn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"Point": {
"Key": "Autodesk.DesignScript.Geometry.Point",
"Value": "ProtoGeometry.dll"
},
"DesignScript.Builtin.Dictionary": {
"Key": "DesignScript.Builtin.Dictionary",
"Value": "DesignScriptBuiltin.dll"
}
}
},
Expand Down Expand Up @@ -309,6 +313,55 @@
],
"Replication": "Disabled",
"Description": "Visualize the node's output"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "{\"id\":7888,\"uid\":\"095a8563-6b2f-4961-b5d0-51d224508ff7\",\"brand\":\"Budweiser\",\"name\":\"Westmalle Trappist Tripel\",\"style\":\"Stout\",\"hop\":\"Willamette\",\"yeast\":\"1099 - Whitbread Ale\",\"malts\":\"Vienna\",\"ibu\":\"45 IBU\",\"alcohol\":\"9.6%\",\"blg\":\"11.7°Blg\"};",
"Id": "4dbf32f1be71457a8a207d659896d274",
"Inputs": [],
"Outputs": [
{
"Id": "97450167f6e844f38de8e1204b9cf543",
"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"
},
{
"ConcreteType": "CoreNodeModels.Watch, CoreNodeModels",
"NodeType": "ExtensionNode",
"Id": "a3b57ebd5fff413da6c5ecee20e80e4e",
"Inputs": [
{
"Id": "9bc1396dc4e642e787f1c273ad7e1c1f",
"Name": "",
"Description": "Node to show output from",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "bc02de04f1fc41f485188d443b311d5d",
"Name": "",
"Description": "Node output",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Visualize the node's output"
}
],
"Connectors": [
Expand Down Expand Up @@ -341,6 +394,12 @@
"End": "79a2a477a7144cf4aa1888f35080c103",
"Id": "a8636b0b2b1e4c9ba0088c5de773290b",
"IsHidden": "False"
},
{
"Start": "97450167f6e844f38de8e1204b9cf543",
"End": "9bc1396dc4e642e787f1c273ad7e1c1f",
"Id": "9850c23ac51f46849692bb191274a853",
"IsHidden": "False"
}
],
"Dependencies": [],
Expand Down Expand Up @@ -368,7 +427,7 @@
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.15.0.5047",
"Version": "2.15.0.5252",
"RunType": "Automatic",
"RunPeriod": "1000"
},
Expand Down Expand Up @@ -495,6 +554,26 @@
"Excluded": false,
"X": 841.30826466519318,
"Y": 973.22971481997047
},
{
"Name": "Code Block",
"ShowGeometry": true,
"Id": "4dbf32f1be71457a8a207d659896d274",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 1053.2918870047356,
"Y": 261.47013517660719
},
{
"Name": "Watch",
"ShowGeometry": true,
"Id": "a3b57ebd5fff413da6c5ecee20e80e4e",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 1516.5673530447943,
"Y": 417.29915557189958
}
],
"Annotations": [],
Expand Down