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 selected parent category is not displayed as selected #37805

Merged
Changes from all 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
6 changes: 3 additions & 3 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ function sortTags(tags: Record<string, Tag> | Tag[]) {
* @param options[].name - a name of an option
* @param [isOneLine] - a flag to determine if text should be one line
*/
function getCategoryOptionTree(options: Record<string, Category> | Category[], isOneLine = false): OptionTree[] {
function getCategoryOptionTree(options: Record<string, Category> | Category[], isOneLine = false, selectedOptionsName: string[] = []): OptionTree[] {
const optionCollection = new Map<string, OptionTree>();
Object.values(options).forEach((option) => {
if (isOneLine) {
Expand Down Expand Up @@ -943,7 +943,7 @@ function getCategoryOptionTree(options: Record<string, Category> | Category[], i
searchText,
tooltipText: optionName,
isDisabled: isChild ? !option.enabled : true,
isSelected: !!option.isSelected,
isSelected: isChild ? !!option.isSelected : selectedOptionsName.includes(searchText),
});
});
});
Expand Down Expand Up @@ -1051,7 +1051,7 @@ function getCategoryListSections(
title: Localize.translateLocal('common.all'),
shouldShow: true,
indexOffset,
data: getCategoryOptionTree(filteredCategories),
data: getCategoryOptionTree(filteredCategories, false, selectedOptionNames),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dukenv0307 should we update other places calling to this method as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you point out any similar cases that we need to fix? I am worried that adding the change to other places can leads to the regression

Copy link
Contributor

@hoangzinh hoangzinh Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, these are several cases:

Case 1: Search a category

if (searchInputValue) {
const searchCategories = enabledCategories.filter((category) => category.name.toLowerCase().includes(searchInputValue.toLowerCase()));
categorySections.push({
// "Search" section
title: '',
shouldShow: true,
indexOffset,
data: getCategoryOptionTree(searchCategories, true),
});
return categorySections;
}

Case 2: When there are no categories

if (numberOfCategories === 0 && selectedOptions.length > 0) {
categorySections.push({
// "Selected" section
title: '',
shouldShow: false,
indexOffset,
data: getCategoryOptionTree(selectedOptions, true),
});
return categorySections;
}

Copy link
Contributor Author

@dukenv0307 dukenv0307 Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • In case 1: Search a category

It will be handled in #37479

  • In case 2: When there are no categories:

I cannot reproduce this case because, if there is no category, the category picker screen will display as "Hmm... it's not here"

});

return categorySections;
Expand Down
Loading