Skip to content

Commit af3d577

Browse files
committed
v13 Property compatability
1 parent de4b128 commit af3d577

File tree

9 files changed

+80
-12
lines changed

9 files changed

+80
-12
lines changed

uSync.Backoffice.Management.Client/assets/src/repository/SyncAction.respositoy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class uSyncActionRepository extends UmbControllerBase {
4848
action: action,
4949
options: {
5050
group : group,
51-
force : true,
51+
force : false,
5252
clean : false,
5353
clientId : clientId,
5454
set: 'default'

uSync.Backoffice.Management.Client/assets/src/workspace/views/default/default.element.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,22 @@ export class uSyncDefaultViewElement extends UmbElementMixin(LitElement) {
104104
});
105105
}
106106

107+
_legacyDialogOpened : boolean = false;
108+
107109
async openLegacyModal() {
108110

111+
if (this._legacyDialogOpened) return;
112+
this._legacyDialogOpened = true;
113+
109114
const legacyModal = this.#modalContext?.open(USYNC_LEGACY_MODAL, {
110115
data : this._legacy
111116
});
112117

113-
const data = await legacyModal?.onSubmit();
114-
if (!data) return;
118+
await legacyModal?.onSubmit().then(function(data) {
119+
console.log('data', data);
120+
});
121+
122+
return;
115123
}
116124

117125

uSync.Core/Extensions/DictionaryExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,23 @@ public static IDictionary<TKey, TValue> MergeIgnoreDuplicates<TKey, TValue>(this
9494

9595
return mergedDictionary;
9696
}
97+
98+
public static IDictionary<string, TValue> ConvertToCamelCase<TValue>(this IDictionary<string, TValue> originalDictionary)
99+
=> originalDictionary
100+
.ToDictionary(kvp => kvp.Key.ToCamelCase(), kvp => kvp.Value);
101+
102+
public static string ToCamelCase(this string s)
103+
{
104+
if (string.IsNullOrWhiteSpace(s))
105+
{
106+
return string.Empty;
107+
}
108+
109+
if (s.Length == 1)
110+
{
111+
return s.ToLowerInvariant();
112+
}
113+
114+
return char.ToLowerInvariant(s[0]) + s.Substring(1);
115+
}
97116
}

uSync.Core/Extensions/JsonTextExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
using Umbraco.Extensions;
66

7+
using uSync.Core.Json;
8+
79
namespace uSync.Core.Extensions;
810

911
/// <summary>
@@ -16,13 +18,15 @@ public static class JsonTextExtensions
1618
WriteIndented = true,
1719
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
1820
PropertyNameCaseInsensitive = true,
21+
TypeInfoResolver = new OrderedPropertiesJsonResolver(),
1922
};
2023

2124
private static readonly JsonSerializerOptions _flatOptions = new()
2225
{
2326
WriteIndented = false,
2427
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
2528
PropertyNameCaseInsensitive = true,
29+
TypeInfoResolver = new OrderedPropertiesJsonResolver(),
2630
};
2731

2832
private static JsonNodeOptions _nodeOptions = new()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization.Metadata;
3+
4+
namespace uSync.Core.Json;
5+
6+
/// <summary>
7+
/// ordering of the json properties.
8+
/// </summary>
9+
/// <remarks>
10+
/// <para>
11+
/// we order json properties because it makes for less changes in the physical files
12+
/// </para>
13+
/// <para>
14+
/// less changes in the files = faster comparison checks.
15+
/// </para>
16+
/// </remarks>
17+
internal class OrderedPropertiesJsonResolver : DefaultJsonTypeInfoResolver
18+
{
19+
public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
20+
{
21+
var order = 0;
22+
23+
JsonTypeInfo typeInfo = base.GetTypeInfo(type, options);
24+
if (typeInfo.Kind != JsonTypeInfoKind.Object) return typeInfo;
25+
26+
foreach(var property in typeInfo.Properties.OrderBy(x => x.Name))
27+
{
28+
property.Order = order++;
29+
}
30+
31+
return typeInfo;
32+
}
33+
34+
}

uSync.Core/Serialization/Serializers/DataTypeSerializer.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private List<uSyncChange> DeserializeConfiguration(IDataType item, XElement node
166166
{
167167
var serializer = _configurationSerializers.GetSerializer(item.EditorAlias);
168168

169-
var config = node.Element("Configuration").ValueOrDefault(string.Empty);
169+
var config = node.Element("Config").ValueOrDefault(string.Empty);
170170
if (string.IsNullOrEmpty(config)) return [];
171171

172172
var changes = new List<uSyncChange>();
@@ -177,6 +177,9 @@ private List<uSyncChange> DeserializeConfiguration(IDataType item, XElement node
177177
return changes;
178178
}
179179

180+
// v8,9,etc configs the properties
181+
dictionaryData = dictionaryData.ConvertToCamelCase();
182+
180183
var importData = serializer == null ? dictionaryData : serializer.GetConfigurationImport(dictionaryData);
181184

182185
if (IsJsonEqual(importData, item.ConfigurationData) is false)
@@ -247,8 +250,11 @@ private XElement SerializeConfiguration(IDataType item)
247250

248251
var exportConfig = serializer == null ? merged : serializer.GetConfigurationExport(merged);
249252

250-
var json = exportConfig.SerializeJsonString() ?? string.Empty;
251-
return new XElement("Configuration", new XCData(json));
253+
var json = exportConfig
254+
.OrderBy(x => x.Key)
255+
.ToDictionary()
256+
.SerializeJsonString() ?? string.Empty;
257+
return new XElement("Config", new XCData(json));
252258
}
253259

254260
private static object? TryGetConfigurationObject(IDataType item)

uSync.Core/Serialization/SyncContainerSerializerBase.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public SyncContainerSerializerBase(IEntityService entityService, ILogger<SyncCon
2727
{
2828

2929
TObject? item = FindItem(node);
30-
if (item is null) return Attempt.Succeed(item);
30+
if (item is not null) return Attempt.Succeed(item);
3131

3232
logger.LogDebug("FindOrCreate: Creating");
3333

@@ -82,9 +82,6 @@ public SyncContainerSerializerBase(IEntityService entityService, ILogger<SyncCon
8282
}
8383
}
8484

85-
if (parent is null || treeItem is null)
86-
return Attempt.Fail(item, new KeyNotFoundException("Unable to find parent location for item"));
87-
8885
var itemType = GetItemBaseType(node);
8986
var alias = node.GetAlias();
9087

uSync.Core/Serialization/SyncSerializerRoot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ protected virtual SyncAttempt<TObject> ProcessRename(Guid key, string alias, Ser
218218

219219
public virtual ChangeType IsCurrent(XElement node, SyncSerializerOptions options)
220220
{
221-
XElement current = new("");
221+
XElement? current = default;
222222
var item = FindItem(node);
223223
if (item != null)
224224
{

uSync.Core/Tracking/SyncXmlTracker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public IEnumerable<uSyncChange> GetChanges(XElement target, XElement source, Syn
6565
if (target.IsEmptyItem())
6666
return SyncXmlTracker<TObject>.GetEmptyFileChange(target, source).AsEnumerableOfOne();
6767

68-
if (GetSerializer(target)?.IsValid(target) is true)
68+
if (GetSerializer(target)?.IsValid(target) is false)
6969
return uSyncChange.Error("", "Invalid File", target.Name.LocalName).AsEnumerableOfOne();
7070

7171
var changeType = GetChangeType(target, source, options);

0 commit comments

Comments
 (0)