From 8a7dc1c3ea98a55e17902bd50cdfb8f674e41c0e Mon Sep 17 00:00:00 2001 From: Artem Makushov <39777589+waterim@users.noreply.github.com> Date: Wed, 13 Dec 2023 21:29:39 +0100 Subject: [PATCH] Revert "Show child tags indented on the Tag list" --- src/libs/OptionsListUtils.js | 26 ++++++---- tests/unit/OptionsListUtilsTest.js | 82 ++---------------------------- 2 files changed, 19 insertions(+), 89 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 95a8c52649d3..71c3a9619f38 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -750,7 +750,7 @@ 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 @@ -758,7 +758,7 @@ function sortTags(tags) { * @param {Boolean} [isOneLine] - a flag to determine if text should be one line * @returns {Array} */ -function getIndentedOptionTree(options, isOneLine = false) { +function getCategoryOptionTree(options, isOneLine = false) { const optionCollection = new Map(); _.each(options, (option) => { @@ -826,7 +826,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt title: '', shouldShow: false, indexOffset, - data: getIndentedOptionTree(selectedOptions, true), + data: getCategoryOptionTree(selectedOptions, true), }); return categorySections; @@ -840,7 +840,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt title: '', shouldShow: true, indexOffset, - data: getIndentedOptionTree(searchCategories, true), + data: getCategoryOptionTree(searchCategories, true), }); return categorySections; @@ -852,7 +852,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt title: '', shouldShow: false, indexOffset, - data: getIndentedOptionTree(enabledCategories), + data: getCategoryOptionTree(enabledCategories), }); return categorySections; @@ -864,7 +864,7 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt title: '', shouldShow: true, indexOffset, - data: getIndentedOptionTree(selectedOptions, true), + data: getCategoryOptionTree(selectedOptions, true), }); indexOffset += selectedOptions.length; @@ -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; @@ -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; @@ -915,7 +915,13 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt * @returns {Array} */ 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, + })); } /** @@ -1758,7 +1764,7 @@ export { getEnabledCategoriesCount, hasEnabledOptions, sortCategories, - getIndentedOptionTree, + getCategoryOptionTree, formatMemberForList, formatSectionsFromSearchTerm, }; diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 45ddf44b244a..999107f0b3ae 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -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); @@ -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, @@ -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', () => {