From d0dee2877dc5c488f4c2fa908ec1ec5edc323ca1 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 21 Nov 2023 11:46:41 -0700 Subject: [PATCH 1/8] fix tagList highlight --- src/components/TagPicker/index.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/TagPicker/index.js b/src/components/TagPicker/index.js index d6d49e3fe288..b2e73f09fd80 100644 --- a/src/components/TagPicker/index.js +++ b/src/components/TagPicker/index.js @@ -37,17 +37,6 @@ 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; @@ -56,6 +45,16 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm const tags = [...selectedOptions, ..._.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, From 0c9edf62898895591986916ac092809f27452812 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 21 Nov 2023 12:58:10 -0700 Subject: [PATCH 2/8] fix lint --- src/components/TagPicker/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/TagPicker/index.js b/src/components/TagPicker/index.js index b2e73f09fd80..9f889c701116 100644 --- a/src/components/TagPicker/index.js +++ b/src/components/TagPicker/index.js @@ -45,14 +45,14 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm const tags = [...selectedOptions, ..._.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(); + .findIndex((policyTag) => policyTag.name === selectedOptions[0].name, true) + .value(); } - + return 0; }, [enabledTags, selectedOptions, isTagsCountBelowThreshold]); From c64984e54105e59a2c4fcafc2ffcdc566128148f Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 21 Nov 2023 15:05:44 -0700 Subject: [PATCH 3/8] 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, From 07e6716aee445d17601d89142f52bded36161c89 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 21 Nov 2023 15:06:20 -0700 Subject: [PATCH 4/8] rm empty line --- src/components/TagPicker/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/TagPicker/index.js b/src/components/TagPicker/index.js index a9bb76e103a2..fd48227e05c0 100644 --- a/src/components/TagPicker/index.js +++ b/src/components/TagPicker/index.js @@ -57,7 +57,6 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm return tags; }, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]); - const sections = useMemo( () => OptionsListUtils.getFilteredOptions({}, {}, [], searchValue, selectedOptions, [], false, false, false, {}, [], true, enabledTags, policyRecentlyUsedTagsList, false).tagOptions, [searchValue, enabledTags, selectedOptions, policyRecentlyUsedTagsList], From 07fd587123e40ea50b2690cbf5ad18224feb38f7 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 21 Nov 2023 15:10:55 -0700 Subject: [PATCH 5/8] dont use values --- src/components/TagPicker/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/TagPicker/index.js b/src/components/TagPicker/index.js index fd48227e05c0..044f0c0bd508 100644 --- a/src/components/TagPicker/index.js +++ b/src/components/TagPicker/index.js @@ -40,7 +40,6 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm const initialFocusedIndex = useMemo(() => { if (isTagsCountBelowThreshold && selectedOptions.length > 0) { return _.chain(policyTagList) - .values() .findIndex((policyTag) => policyTag.name === selectedOptions[0].name, true) .value(); } @@ -53,8 +52,7 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm return policyTagList; } const selectedNames = _.map(selectedOptions, (s) => s.name); - const tags = _.filter(policyTagList, (policyTag) => policyTag.enabled || selectedNames.includes(policyTag.name)); - return tags; + return _.filter(policyTagList, (policyTag) => policyTag.enabled || selectedNames.includes(policyTag.name)); }, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]); const sections = useMemo( From 53213f3864685b342d5ebadce46227333e8425b9 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 21 Nov 2023 15:31:36 -0700 Subject: [PATCH 6/8] update initialFocusedIndex --- src/components/TagPicker/index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/TagPicker/index.js b/src/components/TagPicker/index.js index 044f0c0bd508..00d544d68ced 100644 --- a/src/components/TagPicker/index.js +++ b/src/components/TagPicker/index.js @@ -37,16 +37,6 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm ]; }, [selectedTag]); - const initialFocusedIndex = useMemo(() => { - if (isTagsCountBelowThreshold && selectedOptions.length > 0) { - return _.chain(policyTagList) - .findIndex((policyTag) => policyTag.name === selectedOptions[0].name, true) - .value(); - } - - return 0; - }, [policyTagList, selectedOptions, isTagsCountBelowThreshold]); - const enabledTags = useMemo(() => { if (!shouldShowDisabledAndSelectedOption) { return policyTagList; @@ -55,6 +45,16 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm return _.filter(policyTagList, (policyTag) => policyTag.enabled || selectedNames.includes(policyTag.name)); }, [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, [searchValue, enabledTags, selectedOptions, policyRecentlyUsedTagsList], From 4ddac94d74263a42eba7aa9f3f5d3c33ecad0a21 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 21 Nov 2023 16:20:50 -0700 Subject: [PATCH 7/8] sort tags first --- src/components/TagPicker/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/TagPicker/index.js b/src/components/TagPicker/index.js index 00d544d68ced..2ff0bfc053d5 100644 --- a/src/components/TagPicker/index.js +++ b/src/components/TagPicker/index.js @@ -42,7 +42,11 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm return policyTagList; } const selectedNames = _.map(selectedOptions, (s) => s.name); - return _.filter(policyTagList, (policyTag) => policyTag.enabled || selectedNames.includes(policyTag.name)); + return _.chain(policyTagList) + .values() + .sortBy((policyTag) => policyTag.name) + .filter((policyTag) => policyTag.enabled || selectedNames.includes(policyTag.name)) + .value(); }, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]); const initialFocusedIndex = useMemo(() => { From 850d8f69568e2eef629e3b5f7c9f3ff7bf64bf03 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 21 Nov 2023 16:42:01 -0700 Subject: [PATCH 8/8] sort both tag lists --- src/components/TagPicker/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/TagPicker/index.js b/src/components/TagPicker/index.js index 2ff0bfc053d5..5fec06c325a6 100644 --- a/src/components/TagPicker/index.js +++ b/src/components/TagPicker/index.js @@ -38,13 +38,16 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm }, [selectedTag]); const enabledTags = useMemo(() => { + const sortedTagList = _.chain(policyTagList) + .values() + .sortBy((policyTag) => policyTag.name) + .value(); + if (!shouldShowDisabledAndSelectedOption) { - return policyTagList; + return sortedTagList; } const selectedNames = _.map(selectedOptions, (s) => s.name); - return _.chain(policyTagList) - .values() - .sortBy((policyTag) => policyTag.name) + return _.chain(sortedTagList) .filter((policyTag) => policyTag.enabled || selectedNames.includes(policyTag.name)) .value(); }, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]);