diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 2621e4d7f12b..cfd2f0214d0d 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -943,32 +943,32 @@ function getCategoryListSections( return categorySections; } - if (selectedOptions.length > 0) { + const selectedOptionNames = selectedOptions.map((selectedOption) => selectedOption.name); + const enabledAndSelectedCategories = sortedCategories.filter((category) => category.enabled || selectedOptionNames.includes(category.name)); + const numberOfVisibleCategories = enabledAndSelectedCategories.length; + + if (numberOfVisibleCategories < CONST.CATEGORY_LIST_THRESHOLD) { categorySections.push({ - // "Selected" section + // "All" section when items amount less than the threshold title: '', shouldShow: false, indexOffset, - data: getCategoryOptionTree(selectedOptions, true), + data: getCategoryOptionTree(enabledAndSelectedCategories), }); - indexOffset += selectedOptions.length; + return categorySections; } - const selectedOptionNames = selectedOptions.map((selectedOption) => selectedOption.name); - const filteredCategories = enabledCategories.filter((category) => !selectedOptionNames.includes(category.name)); - const numberOfVisibleCategories = selectedOptions.length + filteredCategories.length; - - if (numberOfVisibleCategories < CONST.CATEGORY_LIST_THRESHOLD) { + if (selectedOptions.length > 0) { categorySections.push({ - // "All" section when items amount less than the threshold + // "Selected" section title: '', shouldShow: false, indexOffset, - data: getCategoryOptionTree(filteredCategories), + data: getCategoryOptionTree(selectedOptions, true), }); - return categorySections; + indexOffset += selectedOptions.length; } const filteredRecentlyUsedCategories = recentlyUsedCategories @@ -992,6 +992,8 @@ function getCategoryListSections( indexOffset += filteredRecentlyUsedCategories.length; } + const filteredCategories = enabledCategories.filter((category) => !selectedOptionNames.includes(category.name)); + categorySections.push({ // "All" section when items amount more than the threshold title: Localize.translateLocal('common.all'),