From c64984e54105e59a2c4fcafc2ffcdc566128148f Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 21 Nov 2023 15:05:44 -0700 Subject: [PATCH] revert initial changes, update logic --- src/components/TagPicker/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/TagPicker/index.js b/src/components/TagPicker/index.js index 9f889c701116..a9bb76e103a2 100644 --- a/src/components/TagPicker/index.js +++ b/src/components/TagPicker/index.js @@ -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,