Skip to content

Commit

Permalink
Merge pull request #32902 from DylanDylann/fix/29901
Browse files Browse the repository at this point in the history
Fix/29901: Selected category should be in the list
  • Loading branch information
yuwenmemon authored Jan 3, 2024
2 parents 3b385ef + 19891e1 commit 339987b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,31 +854,34 @@ function getCategoryListSections(categories, recentlyUsedCategories, selectedOpt
return categorySections;
}

if (numberOfCategories < 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(enabledCategories),
data: getCategoryOptionTree(selectedOptions, true),
});

return categorySections;
indexOffset += selectedOptions.length;
}

if (!_.isEmpty(selectedOptions)) {
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) {
categorySections.push({
// "Selected" section
// "All" section when items amount less than the threshold
title: '',
shouldShow: true,
shouldShow: false,
indexOffset,
data: getCategoryOptionTree(selectedOptions, true),
data: getCategoryOptionTree(filteredCategories),
});

indexOffset += selectedOptions.length;
return categorySections;
}

const selectedOptionNames = _.map(selectedOptions, (selectedOption) => selectedOption.name);
const filteredRecentlyUsedCategories = _.chain(recentlyUsedCategories)
.filter((categoryName) => !_.includes(selectedOptionNames, categoryName) && lodashGet(categories, [categoryName, 'enabled'], false))
.map((categoryName) => ({
Expand All @@ -901,8 +904,6 @@ 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'),
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ describe('OptionsListUtils', () => {
const largeResultList = [
{
title: '',
shouldShow: true,
shouldShow: false,
indexOffset: 0,
data: [
{
Expand Down

0 comments on commit 339987b

Please sign in to comment.