Skip to content

Commit

Permalink
adding passthrough for custom pages inputs metadata file (#410)
Browse files Browse the repository at this point in the history
* adding passthrough for custom pages inputs metadata file

* adding code for copy from git to msapp

* roundtrip test

* move custom page inputs file into pkgs folder.

* cr issue, move code where pckg folder is populated

* formatting.

* change format of custom pages metadata

* code review issues
  • Loading branch information
milantomic6 committed Jun 14, 2022
1 parent 5913abd commit dae85de
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/PAModel/CanvasDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ public class CanvasDocument
internal Dictionary<string, List<DataSourceEntry>> _dataSources = new Dictionary<string, List<DataSourceEntry>>(StringComparer.Ordinal);
internal List<string> _screenOrder = new List<string>();


internal HeaderJson _header;
internal DocumentPropertiesJson _properties;
internal PublishInfoJson _publishInfo;
internal TemplatesJson _templates;
internal ThemesJson _themes;
internal ResourcesJson _resourcesJson;
internal ParameterSchema _parameterSchema;

// Dictionary with input schemas for custom pages used in the app through Navigate function, key is custom page logical name, value is parameter schema for that page
internal Dictionary<string, ParameterSchema> _customPageInputsMetadata;
internal AppCheckerResultJson _appCheckerResultJson;
internal Dictionary<string, PcfControl> _pcfControls = new Dictionary<string, PcfControl>(StringComparer.OrdinalIgnoreCase);

Expand Down Expand Up @@ -297,6 +299,7 @@ internal CanvasDocument(CanvasDocument other)
_header = other._header.JsonClone();
_properties = other._properties.JsonClone();
_parameterSchema = other._parameterSchema.JsonClone();
_customPageInputsMetadata = other._customPageInputsMetadata.JsonClone();
_publishInfo = other._publishInfo.JsonClone();
_templates = other._templates.JsonClone();
_themes = other._themes.JsonClone();
Expand Down Expand Up @@ -586,14 +589,15 @@ internal void StabilizeAssetFilePaths(ErrorContainer errors)
_assetFiles.Remove(assetFilePath);

// Add or Update the assetFile path entry
if (_assetFiles.ContainsKey(withoutPrefix)) {
if (_assetFiles.ContainsKey(withoutPrefix))
{
_assetFiles.Remove(withoutPrefix);
_assetFiles.Add(withoutPrefix, fileEntry);
}
else
{
_assetFiles.Add(withoutPrefix, fileEntry);
}
}

// For every duplicate asset file an additional <filename>.json file is created which contains information like - originalName, newFileName.
if (resource.Name != originalName && !_localAssetInfoJson.ContainsKey(newFileName))
Expand Down Expand Up @@ -627,7 +631,7 @@ private void RestoreAssetFilePaths()
if (_resourcesJson == null || _assetFiles == null)
return;

var maxFileNumber = FindMaxEntropyFileName();
var maxFileNumber = FindMaxEntropyFileName();

foreach (var resource in _resourcesJson.Resources)
{
Expand Down
8 changes: 7 additions & 1 deletion src/PAModel/Serializers/FileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ enum FileKind
AppTestParentControl,

// Schema.yaml describing app's parameters at top level.
Schema
Schema,

// Custom page inputs for outbound custom page navigate calls.
CustomPageInputs,
}

// Represent a file from disk or a Zip archive.
Expand All @@ -79,6 +82,8 @@ public FileEntry(FileEntry other)
RawBytes = other.RawBytes.ToArray(); // ToArray clones byte arrays
}

public const string CustomPagesMetadataFileName = "CustomPagesMetadata.json";

public static FileEntry FromFile(string fullPath, string root)
{
var relativePath = Utilities.GetRelativePath(root, fullPath);
Expand Down Expand Up @@ -117,6 +122,7 @@ public static FileEntry FromZip(ZipArchiveEntry z, string name = null)
{"Properties.json", FileKind.Properties },
{"Header.json", FileKind.Header},
{"Schema.yaml", FileKind.Schema },
{CustomPagesMetadataFileName, FileKind.CustomPageInputs },
{ChecksumMaker.ChecksumName, FileKind.Checksum },
{"AppCheckerResult.sarif", FileKind.AppCheckerResult },
{"ComponentsMetadata.json", FileKind.ComponentsMetadata },
Expand Down
12 changes: 10 additions & 2 deletions src/PAModel/Serializers/MsAppSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public static CanvasDocument Load(Stream streamToMsapp, ErrorContainer errors)
case FileKind.Schema:
app._parameterSchema = ToObject<ParameterSchema>(entry);
break;
case FileKind.CustomPageInputs:
app._customPageInputsMetadata = ToObject<Dictionary<string, ParameterSchema>>(entry);
break;

case FileKind.Properties:
app._properties = ToObject<DocumentPropertiesJson>(entry);
Expand Down Expand Up @@ -313,7 +316,7 @@ public static CanvasDocument Load(Stream streamToMsapp, ErrorContainer errors)

// Basically making sure conn instance id is not added to app._connections
extensionData.Remove(ConnectionInstanceIDPropertyName);
}
}
}
}

Expand All @@ -337,7 +340,7 @@ public static CanvasDocument Load(Stream streamToMsapp, ErrorContainer errors)
app._properties.LocalDatabaseReferences = null;
}
}

if (!string.IsNullOrEmpty(app._properties.InstrumentationKey))
{
app._appInsights = new AppInsightsKeyJson() { InstrumentationKey = app._properties.InstrumentationKey };
Expand Down Expand Up @@ -605,6 +608,11 @@ private static IEnumerable<FileEntry> GetMsAppFiles(this CanvasDocument app, Err
yield return ToFile(FileKind.Schema, app._parameterSchema);
}

if (app._customPageInputsMetadata != null)
{
yield return ToFile(FileKind.CustomPageInputs, app._customPageInputsMetadata);
}

var (publishInfo, logoFile) = app.TransformLogoOnSave();
yield return logoFile;

Expand Down
18 changes: 18 additions & 0 deletions src/PAModel/Serializers/SourceSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public static CanvasDocument LoadFromSource(string directory2, ErrorContainer er
// Load PowerAppsControl Templates
LoadPcfControlTemplateFiles(errors, app, Path.Combine(directory2, PackagesDir, PcfControlTemplatesDir));

// Load used custom pages schema metadata
LoadCustomPagesSchemaMetadata(errors, app, Path.Combine(directory2, PackagesDir, FileEntry.CustomPagesMetadataFileName));

foreach (var file in dir.EnumerateFiles(EntropyDir))
{
switch (file.Kind)
Expand Down Expand Up @@ -285,6 +288,7 @@ public static CanvasDocument Create(string appName, string packagesPath, IList<s
app._properties = DocumentPropertiesJson.CreateDefault(appName);
app._header = HeaderJson.CreateDefault();
app._parameterSchema = new ParameterSchema();
app._customPageInputsMetadata = new Dictionary<string, ParameterSchema>();

LoadTemplateFiles(errors, app, packagesPath, out var loadedTemplates);
app._entropy = new Entropy();
Expand Down Expand Up @@ -342,6 +346,15 @@ private static void LoadPcfControlTemplateFiles(ErrorContainer errors, CanvasDoc
}
}

private static void LoadCustomPagesSchemaMetadata(ErrorContainer errors, CanvasDocument app, string custompagesMetadataPath)
{
if (File.Exists(custompagesMetadataPath))
{
DirectoryReader.Entry file = new DirectoryReader.Entry(custompagesMetadataPath);
app._customPageInputsMetadata = file.ToObject<Dictionary<string, ParameterSchema>>();
}
}

// The publish info points to the logo file. Grab it from the unknowns.
private static void GetLogoFile(this CanvasDocument app)
{
Expand Down Expand Up @@ -533,6 +546,11 @@ public static void SaveAsSource(CanvasDocument app, string directory2, ErrorCont
dir.WriteAllJson(PackagesDir, new FilePath(PcfControlTemplatesDir, $"{kvp.Value.Name}_{kvp.Value.Version}.json"), kvp.Value);
}

if (app._customPageInputsMetadata != null)
{
dir.WriteAllJson(PackagesDir, FileKind.CustomPageInputs, app._customPageInputsMetadata);
}

// Also add Screen and App templates (not xml, constructed in code on the server)
GlobalTemplates.AddCodeOnlyTemplates(app._templateStore, templateDefaults, app._properties.DocumentAppType);

Expand Down
Binary file not shown.

0 comments on commit dae85de

Please sign in to comment.