Skip to content

Commit

Permalink
Added svg, icon path in the search results and refine search term
Browse files Browse the repository at this point in the history
  • Loading branch information
Samiul-TheSoccerFan committed Feb 11, 2024
1 parent 944e05d commit 6c9e46a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion x-pack/plugins/enterprise_search/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export class EnterpriseSearchPlugin implements Plugin {

if (globalSearch) {
globalSearch.registerResultProvider(getSearchResultProvider(http.basePath, config));
globalSearch.registerResultProvider(getIndicesSearchResultProvider());
globalSearch.registerResultProvider(getIndicesSearchResultProvider(http.basePath));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { ENTERPRISE_SEARCH_CONTENT_PLUGIN } from '../../common/constants';
import { getIndicesSearchResultProvider } from './indices_search_result_provider';

describe('Enterprise Search - indices search provider', () => {
const indicesSearchResultProvider = getIndicesSearchResultProvider();
const basePathMock = {
prepend: (input: string) => `/kbn${input}`,
} as any;

const indicesSearchResultProvider = getIndicesSearchResultProvider(basePathMock);

const regularIndexResponse = {
'search-github-api': {
Expand Down Expand Up @@ -50,6 +54,7 @@ describe('Enterprise Search - indices search provider', () => {
path: `${ENTERPRISE_SEARCH_CONTENT_PLUGIN.URL}/search_indices/search-github-api`,
prependBasePath: true,
},
icon: '/kbn/plugins/enterpriseSearch/assets/source_icons/index.svg',
};

const msftIndex = {
Expand All @@ -61,6 +66,7 @@ describe('Enterprise Search - indices search provider', () => {
path: `${ENTERPRISE_SEARCH_CONTENT_PLUGIN.URL}/search_indices/search-msft-sql-index`,
prependBasePath: true,
},
icon: '/kbn/plugins/enterpriseSearch/assets/source_icons/index.svg',
};

beforeEach(() => {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { from, takeUntil } from 'rxjs';

import { IBasePath } from '@kbn/core-http-server';
import {
GlobalSearchProviderResult,
GlobalSearchResultProvider,
Expand All @@ -17,7 +18,7 @@ import { ENTERPRISE_SEARCH_CONTENT_PLUGIN } from '../../common/constants';

import { getIndexData } from '../lib/indices/utils/get_index_data';

export function getIndicesSearchResultProvider(): GlobalSearchResultProvider {
export function getIndicesSearchResultProvider(basePath: IBasePath): GlobalSearchResultProvider {
return {
find: ({ term, types, tags }, { aborted$, client, maxResults }) => {
if (!client || !term || tags || (types && !types.includes('indices'))) {
Expand All @@ -44,6 +45,7 @@ export function getIndicesSearchResultProvider(): GlobalSearchResultProvider {
return {
id: indexName,
title: indexName,
icon: basePath.prepend('/plugins/enterpriseSearch/assets/source_icons/index.svg'),
type: i18n.translate('xpack.enterpriseSearch.searchIndexProvider.type.name', {
defaultMessage: 'Index',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ describe('resultToOption', () => {
);
});

it('uses icon for `index` type', () => {
const input = createSearchResult({ type: 'index', icon: 'index-icon' });
expect(resultToOption(input, [])).toEqual(
expect.objectContaining({
icon: { type: 'index-icon' },
})
);
});

it('does not use icon for other types', () => {
const input = createSearchResult({ type: 'dashboard', icon: 'dash-icon' });
expect(resultToOption(input, [])).toEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const resultToOption = (
type === 'application' ||
type === 'integration' ||
type.toLowerCase() === 'enterprise search' ||
type.toLowerCase() === 'search';
type.toLowerCase() === 'search' ||
type.toLowerCase() === 'index';
const option: EuiSelectableTemplateSitewideOption = {
key: id,
label: title,
Expand Down

0 comments on commit 6c9e46a

Please sign in to comment.