Skip to content

Commit

Permalink
Merge pull request #31129 from rayane-djouah/fix-Tags-under-"All"-sec…
Browse files Browse the repository at this point in the history
…tion-displayed-not-in-alphabetic-order

Fix: Tags under "All" section displayed not in alphabetic order
  • Loading branch information
MariaHCD authored Nov 17, 2023
2 parents 942a64e + 96c5f71 commit 222993c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
18 changes: 17 additions & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,21 @@ function sortCategories(categories) {
return flatHierarchy(hierarchy);
}

/**
* Sorts tags alphabetically by name.
*
* @param {Object<String, {name: String, enabled: Boolean}>} tags
* @returns {Array<Object>}
*/
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
*
Expand Down Expand Up @@ -919,7 +934,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;

Expand Down
46 changes: 24 additions & 22 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -1099,6 +1093,13 @@ describe('OptionsListUtils', () => {
tooltipText: 'HR',
isDisabled: false,
},
{
text: 'Medical',
keyForList: 'Medical',
searchText: 'Medical',
tooltipText: 'Medical',
isDisabled: false,
},
],
},
];
Expand Down Expand Up @@ -1205,6 +1206,7 @@ describe('OptionsListUtils', () => {
title: 'All',
shouldShow: true,
indexOffset: 2,
// data sorted alphabetically by name
data: [
{
text: 'Accounting',
Expand All @@ -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,
},
{
Expand All @@ -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,
},
{
Expand All @@ -1248,13 +1257,6 @@ describe('OptionsListUtils', () => {
tooltipText: 'Taxes',
isDisabled: false,
},
{
text: 'Benefits',
keyForList: 'Benefits',
searchText: 'Benefits',
tooltipText: 'Benefits',
isDisabled: false,
},
],
},
];
Expand Down

0 comments on commit 222993c

Please sign in to comment.