Skip to content

Commit

Permalink
revert initial changes, update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Nov 21, 2023
1 parent 0c9edf6 commit c64984e
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/components/TagPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,26 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm
];
}, [selectedTag]);

const initialFocusedIndex = useMemo(() => {
if (isTagsCountBelowThreshold && selectedOptions.length > 0) {
return _.chain(policyTagList)
.values()
.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))];
const tags = _.filter(policyTagList, (policyTag) => policyTag.enabled || selectedNames.includes(policyTag.name));
return tags;
}, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]);

const initialFocusedIndex = useMemo(() => {
if (isTagsCountBelowThreshold && selectedOptions.length > 0) {
return _.chain(enabledTags)
.findIndex((policyTag) => policyTag.name === selectedOptions[0].name, true)
.value();
}

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

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

0 comments on commit c64984e

Please sign in to comment.