Skip to content

Commit

Permalink
Merge pull request #34848 from bernhardoj/fix/34018-categories-list-p…
Browse files Browse the repository at this point in the history
…osition

Keep selected category at the same position if the list length is < 8
  • Loading branch information
youssef-lr authored Jan 29, 2024
2 parents 1c19c54 + afe01cf commit 533b870
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -944,32 +944,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
Expand All @@ -993,6 +993,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'),
Expand Down

0 comments on commit 533b870

Please sign in to comment.