Skip to content

Commit

Permalink
Handling Control instances with same control template but different f…
Browse files Browse the repository at this point in the history
…ield values (#451)
  • Loading branch information
NavneetThekkumpat authored Dec 5, 2022
1 parent b5d3554 commit 37fdac2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/PAModel/Entropy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ internal class PropertyEntropy
// Key is test rule, value is test screen id without Screen name
public Dictionary<string, string> RuleScreenIdWithoutScreen { get; set; } = new Dictionary<string, string>(StringComparer.Ordinal);

// Key is control name, value is OverridableProperties
public Dictionary<string, object> OverridablePropertiesEntry { get; set; } = new Dictionary<string, object>(StringComparer.Ordinal);

// Key is control name, value is PCFDynamicSchemaForIRRetrieval
public Dictionary<string, object> PCFDynamicSchemaForIRRetrievalEntry { get; set; } = new Dictionary<string, object>(StringComparer.Ordinal);

public int GetOrder(DataSourceEntry dataSource)
{
// To ensure that that TableDefinitions are put at the end in DataSources.json when the order information is not available.
Expand Down
29 changes: 28 additions & 1 deletion src/PAModel/IR/IRStateHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace Microsoft.PowerPlatform.Formulas.Tools
{
internal static class IRStateHelpers
{
public const string ControlTemplateOverridableProperties = "OverridableProperties";
public const string ControlTemplatePCFDynamicSchemaForIRRetrieval = "PCFDynamicSchemaForIRRetrieval";

internal static void SplitIRAndState(SourceFile file, EditorStateStore stateStore, TemplateStore templateStore, Entropy entropy, out BlockNode topParentIR)
{
var topParentJson = file.Value.TopParent;
Expand Down Expand Up @@ -179,6 +182,19 @@ private static void SplitIRAndState(ControlInfoJson.Item control, string topPare
Functions = functions,
};

// Storing Template PCFDynamicSchemaForIRRetrieval/OverridableProperties field values for each control instance.
// Since this value could be different for each control instance though it follows same control template.
// Eg:Control Instance 1 -> template1 -> PCFDynamicSchemaForIRRetrieval1/OverridableProperties1
// Control Instance 2 -> template1 -> PCFDynamicSchemaForIRRetrieval2/OverridableProperties2

if (control.Template.ExtensionData.TryGetValue(ControlTemplatePCFDynamicSchemaForIRRetrieval, out object PCFVal))
{
entropy.PCFDynamicSchemaForIRRetrievalEntry.Add(control.Name, PCFVal);
}
if (control.Template.ExtensionData.TryGetValue(ControlTemplateOverridableProperties, out object OverridablePropVal))
{
entropy.OverridablePropertiesEntry.Add(control.Name, OverridablePropVal);
}

if (templateStore.TryGetTemplate(control.Template.Name, out var templateState))
{
Expand Down Expand Up @@ -423,9 +439,20 @@ private static (ControlInfoJson.Item item, int index) CombineIRAndState(BlockNod
resultControlInfo.HasDynamicProperties = hasDynamicProperties;
resultControlInfo.AllowAccessToGlobals = templateState?.ComponentManifest?.AllowAccessToGlobals;
}
resultControlInfo.Template = template;
resultControlInfo.Template = template.JsonClone();
resultControlInfo.Children = orderedChildren;

// Using the stored PCFDynamicSchemaForIRRetrieval/OverridableProperties value for each control instance,
// instead of the default value from the control template.
if (entropy.OverridablePropertiesEntry.TryGetValue(controlName, out object OverridablePropVal))
{
resultControlInfo.Template.ExtensionData[ControlTemplateOverridableProperties] = OverridablePropVal;
}
if (entropy.PCFDynamicSchemaForIRRetrievalEntry.TryGetValue(controlName, out object PCFVal))
{
resultControlInfo.Template.ExtensionData[ControlTemplatePCFDynamicSchemaForIRRetrieval] = PCFVal;
}

return (resultControlInfo, state?.ParentIndex ?? -1);
}

Expand Down
Binary file not shown.
16 changes: 16 additions & 0 deletions src/PAModelTests/EntropyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,21 @@ public void TestControlIdIntParsing(string filename)
Assert.IsTrue(msapp._entropy.ControlUniqueIds.Count > 0);
Assert.AreEqual(msapp._entropy.ControlUniqueGuids.Count, 0);
}

// Validate that the control template fields OverridaleProperties and PCFDynamicSchemaForIRRetrieval are stored in entropy while unpacking
// The test app contains control instances with same template but different fields
[DataTestMethod]
[DataRow("ControlInstancesWithDifferentTemplateFields.msapp")]
public void TestControlInstancesWithSameTemplateDifferentFields(string appName)
{
var root = Path.Combine(Environment.CurrentDirectory, "Apps", appName);
Assert.IsTrue(File.Exists(root));

(var msapp, var errors) = CanvasDocument.LoadFromMsapp(root);
errors.ThrowOnErrors();

Assert.IsNotNull(msapp._entropy.OverridablePropertiesEntry);
Assert.IsNotNull(msapp._entropy.PCFDynamicSchemaForIRRetrievalEntry);
}
}
}

0 comments on commit 37fdac2

Please sign in to comment.