From f2e4760ac4c3086f2dc5cce3ecc2b274d2882b97 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 20 Jan 2024 15:03:47 +0800 Subject: [PATCH] keep selected category at the same position if the list length is below the threshold --- src/libs/OptionsListUtils.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index e86c9daacb42..812f142f4a5a 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -875,32 +875,32 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt return categorySections; } - if (!_.isEmpty(selectedOptions)) { + const selectedOptionNames = _.map(selectedOptions, (selectedOption) => selectedOption.name); + const enabledAndSelectedCategories = _.filter(sortedCategories, (category) => category.enabled || _.includes(selectedOptionNames, 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 = _.map(selectedOptions, (selectedOption) => selectedOption.name); - const filteredCategories = _.filter(enabledCategories, (category) => !_.includes(selectedOptionNames, category.name)); - const numberOfVisibleCategories = selectedOptions.length + filteredCategories.length; - - if (numberOfVisibleCategories < CONST.CATEGORY_LIST_THRESHOLD) { + if (!_.isEmpty(selectedOptions)) { 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 = _.chain(recentlyUsedCategories) @@ -925,6 +925,8 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt indexOffset += filteredRecentlyUsedCategories.length; } + const filteredCategories = _.filter(enabledCategories, (category) => !_.includes(selectedOptionNames, category.name)); + categorySections.push({ // "All" section when items amount more than the threshold title: Localize.translateLocal('common.all'),