Skip to content

Commit

Permalink
added support for namemaps on control properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mizrael committed Oct 3, 2024
1 parent 79d5d46 commit 458c2fe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using Microsoft.PowerPlatform.PowerApps.Persistence;
using Microsoft.PowerPlatform.PowerApps.Persistence.Models;

Check failure on line 5 in src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 5 in src/Persistence.Tests/PaYaml/Serialization/PaYamlSerializerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)
using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models;
using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models.SchemaV3;
using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Serialization;
Expand All @@ -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<PaModule>(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]
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Persistence/PaYaml/Models/SchemaV3/ControlInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ public ControlInstance(string controlType)

public NamedObjectMapping<PFxExpressionYaml>? Properties { get; init; }

public NamedObjectMapping<IDictionary<string, string>>? PropertiesNameMaps { get; init; }

public NamedObjectSequence<ControlInstance>? Children { get; init; }
}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 458c2fe

Please sign in to comment.