Skip to content

Commit

Permalink
DYN-6633: Define Data node revisions (#15229)
Browse files Browse the repository at this point in the history
  • Loading branch information
twastvedt authored May 23, 2024
1 parent 47297b5 commit 28909dd
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 141 deletions.
46 changes: 17 additions & 29 deletions src/Libraries/CoreNodeModels/DefineData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace CoreNodeModels
[AlsoKnownAs("Data.DefineData")]
public class DefineData : DSDropDownBase
{
private List<DynamoDropDownItem> serializedItems;
private bool isAutoMode = true; // default start with auto-detect 'on'
private bool isList;
private string displayValue = Properties.Resources.DefineDataDisplayValueMessage;
Expand All @@ -48,7 +47,7 @@ public class DefineData : DSDropDownBase
[JsonProperty]
public bool IsAutoMode
{
get { return isAutoMode; }
get => isAutoMode;
set
{
isAutoMode = value;
Expand All @@ -64,7 +63,7 @@ public bool IsAutoMode
[JsonProperty]
public bool IsList
{
get { return isList; }
get => isList;
set
{
isList = value;
Expand All @@ -79,8 +78,8 @@ public bool IsList
///
[JsonProperty]
public string DisplayValue
{
get { return displayValue; }
{
get => displayValue;
set
{
if (displayValue != value)
Expand All @@ -93,10 +92,7 @@ public string DisplayValue


[JsonIgnore]
public override bool IsInputNode
{
get { return true; }
}
public override bool IsInputNode => true;


private string value = "";
Expand Down Expand Up @@ -146,7 +142,6 @@ private DefineData(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPor

private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{

}

protected override void OnBuilt()
Expand All @@ -170,7 +165,7 @@ public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode
// the object to be (type) evaluated
// the expected datatype
// if the input is an ArrayList or not
var function = new Func<object, string, bool, bool, string, Dictionary<string, object>>(DSCore.Data.IsSupportedDataNodeType);
var function = new Func<object, string, bool, bool, string, Dictionary<string, object>>(EvaluateDefineDataNode);
var functionInputs = new List<AssociativeNode> {
inputAstNodes[0],
AstFactory.BuildStringNode((Items[SelectedIndex].Item as Data.DataNodeDynamoType).Type.ToString()),
Expand All @@ -196,25 +191,24 @@ public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode
[functionCallIdentifier, AstFactory.BuildStringNode("Validation")]);

resultAst.Add(AstFactory.BuildAssignment(
AstFactory.BuildIdentifier(GUID + "_db"),
DataBridge.GenerateBridgeDataAst(GUID.ToString(), getSecondKey)));
AstFactory.BuildIdentifier(GUID + "_db"),
DataBridge.GenerateBridgeDataAst(GUID.ToString(), getSecondKey)));

return resultAst;
}


private void DataBridgeCallback(object data)
{
//Todo If the playerValue is not empty string then we can chanage the UI to reflect the value is coming from the player
//Todo If the playerValue is not empty string then we can change the UI to reflect the value is coming from the player
//Todo if the function call throws we don't get back to DatabridgeCallback. Not sure if we need to handle this case

//Now we reset this value to empty string so that the next time a value is set from upstream nodes we can know that it is not coming from the player
value = "";

// If data is null
if (data == null)
{
if(IsAutoMode)
if (IsAutoMode)
{
DisplayValue = string.Empty; // show blank if we are in locked mode (as we cannot interact with the node)
}
Expand All @@ -226,26 +220,26 @@ private void DataBridgeCallback(object data)
}

// If data is not null
(bool IsValid, bool UpdateList, DataNodeDynamoType InputType) resultData = (ValueTuple<bool, bool, DataNodeDynamoType>)data;
(bool IsValid, bool UpdateList, DataNodeDynamoType InputType) = (ValueTuple<bool, bool, DataNodeDynamoType>)data;

if (IsAutoMode)
{
if (resultData.UpdateList)
if (UpdateList)
{
IsList = !IsList;
}

if (resultData.InputType != null)
if (InputType != null)
{
if (!resultData.IsValid)
if (!IsValid)
{
// Assign to the correct value, if the object was of supported type
var index = Items.IndexOf(Items.First(i => i.Name.Equals(resultData.InputType.Name)));
var index = Items.IndexOf(Items.First(i => i.Name.Equals(InputType.Name)));
SelectedIndex = index;
}
if (!DisplayValue.Equals(resultData.InputType.Name))
if (!DisplayValue.Equals(InputType.Name))
{
DisplayValue = resultData.InputType.Name;
DisplayValue = InputType.Name;
}
}
}
Expand Down Expand Up @@ -273,12 +267,6 @@ protected override SelectionState PopulateItemsCore(string currentSelection)
return SelectionState.Restore;
}

[OnSerializing]
private void OnSerializing(StreamingContext context)
{
serializedItems = Items.ToList();
}

protected override bool UpdateValueCore(UpdateValueParams updateValueParams)
{
string name = updateValueParams.PropertyName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace CoreNodeModelsWpf.Nodes
/// <summary>
/// View customizer for DefineData node model.
/// </summary>
public class DefineDataNodeViewCustomization : DropDownNodeViewCustomization, INodeViewCustomization<DefineData>
internal class DefineDataNodeViewCustomization : DropDownNodeViewCustomization, INodeViewCustomization<DefineData>
{
private ComboBox dropdown;
private ToggleButton modeToggleButton;
Expand Down
Loading

0 comments on commit 28909dd

Please sign in to comment.