From 458c2fe36f1f00e40cb72e8e1c0356f92b069bdc Mon Sep 17 00:00:00 2001 From: David Guida <1432872+mizrael@users.noreply.github.com> Date: Thu, 3 Oct 2024 09:50:01 -0400 Subject: [PATCH 1/3] added support for namemaps on control properties --- .../Serialization/PaYamlSerializerTests.cs | 33 +++++++++++++++++++ .../PaYaml/Models/SchemaV3/ControlInstance.cs | 2 ++ .../Src/Controls/control-with-namemap.pa.yaml | 11 +++++++ 3 files changed, 46 insertions(+) create mode 100644 src/schemas-tests/pa-yaml/v3.0/Examples/Src/Controls/control-with-namemap.pa.yaml diff --git a/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs b/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs index cb54b176..ae5e86ea 100644 --- a/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs +++ b/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using Microsoft.PowerPlatform.PowerApps.Persistence; +using Microsoft.PowerPlatform.PowerApps.Persistence.Models; using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models; using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models.SchemaV3; using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Serialization; @@ -28,6 +29,37 @@ public void DeserializeNamedObjectSetsLocationInfo() paModule.App.Properties.Should().ContainName("Bar").WhoseNamedObject.Start.Should().Be(new(4, 9)); } + [TestMethod] + public void DeserializeDropDownPropertiesNameMap() + { + var yaml = """ + Screens: + Screen1: + Children: + - DropDown1: + Control: Classic/DropDown + PropertiesNameMaps: + Items: + Value: Title + """; + var paModule = PaYamlSerializer.Deserialize(yaml); + paModule.ShouldNotBeNull(); + paModule.Screens.Should().NotBeNull() + .And.ContainNames("Screen1"); + + var screen = paModule.Screens["Screen1"]; + screen.Children.Should().NotBeNull() + .And.ContainNames("DropDown1"); + + var dropDown = screen.Children!["DropDown1"]; + dropDown.PropertiesNameMaps.Should().NotBeNull() + .And.ContainNames("Items"); + + var itemsNameMap = dropDown.PropertiesNameMaps!["Items"]; + itemsNameMap.Should().ContainKey("Value") + .WhoseValue.Should().Be("Title"); + } + #region Deserialize Examples [TestMethod] @@ -186,6 +218,7 @@ public void DeserializeDuplicateControlNamesShouldFail() [DataRow(@"_TestData/SchemaV3_0/FullSchemaUses/Screens-general-controls.pa.yaml")] [DataRow(@"_TestData/SchemaV3_0/FullSchemaUses/Screens-with-components.pa.yaml")] [DataRow(@"_TestData/SchemaV3_0/Examples/Src/DataSources/Dataversedatasources1.pa.yaml")] + [DataRow(@"_TestData/SchemaV3_0/Examples/Src/Controls/control-with-namemap.pa.yaml")] public void RoundTripFromYaml(string path) { var originalYaml = File.ReadAllText(path); diff --git a/src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs b/src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs index f08da803..9a0bd48e 100644 --- a/src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs +++ b/src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs @@ -37,5 +37,7 @@ public ControlInstance(string controlType) public NamedObjectMapping? Properties { get; init; } + public NamedObjectMapping>? PropertiesNameMaps { get; init; } + public NamedObjectSequence? Children { get; init; } } diff --git a/src/schemas-tests/pa-yaml/v3.0/Examples/Src/Controls/control-with-namemap.pa.yaml b/src/schemas-tests/pa-yaml/v3.0/Examples/Src/Controls/control-with-namemap.pa.yaml new file mode 100644 index 00000000..2ad061d8 --- /dev/null +++ b/src/schemas-tests/pa-yaml/v3.0/Examples/Src/Controls/control-with-namemap.pa.yaml @@ -0,0 +1,11 @@ +Screens: + Screen1: + Children: + - Dropdown1: + Control: Classic/DropDown + Properties: + Items: |- + =[{Id: 1, Title: "Item 1", Desc: "desc1"}, {Id: 2, Title: "Item 2", Desc: "desc2"}, {Id: 3, Title: "Item 3", Desc: "desc3"}] + PropertiesNameMaps: + Items: + Value: Title From 92f986c09dee11a3501a7f260e04f6379dc88db0 Mon Sep 17 00:00:00 2001 From: David Guida <1432872+mizrael@users.noreply.github.com> Date: Thu, 3 Oct 2024 09:55:23 -0400 Subject: [PATCH 2/3] minor fixes --- .../PaYaml/Serialization/PaYamlSerializerTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs b/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs index ae5e86ea..43f8f3e9 100644 --- a/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs +++ b/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using Microsoft.PowerPlatform.PowerApps.Persistence; -using Microsoft.PowerPlatform.PowerApps.Persistence.Models; using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models; using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models.SchemaV3; using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Serialization; From 9afde659e6d4fcd9b77afdb1db6cef45182d5578 Mon Sep 17 00:00:00 2001 From: David Guida <1432872+mizrael@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:48:41 -0400 Subject: [PATCH 3/3] addressing PR comments --- .../Serialization/PaYamlSerializerTests.cs | 31 ------------------- .../PaYaml/Models/SchemaV3/ControlInstance.cs | 2 +- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs b/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs index 43f8f3e9..90748322 100644 --- a/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs +++ b/src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs @@ -28,37 +28,6 @@ public void DeserializeNamedObjectSetsLocationInfo() paModule.App.Properties.Should().ContainName("Bar").WhoseNamedObject.Start.Should().Be(new(4, 9)); } - [TestMethod] - public void DeserializeDropDownPropertiesNameMap() - { - var yaml = """ - Screens: - Screen1: - Children: - - DropDown1: - Control: Classic/DropDown - PropertiesNameMaps: - Items: - Value: Title - """; - var paModule = PaYamlSerializer.Deserialize(yaml); - paModule.ShouldNotBeNull(); - paModule.Screens.Should().NotBeNull() - .And.ContainNames("Screen1"); - - var screen = paModule.Screens["Screen1"]; - screen.Children.Should().NotBeNull() - .And.ContainNames("DropDown1"); - - var dropDown = screen.Children!["DropDown1"]; - dropDown.PropertiesNameMaps.Should().NotBeNull() - .And.ContainNames("Items"); - - var itemsNameMap = dropDown.PropertiesNameMaps!["Items"]; - itemsNameMap.Should().ContainKey("Value") - .WhoseValue.Should().Be("Title"); - } - #region Deserialize Examples [TestMethod] diff --git a/src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs b/src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs index 9a0bd48e..4fb7d57d 100644 --- a/src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs +++ b/src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs @@ -37,7 +37,7 @@ public ControlInstance(string controlType) public NamedObjectMapping? Properties { get; init; } - public NamedObjectMapping>? PropertiesNameMaps { get; init; } + public NamedObjectMapping>? PropertiesNameMaps { get; init; } public NamedObjectSequence? Children { get; init; } }