From 0f072296b5844f29ce32e31194895b3fc390169e Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Tue, 22 Oct 2024 11:40:42 +0200 Subject: [PATCH] [Global Search] Fix convertTagNameToId to use lowercase values (#196819) ## Summary This PR fixes a bug which caused mixed case tags to not be found in global search. Fixes: #196168 The `allTags` argument contains tags with names in the original case they were created but the `tagName` argument passed in [search_bar.tsx:180](https://github.com/elastic/kibana/blob/main/x-pack/plugins/global_search_bar/public/components/search_bar.tsx#L180) is lowercase. Since you can't have tags with the same name but different casing, converting them to lowercase is safe. I've also added lowercase conversion to `tagName` argument in case this function gets called somewhere else and the input is not lowercase. (cherry picked from commit b495c371fd946f39341a557599033647f81cdbf3) --- .../plugins/global_search_bar/public/components/search_bar.tsx | 2 +- x-pack/plugins/saved_objects_tagging/public/utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/global_search_bar/public/components/search_bar.tsx b/x-pack/plugins/global_search_bar/public/components/search_bar.tsx index efc564089fb43..de9bb85f7a8a3 100644 --- a/x-pack/plugins/global_search_bar/public/components/search_bar.tsx +++ b/x-pack/plugins/global_search_bar/public/components/search_bar.tsx @@ -177,7 +177,7 @@ export const SearchBar: FC = (opts) => { let tagIds: string[] | undefined; if (taggingApi && rawParams.filters.tags) { tagIds = rawParams.filters.tags.map( - (tagName) => taggingApi.ui.getTagIdFromName(tagName.toLowerCase()) ?? UNKNOWN_TAG_ID + (tagName) => taggingApi.ui.getTagIdFromName(tagName) ?? UNKNOWN_TAG_ID ); } else { tagIds = undefined; diff --git a/x-pack/plugins/saved_objects_tagging/public/utils.ts b/x-pack/plugins/saved_objects_tagging/public/utils.ts index 38ae79f3ca033..fc8ec8ebd3029 100644 --- a/x-pack/plugins/saved_objects_tagging/public/utils.ts +++ b/x-pack/plugins/saved_objects_tagging/public/utils.ts @@ -45,7 +45,7 @@ export const getTagsFromReferences = (references: SavedObjectReference[], allTag }; export const convertTagNameToId = (tagName: string, allTags: Tag[]): string | undefined => { - const found = allTags.find((tag) => tag.name === tagName); + const found = allTags.find((tag) => tag.name.toLowerCase() === tagName.toLowerCase()); return found?.id; };