From a5c38479379edddb367c4a5c9bb5155d354cda63 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Tue, 22 Jun 2021 13:21:16 +0200 Subject: [PATCH] Ensure groups are grouped on name, parent key and type when mapped --- src/Umbraco.Core/Models/PropertyGroup.cs | 34 ++++++++++++++----- .../Models/Mapping/TabsAndPropertiesMapper.cs | 4 +-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Core/Models/PropertyGroup.cs b/src/Umbraco.Core/Models/PropertyGroup.cs index 31351a46ad..6aaee42b18 100644 --- a/src/Umbraco.Core/Models/PropertyGroup.cs +++ b/src/Umbraco.Core/Models/PropertyGroup.cs @@ -9,7 +9,7 @@ using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models { /// - /// A group of property types, which corresponds to the properties grouped under a Tab. + /// Represents a group of property types. /// [Serializable] [DataContract(IsReference = true)] @@ -40,6 +40,9 @@ namespace Umbraco.Core.Models /// /// Gets or sets the parent key of the group. /// + /// + /// The parent key. + /// [DataMember] public Guid? ParentKey { @@ -48,8 +51,11 @@ namespace Umbraco.Core.Models } /// - /// Gets or sets the Sort Order of the Group + /// Gets or sets the type of the group. /// + /// + /// The type. + /// [DataMember] public PropertyGroupType Type { @@ -58,8 +64,11 @@ namespace Umbraco.Core.Models } /// - /// Gets or sets the Name of the Group, which corresponds to the Tab-name in the UI + /// Gets or sets the name of the group. /// + /// + /// The name. + /// [DataMember] public string Name { @@ -70,6 +79,9 @@ namespace Umbraco.Core.Models /// /// Gets or sets the icon of the group. /// + /// + /// The icon. + /// [DataMember] public string Icon { @@ -78,8 +90,11 @@ namespace Umbraco.Core.Models } /// - /// Gets or sets the Sort Order of the Group + /// Gets or sets the sort order of the group. /// + /// + /// The sort order. + /// [DataMember] public int SortOrder { @@ -88,10 +103,13 @@ namespace Umbraco.Core.Models } /// - /// Gets or sets a collection of PropertyTypes for this PropertyGroup + /// Gets or sets a collection of property types for the group. /// + /// + /// The property types. + /// /// - /// Marked DoNotClone because we will manually deal with cloning and the event handlers + /// Marked with DoNotClone, because we will manually deal with cloning and the event handlers. /// [DataMember] [DoNotClone] @@ -117,9 +135,9 @@ namespace Umbraco.Core.Models } } - public bool Equals(PropertyGroup other) => other != null && base.Equals(other) && ParentKey == other.ParentKey && Type == other.Type && Icon == other.Icon && Name.InvariantEquals(other.Name); + public bool Equals(PropertyGroup other) => base.Equals(other) && Name.InvariantEquals(other.Name); - public override int GetHashCode() => (base.GetHashCode(), ParentKey, Type, Icon, Name?.ToLowerInvariant()).GetHashCode(); + public override int GetHashCode() => base.GetHashCode() ^ (Name?.ToLowerInvariant()).GetHashCode(); protected override void PerformDeepClone(object clone) { diff --git a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesMapper.cs b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesMapper.cs index 97467bd06e..0657d505b8 100644 --- a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesMapper.cs @@ -129,9 +129,9 @@ namespace Umbraco.Web.Models.Mapping // need to aggregate the tabs, as content.PropertyGroups contains all the composition tabs, // and there might be duplicates (content does not work like contentType and there is no // content.CompositionPropertyGroups). - var groups = contentType.CompositionPropertyGroups.ToArray(); + var groups = contentType.CompositionPropertyGroups.OrderByHierarchy().ToArray(); var parentKeys = groups.Where(x => x.ParentKey.HasValue).Select(x => x.ParentKey.Value).Distinct().ToArray(); - foreach (var groupsByHierarchy in groups.OrderByHierarchy().GroupBy(x => (x.Name, x.ParentKey))) + foreach (var groupsByHierarchy in groups.GroupBy(x => (x.Name, x.ParentKey, x.Type))) { var properties = new List();