sets sortOrder on the converted tab based on the exiting tabs
This commit is contained in:
@@ -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;
|
||||
},
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user