Skip to content

Commit

Permalink
Adding meta data and highlighting to nav search (#77662)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michail Yasonik authored Sep 17, 2020
1 parent 102be1b commit 4bf0932
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ type Result = { id: string; type: string } | string;
const createResult = (result: Result): GlobalSearchResult => {
const id = typeof result === 'string' ? result : result.id;
const type = typeof result === 'string' ? 'application' : result.type;
const meta = type === 'application' ? { categoryLabel: 'Kibana' } : { categoryLabel: null };

return {
id,
type,
title: id,
url: `/app/test/${id}`,
score: 42,
meta,
};
};

Expand Down Expand Up @@ -74,7 +76,7 @@ describe('SearchBar', () => {
expect(findSpy).toHaveBeenCalledTimes(1);
expect(findSpy).toHaveBeenCalledWith('', {});
expect(getSelectableProps(component).options).toMatchSnapshot();
await wait(() => getSearchProps(component).onSearch('d'));
await wait(() => getSearchProps(component).onKeyUpCapture({ currentTarget: { value: 'd' } }));
jest.runAllTimers();
component.update();
expect(getSelectableProps(component).options).toMatchSnapshot();
Expand Down
25 changes: 16 additions & 9 deletions x-pack/plugins/global_search_bar/public/components/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ export function SearchBar({ globalSearch, navigateToUrl }: Props) {
if (!isMounted()) return;

_setOptions([
..._options.map((option) => ({
key: option.id,
label: option.title,
url: option.url,
...(option.icon && { icon: { type: option.icon } }),
...(option.type &&
option.type !== 'application' && { meta: [{ text: cleanMeta(option.type) }] }),
})),
..._options.map(({ id, title, url, icon, type, meta }) => {
const option: EuiSelectableTemplateSitewideOption = {
key: id,
label: title,
url,
};

if (icon) option.icon = { type: icon };

if (type === 'application') option.meta = [{ text: meta?.categoryLabel as string }];
else option.meta = [{ text: cleanMeta(type) }];

return option;
}),
]);
},
[isMounted, _setOptions]
Expand Down Expand Up @@ -133,7 +139,8 @@ export function SearchBar({ globalSearch, navigateToUrl }: Props) {
onChange={onChange}
options={options}
searchProps={{
onSearch: setSearchValue,
onKeyUpCapture: (e: React.KeyboardEvent<HTMLInputElement>) =>
setSearchValue(e.currentTarget.value),
'data-test-subj': 'header-search',
inputRef: setSearchRef,
compressed: true,
Expand Down

0 comments on commit 4bf0932

Please sign in to comment.