Skip to content

Commit

Permalink
Fix #643, don't clean up inherited tabs.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed May 28, 2024
1 parent 0b37355 commit 983f455
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions uSync.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,31 +863,29 @@ protected IEnumerable<uSyncChange> DeserializeTabs(TObject item, XElement node)
if (TabClashesWithExisting(item, tab.Alias, tab.Type))
tab.Alias = SyncPropertyGroupHelpers.GetTempTabAlias(tab.Alias);

logger.LogInformation("Explicit Tabs : {list}", string.Join(",", item.PropertyGroups.Select(x => x.Alias)));
logger.LogInformation("Inherited Tabs : {list}", string.Join(",", item.CompositionPropertyGroups.Select(x => x.Alias)));

// v14: if the tab is a child (group) - then we might need to create a parent tab
if (tab.Depth > 0)
{
var tabRoot = tab.Alias.Split('/')[0];
if (item.PropertyGroups.Contains(tabRoot))
{
logger.LogDebug("Parent Tab {tabRoot} already exists", tabRoot);
logger.LogInformation("Parent Tab {tabRoot} already exists", tabRoot);
}
else
{
logger.LogDebug("Parent Tab {tabRoot} doesn't exist, creating", tabRoot);
logger.LogInformation("Parent Tab {tabRoot} doesn't exist, creating", tabRoot);

var compositionParent = item.CompositionPropertyGroups.FirstOrDefault(x => x.Alias.InvariantEquals(tabRoot));
if (compositionParent != null)
{
logger.LogDebug("Creating parent tab from inherited tab data, {alias} {name}", compositionParent.Alias, compositionParent.Name ?? compositionParent.Alias);
var parentPropertyGroup = new PropertyGroup(supportsPublishing)
{
Alias = tabRoot,
Name = compositionParent.Name ?? tabRoot,
Type = compositionParent.Type,
SortOrder = compositionParent.SortOrder,
};

item.PropertyGroups.Add(parentPropertyGroup);
logger.LogInformation("Creating parent tab from inherited tab data, {alias} {name}", compositionParent.Alias, compositionParent.Name ?? compositionParent.Alias);

item.AddPropertyGroup(tabRoot, compositionParent.Name ?? tabRoot);
item.PropertyGroups[tabRoot].Type = compositionParent.Type;
item.PropertyGroups[tabRoot].SortOrder = compositionParent.SortOrder;
}
}
}
Expand Down Expand Up @@ -989,9 +987,14 @@ protected IEnumerable<uSyncChange> CleanTabs(TObject item, XElement node, SyncSe
.Select(x => GetTabAliasFromTabGroup(x))
.ToList();

var inheritedTabs =item.CompositionPropertyGroups.Select(x => x.Alias).ToList();

List<PropertyGroup> removals = [];
foreach (var tab in item.PropertyGroups)
{
// don't remove the inherited tabs
if (inheritedTabs.Contains(tab.Alias)) continue;

if (!newTabs.InvariantContains(tab.Alias))
{
removals.Add(tab);
Expand All @@ -1011,7 +1014,7 @@ protected IEnumerable<uSyncChange> CleanTabs(TObject item, XElement node, SyncSe
}
else
{
logger.LogDebug("Removing tab : {alias}", tab.Alias);
logger.LogInformation("Removing tab : {alias}", tab.Alias);
changes.Add(uSyncChange.Delete($"Tabs/{tab.Alias}", tab.Alias, tab.Alias));
item.PropertyGroups.Remove(tab);
}
Expand Down

0 comments on commit 983f455

Please sign in to comment.