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 tagList highlight #31652

Closed
wants to merge 8 commits into from
Closed
Changes from 7 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
26 changes: 14 additions & 12 deletions src/components/TagPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,27 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm
];
}, [selectedTag]);

const enabledTags = useMemo(() => {
if (!shouldShowDisabledAndSelectedOption) {
return policyTagList;
}
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
const selectedNames = _.map(selectedOptions, (s) => s.name);
return _.chain(policyTagList)
.values()
.sortBy((policyTag) => policyTag.name)
.filter((policyTag) => policyTag.enabled || selectedNames.includes(policyTag.name))
.value();
}, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]);

const initialFocusedIndex = useMemo(() => {
if (isTagsCountBelowThreshold && selectedOptions.length > 0) {
return _.chain(policyTagList)
.values()
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
return _.chain(enabledTags)
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
.findIndex((policyTag) => policyTag.name === selectedOptions[0].name, true)
.value();
}

return 0;
}, [policyTagList, selectedOptions, isTagsCountBelowThreshold]);

const enabledTags = useMemo(() => {
if (!shouldShowDisabledAndSelectedOption) {
return policyTagList;
}
const selectedNames = _.map(selectedOptions, (s) => s.name);
const tags = [...selectedOptions, ..._.filter(policyTagList, (policyTag) => policyTag.enabled && !selectedNames.includes(policyTag.name))];
return tags;
}, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]);
}, [enabledTags, selectedOptions, isTagsCountBelowThreshold]);

const sections = useMemo(
() => OptionsListUtils.getFilteredOptions({}, {}, [], searchValue, selectedOptions, [], false, false, false, {}, [], true, enabledTags, policyRecentlyUsedTagsList, false).tagOptions,
Expand Down
Loading