From f51e59492975ba2194bbfb6303ebaf55ffe442f7 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 7 Sep 2021 14:45:44 +0200 Subject: [PATCH] sets sortOrder on the converted tab based on the exiting tabs --- .../services/contenttypehelper.service.js | 5 ++- .../services/content-type-helper.spec.js | 35 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/contenttypehelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/contenttypehelper.service.js index e8c67e0f6e..d9157093a7 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/contenttypehelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/contenttypehelper.service.js @@ -90,6 +90,9 @@ function contentTypeHelper(contentTypeResource, dataTypeResource, $filter, $inje }, convertGroupToTab: function (groups, group) { + const tabs = groups.filter(group => group.type === this.TYPE_TAB).sort((a, b) => a.sortOrder - b.sortOrder); + const nextSortOrder = tabs && tabs.length > 0 ? tabs[tabs.length - 1].sortOrder + 1 : 0; + group.convertingToTab = true; group.type = this.TYPE_TAB; @@ -100,7 +103,7 @@ function contentTypeHelper(contentTypeResource, dataTypeResource, $filter, $inje group.alias = this.isAliasUnique(otherGroups, newAlias) ? newAlias : this.createUniqueAlias(otherGroups, newAlias); group.parentAlias = null; - + group.sortOrder = nextSortOrder; group.convertingToTab = false; }, diff --git a/src/Umbraco.Web.UI.Client/test/unit/common/services/content-type-helper.spec.js b/src/Umbraco.Web.UI.Client/test/unit/common/services/content-type-helper.spec.js index 5add5a4129..88b6d828af 100644 --- a/src/Umbraco.Web.UI.Client/test/unit/common/services/content-type-helper.spec.js +++ b/src/Umbraco.Web.UI.Client/test/unit/common/services/content-type-helper.spec.js @@ -173,13 +173,13 @@ describe('contentTypeHelper tests', function () { describe('convertGroupToTab', function () { - const groups = [ - { type: 0, alias: 'hero', name: 'Hero' }, - { type: 0, alias: 'content' }, - { type: 0, alias: 'footer' } - ]; - it('should convert group to tab', function () { + const groups = [ + { type: 0, alias: 'hero', name: 'Hero' }, + { type: 0, alias: 'content' }, + { type: 0, alias: 'footer' } + ]; + const newTab = groups[0]; contentTypeHelper.convertGroupToTab(groups, newTab); @@ -189,6 +189,29 @@ describe('contentTypeHelper tests', function () { expect(newTab.parentAlias).toBeNull(); }); + it('should set sort order to 0 if it is the first tab', function () { + const groups = [ + { type: 0, alias: 'hero', name: 'Hero' } + ]; + + const newTab = groups[0]; + contentTypeHelper.convertGroupToTab(groups, newTab); + + expect(newTab.sortOrder).toBe(0); + }); + + it('should set sort order to 1 higher than the last tab', function () { + const groups = [ + { type: 0, alias: 'settings', name: 'Settings', sortOrder: 100 }, + { type: 1, alias: 'content', name: 'Content', sortOrder: 5 } + ]; + + const newTab = groups[0]; + contentTypeHelper.convertGroupToTab(groups, newTab); + + expect(newTab.sortOrder).toBe(6); + }); + }); });