Skip to content

Commit

Permalink
[Global Search] Fix convertTagNameToId to use lowercase values (elast…
Browse files Browse the repository at this point in the history
…ic#196819)

## Summary

This PR fixes a bug which caused mixed case tags to not be found in
global search.
Fixes: elastic#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.
  • Loading branch information
kowalczyk-krzysztof authored Oct 22, 2024
1 parent 996eb73 commit b495c37
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const SearchBar: FC<SearchBarProps> = (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;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/saved_objects_tagging/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit b495c37

Please sign in to comment.