Skip to content

Commit

Permalink
Merge pull request Expensify#33012 from waterim/revert-32337-bugfix/i…
Browse files Browse the repository at this point in the history
…ssue-31753

Revert "Show child tags indented on the Tag list"
  • Loading branch information
amyevans authored Dec 15, 2023
2 parents 3b7cd1d + a5d24ac commit 275bd03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 89 deletions.
26 changes: 16 additions & 10 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,15 @@ function sortTags(tags) {
}

/**
* Builds the options for the tree hierarchy via indents
* Builds the options for the category tree hierarchy via indents
*
* @param {Object[]} options - an initial object array
* @param {Boolean} options[].enabled - a flag to enable/disable option in a list
* @param {String} options[].name - a name of an option
* @param {Boolean} [isOneLine] - a flag to determine if text should be one line
* @returns {Array<Object>}
*/
function getIndentedOptionTree(options, isOneLine = false) {
function getCategoryOptionTree(options, isOneLine = false) {
const optionCollection = new Map();

_.each(options, (option) => {
Expand Down Expand Up @@ -826,7 +826,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt
title: '',
shouldShow: false,
indexOffset,
data: getIndentedOptionTree(selectedOptions, true),
data: getCategoryOptionTree(selectedOptions, true),
});

return categorySections;
Expand All @@ -840,7 +840,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt
title: '',
shouldShow: true,
indexOffset,
data: getIndentedOptionTree(searchCategories, true),
data: getCategoryOptionTree(searchCategories, true),
});

return categorySections;
Expand All @@ -852,7 +852,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt
title: '',
shouldShow: false,
indexOffset,
data: getIndentedOptionTree(enabledCategories),
data: getCategoryOptionTree(enabledCategories),
});

return categorySections;
Expand All @@ -864,7 +864,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt
title: '',
shouldShow: true,
indexOffset,
data: getIndentedOptionTree(selectedOptions, true),
data: getCategoryOptionTree(selectedOptions, true),
});

indexOffset += selectedOptions.length;
Expand All @@ -887,7 +887,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt
title: Localize.translateLocal('common.recent'),
shouldShow: true,
indexOffset,
data: getIndentedOptionTree(cutRecentlyUsedCategories, true),
data: getCategoryOptionTree(cutRecentlyUsedCategories, true),
});

indexOffset += filteredRecentlyUsedCategories.length;
Expand All @@ -900,7 +900,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt
title: Localize.translateLocal('common.all'),
shouldShow: true,
indexOffset,
data: getIndentedOptionTree(filteredCategories),
data: getCategoryOptionTree(filteredCategories),
});

return categorySections;
Expand All @@ -915,7 +915,13 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt
* @returns {Array<Object>}
*/
function getTagsOptions(tags) {
return getIndentedOptionTree(tags);
return _.map(tags, (tag) => ({
text: tag.name,
keyForList: tag.name,
searchText: tag.name,
tooltipText: tag.name,
isDisabled: !tag.enabled,
}));
}

/**
Expand Down Expand Up @@ -1758,7 +1764,7 @@ export {
getEnabledCategoriesCount,
hasEnabledOptions,
sortCategories,
getIndentedOptionTree,
getCategoryOptionTree,
formatMemberForList,
formatSectionsFromSearchTerm,
};
82 changes: 3 additions & 79 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1291,65 +1291,6 @@ describe('OptionsListUtils', () => {
},
];

const smallTagsListWithParentChild = {
Movies: {
enabled: true,
name: 'Movies',
},
'Movies: Avengers: Endgame': {
enabled: true,
name: 'Movies: Avengers: Endgame',
unencodedName: 'Movies: Avengers: Endgame',
},
Places: {
enabled: false,
name: 'Places',
},
Task: {
enabled: true,
name: 'Task',
},
};

const smallResultListWithParentChild = [
{
title: '',
shouldShow: false,
indexOffset: 0,
// data sorted alphabetically by name
data: [
{
text: 'Movies',
keyForList: 'Movies',
searchText: 'Movies',
tooltipText: 'Movies',
isDisabled: false,
},
{
text: ' Avengers',
keyForList: 'Movies: Avengers',
searchText: 'Movies: Avengers',
tooltipText: 'Avengers',
isDisabled: true,
},
{
text: ' Endgame',
keyForList: 'Movies: Avengers: Endgame',
searchText: 'Movies: Avengers: Endgame',
tooltipText: 'Endgame',
isDisabled: false,
},
{
text: 'Task',
keyForList: 'Task',
searchText: 'Task',
tooltipText: 'Task',
isDisabled: false,
},
],
},
];

const smallResult = OptionsListUtils.getFilteredOptions(REPORTS, PERSONAL_DETAILS, [], emptySearch, [], [], false, false, false, {}, [], true, smallTagsList);
expect(smallResult.tagOptions).toStrictEqual(smallResultList);

Expand Down Expand Up @@ -1412,26 +1353,9 @@ describe('OptionsListUtils', () => {
recentlyUsedTags,
);
expect(largeWrongSearchResult.tagOptions).toStrictEqual(largeWrongSearchResultList);

const smallResultWithParentChild = OptionsListUtils.getFilteredOptions(
REPORTS,
PERSONAL_DETAILS,
[],
emptySearch,
[],
[],
false,
false,
false,
{},
[],
true,
smallTagsListWithParentChild,
);
expect(smallResultWithParentChild.tagOptions).toStrictEqual(smallResultListWithParentChild);
});

it('getIndentedOptionTree()', () => {
it('getCategoryOptionTree()', () => {
const categories = {
Meals: {
enabled: true,
Expand Down Expand Up @@ -1744,8 +1668,8 @@ describe('OptionsListUtils', () => {
},
];

expect(OptionsListUtils.getIndentedOptionTree(categories)).toStrictEqual(result);
expect(OptionsListUtils.getIndentedOptionTree(categories, true)).toStrictEqual(resultOneLine);
expect(OptionsListUtils.getCategoryOptionTree(categories)).toStrictEqual(result);
expect(OptionsListUtils.getCategoryOptionTree(categories, true)).toStrictEqual(resultOneLine);
});

it('sortCategories', () => {
Expand Down

0 comments on commit 275bd03

Please sign in to comment.