Fix up so manifestParser can deserialize new property "supportsReadOnly"

This commit is contained in:
Zeegaan
2022-07-05 08:41:55 +02:00
parent a572044f9e
commit a3bcc99ed0
3 changed files with 69 additions and 0 deletions

View File

@@ -79,6 +79,8 @@ public class DataValueEditor : IDataValueEditor
/// </summary>
public virtual object? Configuration { get; set; }
public bool SupportsReadOnly { get; set; }
/// <summary>
/// Gets the validator used to validate the special property type -level "required".
/// </summary>

View File

@@ -110,6 +110,11 @@ internal class DataEditorConverter : JsonReadConverter<IDataEditor>
throw new InvalidOperationException("Missing 'editor' value.");
}
if (jobject.Property("supportsReadOnly") is null)
{
jobject["supportsReadOnly"] = false;
}
// explicitly assign a value editor of type ValueEditor
// (else the deserializer will try to read it before setting it)
// (and besides it's an interface)
@@ -204,6 +209,11 @@ internal class DataEditorConverter : JsonReadConverter<IDataEditor>
jobject.Property("view")?.Remove();
}
if (jobject.Property("supportsReadOnly") is null)
{
jobject["supportsReadOnly"] = false;
}
// in the manifest, default configuration is named 'config', rename
if (jobject["config"] is JObject config)
{

View File

@@ -505,4 +505,61 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2
Assert.IsFalse(manifest.AllowPackageTelemetry);
}
[Test]
public void CanParseManifest_ParameterEditors_SupportsReadOnly()
{
const string json = @"{'parameterEditors': [
{
alias: 'parameter1',
name: 'My Parameter',
view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html',
supportsReadOnly: true
}]}";
var manifest = _parser.ParseManifest(json);
Assert.IsTrue(manifest.ParameterEditors.FirstOrDefault().SupportsReadOnly);
}
[Test]
public void CanParseManifest_PropertyEditors_SupportsReadOnly()
{
const string json = @"{'propertyEditors': [
{
alias: 'Test.Test1',
name: 'Test 1',
supportsReadOnly: true,
editor: {
view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html',
valueType: 'int',
hideLabel: true,
validation: {
'required': true,
'Regex': '\\d*'
}
},
prevalues: {
fields: [
{
label: 'Some config 1',
key: 'key1',
view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val1.html',
validation: {
required: true
}
},
{
label: 'Some config 2',
key: 'key2',
view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val2.html'
}
]
}
}]}";
var manifest = _parser.ParseManifest(json);
Assert.IsTrue(manifest.PropertyEditors.FirstOrDefault().SupportsReadOnly);
}
}