Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/29901: Selected category should be in the list #32902

Merged
merged 10 commits into from
Jan 3, 2024
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,31 +846,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,
shouldShow: true,
indexOffset,
data: getCategoryOptionTree(enabledCategories),
data: getCategoryOptionTree(selectedOptions, true),
});

return categorySections;
indexOffset += selectedOptions.length;
}

if (!_.isEmpty(selectedOptions)) {
const categoryListThreshold = !_.isEmpty(selectedOptions) ? CONST.CATEGORY_LIST_THRESHOLD - 1 : CONST.CATEGORY_LIST_THRESHOLD;
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
const selectedOptionNames = _.map(selectedOptions, (selectedOption) => selectedOption.name);
const filteredCategories = _.filter(enabledCategories, (category) => !_.includes(selectedOptionNames, category.name));

if (numberOfCategories < categoryListThreshold) {
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 @@ -893,8 +896,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
Loading