From 59b50e4e90615c168572ce297762e23c1030e438 Mon Sep 17 00:00:00 2001 From: rayane-djouah <77965000+rayane-djouah@users.noreply.github.com> Date: Thu, 9 Nov 2023 14:11:54 +0100 Subject: [PATCH 1/3] sort tags alphabetically by name --- src/libs/OptionsListUtils.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 5cd04375ce62..023c52f576e9 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -744,6 +744,21 @@ function sortCategories(categories) { return flatHierarchy(hierarchy); } +/** + * Sorts tags alphabetically by name. + * + * @param {Object} tags + * @returns {Array} + */ +function sortTags(tags) { + const sortedTags = _.chain(tags) + .values() + .sortBy((tag) => tag.name) + .value(); + + return sortedTags; +} + /** * Builds the options for the category tree hierarchy via indents * @@ -934,7 +949,8 @@ function getTagsOptions(tags) { */ function getTagListSections(tags, recentlyUsedTags, selectedOptions, searchInputValue, maxRecentReportsToShow) { const tagSections = []; - const enabledTags = _.filter(tags, (tag) => tag.enabled); + const sortedTags = sortTags(tags); + const enabledTags = _.filter(sortedTags, (tag) => tag.enabled); const numberOfTags = _.size(enabledTags); let indexOffset = 0; @@ -1747,6 +1763,7 @@ export { getEnabledCategoriesCount, hasEnabledOptions, sortCategories, + sortTags, getCategoryOptionTree, formatMemberForList, formatSectionsFromSearchTerm, From ce828d2d46e0388c5c2a91bca61eb5b359cc6280 Mon Sep 17 00:00:00 2001 From: rayane-djouah <77965000+rayane-djouah@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:43:11 +0100 Subject: [PATCH 2/3] fix failing test --- tests/unit/OptionsListUtilsTest.js | 46 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 7f8fae8e3812..dff19baabd3d 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -1077,14 +1077,8 @@ describe('OptionsListUtils', () => { title: '', shouldShow: false, indexOffset: 0, + // data sorted alphabetically by name data: [ - { - text: 'Medical', - keyForList: 'Medical', - searchText: 'Medical', - tooltipText: 'Medical', - isDisabled: false, - }, { text: 'Accounting', keyForList: 'Accounting', @@ -1099,6 +1093,13 @@ describe('OptionsListUtils', () => { tooltipText: 'HR', isDisabled: false, }, + { + text: 'Medical', + keyForList: 'Medical', + searchText: 'Medical', + tooltipText: 'Medical', + isDisabled: false, + }, ], }, ]; @@ -1205,6 +1206,7 @@ describe('OptionsListUtils', () => { title: 'All', shouldShow: true, indexOffset: 2, + // data sorted alphabetically by name data: [ { text: 'Accounting', @@ -1214,10 +1216,17 @@ describe('OptionsListUtils', () => { isDisabled: false, }, { - text: 'HR', - keyForList: 'HR', - searchText: 'HR', - tooltipText: 'HR', + text: 'Benefits', + keyForList: 'Benefits', + searchText: 'Benefits', + tooltipText: 'Benefits', + isDisabled: false, + }, + { + text: 'Cleaning', + keyForList: 'Cleaning', + searchText: 'Cleaning', + tooltipText: 'Cleaning', isDisabled: false, }, { @@ -1228,10 +1237,10 @@ describe('OptionsListUtils', () => { isDisabled: false, }, { - text: 'Cleaning', - keyForList: 'Cleaning', - searchText: 'Cleaning', - tooltipText: 'Cleaning', + text: 'HR', + keyForList: 'HR', + searchText: 'HR', + tooltipText: 'HR', isDisabled: false, }, { @@ -1248,13 +1257,6 @@ describe('OptionsListUtils', () => { tooltipText: 'Taxes', isDisabled: false, }, - { - text: 'Benefits', - keyForList: 'Benefits', - searchText: 'Benefits', - tooltipText: 'Benefits', - isDisabled: false, - }, ], }, ]; From 96c5f71c148dc7dc7b1345dd0730100a287cdba0 Mon Sep 17 00:00:00 2001 From: rayane-djouah <77965000+rayane-djouah@users.noreply.github.com> Date: Wed, 15 Nov 2023 10:38:30 +0100 Subject: [PATCH 3/3] remove sortTags function export --- src/libs/OptionsListUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 023c52f576e9..182eafec447f 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -1763,7 +1763,6 @@ export { getEnabledCategoriesCount, hasEnabledOptions, sortCategories, - sortTags, getCategoryOptionTree, formatMemberForList, formatSectionsFromSearchTerm,