Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show child tags indented on the Tag list #32337

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,15 +747,15 @@ function sortTags(tags) {
}

/**
* Builds the options for the category tree hierarchy via indents
* Builds the options for the 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
Copy link
Contributor

@c3024 c3024 Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the function description to a more generic description instead of one specifically for category to something like
"Builds the options for the tree hierarchy via indents"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @c3024 sorry I forgot to change this description.

Done: 3f5b02487

* @returns {Array<Object>}
*/
function getCategoryOptionTree(options, isOneLine = false) {
function getIndentedOptionTree(options, isOneLine = false) {
const optionCollection = new Map();

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

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

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

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

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

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

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

/**
Expand Down Expand Up @@ -1756,7 +1750,7 @@ export {
getEnabledCategoriesCount,
hasEnabledOptions,
sortCategories,
getCategoryOptionTree,
getIndentedOptionTree,
formatMemberForList,
formatSectionsFromSearchTerm,
};
82 changes: 79 additions & 3 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,65 @@ 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 @@ -1354,9 +1413,26 @@ 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('getCategoryOptionTree()', () => {
it('getIndentedOptionTree()', () => {
const categories = {
Meals: {
enabled: true,
Expand Down Expand Up @@ -1669,8 +1745,8 @@ describe('OptionsListUtils', () => {
},
];

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

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