Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@ public void DeserializeNamedObjectSetsLocationInfo()
paModule.App.Properties.Should().ContainName("Bar").WhoseNamedObject.Start.Should().Be(new(4, 9));
}

[TestMethod]
public void DeserializeControlStyles()
{
var paModule = PaYamlSerializer.Deserialize<PaModule>("""
ControlStyles:
PrimaryButton:
Control: Button
Properties:
Fill: =Color.Blue
Emphasis:
Control: Label
Properties:
Color: =Color.Red
""");

paModule.ShouldNotBeNull();
paModule.ControlStyles.ShouldNotBeNull();
paModule.ControlStyles.Should().HaveCount(2);

// Each style is keyed by its (unique) name and targets a single control type.
paModule.ControlStyles["PrimaryButton"].ControlType.Should().Be("Button");
paModule.ControlStyles["PrimaryButton"].Properties.Should().ContainName("Fill");

paModule.ControlStyles["Emphasis"].ControlType.Should().Be("Label");
paModule.ControlStyles["Emphasis"].Properties.Should().ContainName("Color");

// Round-trips back to equivalent YAML.
var roundTrippedYaml = PaYamlSerializer.Serialize(paModule);
roundTrippedYaml.Should().BeYamlEquivalentTo("""
ControlStyles:
PrimaryButton:
Control: Button
Properties:
Fill: =Color.Blue
Emphasis:
Control: Label
Properties:
Color: =Color.Red
""");
}

#region Deserialize Examples

[TestMethod]
Expand Down Expand Up @@ -193,6 +234,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/FullSchemaUses/Themes.pa.yaml")]
[DataRow(@"_TestData/SchemaV3_0/FullSchemaUses/ControlStyles.pa.yaml")]
[DataRow(@"_TestData/SchemaV3_0/Examples/Src/DataSources/Dataversedatasources1.pa.yaml")]
[DataRow(@"_TestData/SchemaV3_0/Examples/Src/_EditorState.pa.yaml")]
public void RoundTripFromYaml(string path)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models.PowerFx;
using YamlDotNet.Serialization;

namespace Microsoft.PowerPlatform.PowerApps.Persistence.PaYaml.Models.SchemaV3;

/// <summary>
/// Represents a reusable control style that can be applied to controls of a specific type.
/// </summary>
/// <remarks>
/// A control style is identified by its name, which is unique within the containing <see cref="PaModule.ControlStyles"/> mapping.
/// Each style applies only to the single target control type specified by <see cref="ControlType"/>.
/// </remarks>
public record ControlStyleDefinition
{
/// <summary>
/// The target control type that this style applies to (e.g. "Button"). Matches <see cref="ControlInstance.ControlType"/>.
/// </summary>
[property: YamlMember(Alias = "Control")]
public required string? ControlType { get; init; }

/// <summary>
/// The set of property formulas defined by this style.
/// </summary>
public NamedObjectMapping<PFxExpressionYaml>? Properties { get; init; }
}
2 changes: 2 additions & 0 deletions src/Persistence/PaYaml/Models/SchemaV3/PaModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public record PaModule
public EditorStateInstance? EditorState { get; init; }

public NamedObjectMapping<ThemeDefinition>? Themes { get; init; }

public NamedObjectMapping<ControlStyleDefinition>? ControlStyles { get; init; }
Comment thread
tehcrashxor marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ControlStyles:
PrimaryButton:
Control: Button
Properties:
Fill: =Color.Blue
Color: =Color.White
BorderThickness: =2

Emphasis:
Control: Label@1.2.3
Properties:
Color: =Color.Red
Bold: =true

SubtleLabel:
Control: Label
Properties:
Color: =Color.Gray
Loading