diff --git a/x-pack/plugins/global_search_providers/public/index.ts b/x-pack/plugins/global_search_providers/public/index.ts index 734c1b856d824..f841ac7988f6d 100644 --- a/x-pack/plugins/global_search_providers/public/index.ts +++ b/x-pack/plugins/global_search_providers/public/index.ts @@ -5,18 +5,9 @@ */ import { PluginInitializer } from 'src/core/public'; -import { - GlobalSearchProvidersPlugin, - GlobalSearchProvidersPluginSetupDeps, - GlobalSearchProvidersPluginStartDeps, -} from './plugin'; -import { GlobalSearchProvidersPluginSetup, GlobalSearchProvidersPluginStart } from './types'; +import { GlobalSearchProvidersPlugin, GlobalSearchProvidersPluginSetupDeps } from './plugin'; -export const plugin: PluginInitializer< - GlobalSearchProvidersPluginSetup, - GlobalSearchProvidersPluginStart, - GlobalSearchProvidersPluginSetupDeps, - GlobalSearchProvidersPluginStartDeps -> = (context) => new GlobalSearchProvidersPlugin(); +export const plugin: PluginInitializer<{}, {}, GlobalSearchProvidersPluginSetupDeps, {}> = () => + new GlobalSearchProvidersPlugin(); export { GlobalSearchProvidersPluginSetup, GlobalSearchProvidersPluginStart }; diff --git a/x-pack/plugins/global_search_providers/public/plugin.ts b/x-pack/plugins/global_search_providers/public/plugin.ts index 5aef8804d91aa..b39e526703067 100644 --- a/x-pack/plugins/global_search_providers/public/plugin.ts +++ b/x-pack/plugins/global_search_providers/public/plugin.ts @@ -13,17 +13,8 @@ export interface GlobalSearchProvidersPluginSetupDeps { globalSearch: GlobalSearchPluginSetup; } -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface GlobalSearchProvidersPluginStartDeps {} - export class GlobalSearchProvidersPlugin - implements - Plugin< - GlobalSearchProvidersPluginSetup, - GlobalSearchProvidersPluginStart, - GlobalSearchProvidersPluginSetupDeps, - GlobalSearchProvidersPluginStartDeps - > { + implements Plugin<{}, {}, GlobalSearchProvidersPluginSetupDeps, {}> { setup( { getStartServices, diff --git a/x-pack/plugins/global_search_providers/public/providers/application.test.ts b/x-pack/plugins/global_search_providers/public/providers/application.test.ts index 490d88d76249c..ca19bddb60297 100644 --- a/x-pack/plugins/global_search_providers/public/providers/application.test.ts +++ b/x-pack/plugins/global_search_providers/public/providers/application.test.ts @@ -87,6 +87,33 @@ describe('applicationResultProvider', () => { ]); }); + it('ignores inaccessible apps', async () => { + application.applications$ = of( + createAppMap([ + createApp({ id: 'app1', title: 'App 1' }), + createApp({ id: 'disabled', title: 'disabled', status: AppStatus.inaccessible }), + ]) + ); + const provider = createApplicationResultProvider(Promise.resolve(application)); + await provider.find('term', defaultOption).toPromise(); + + expect(getAppResultsMock).toHaveBeenCalledWith('term', [expectApp('app1')]); + }); + + it('ignores chromeless apps', async () => { + application.applications$ = of( + createAppMap([ + createApp({ id: 'app1', title: 'App 1' }), + createApp({ id: 'chromeless', title: 'chromeless', chromeless: true }), + ]) + ); + + const provider = createApplicationResultProvider(Promise.resolve(application)); + await provider.find('term', defaultOption).toPromise(); + + expect(getAppResultsMock).toHaveBeenCalledWith('term', [expectApp('app1')]); + }); + it('sorts the results returned by `getAppResults`', async () => { getAppResultsMock.mockReturnValue([ createResult({ id: 'r60', score: 60 }), @@ -96,7 +123,6 @@ describe('applicationResultProvider', () => { ]); const provider = createApplicationResultProvider(Promise.resolve(application)); - const results = await provider.find('term', defaultOption).toPromise(); expect(results).toEqual([ diff --git a/x-pack/plugins/global_search_providers/public/providers/application.ts b/x-pack/plugins/global_search_providers/public/providers/application.ts index 8d6955cf0347f..e40fcef17f73c 100644 --- a/x-pack/plugins/global_search_providers/public/providers/application.ts +++ b/x-pack/plugins/global_search_providers/public/providers/application.ts @@ -5,7 +5,7 @@ */ import { from } from 'rxjs'; -import { take, map, takeUntil, mergeMap } from 'rxjs/operators'; +import { take, map, takeUntil, mergeMap, shareReplay } from 'rxjs/operators'; import { ApplicationStart } from 'src/core/public'; import { GlobalSearchResultProvider } from '../../../global_search/public'; import { getAppResults } from './get_app_results'; @@ -13,11 +13,20 @@ import { getAppResults } from './get_app_results'; export const createApplicationResultProvider = ( applicationPromise: Promise ): GlobalSearchResultProvider => { + const searchableApps$ = from(applicationPromise).pipe( + mergeMap((application) => application.applications$), + map((apps) => + [...apps.values()].filter( + (app) => app.status === 0 && (app.legacy === true || app.chromeless !== true) + ) + ), + shareReplay(1) + ); + return { id: 'application', find: (term, { aborted$, maxResults }) => { - return from(applicationPromise).pipe( - mergeMap((application) => application.applications$), + return searchableApps$.pipe( takeUntil(aborted$), take(1), map((apps) => { diff --git a/x-pack/plugins/global_search_providers/public/providers/get_app_results.test.ts b/x-pack/plugins/global_search_providers/public/providers/get_app_results.test.ts index 79147b1473fa7..1c5a446b8e564 100644 --- a/x-pack/plugins/global_search_providers/public/providers/get_app_results.test.ts +++ b/x-pack/plugins/global_search_providers/public/providers/get_app_results.test.ts @@ -40,24 +40,6 @@ describe('getAppResults', () => { expect(results.length).toBe(1); expect(results[0]).toEqual(expect.objectContaining({ id: 'dashboard', score: 100 })); }); - - it('ignores inaccessible apps', () => { - const apps = [ - createApp({ id: 'dashboard', title: 'dashboard', status: AppStatus.inaccessible }), - ]; - - const results = getAppResults('dashboard', apps); - - expect(results.length).toBe(0); - }); - - it('ignores chromeless apps', () => { - const apps = [createApp({ id: 'dashboard', title: 'dashboard', chromeless: true })]; - - const results = getAppResults('dashboard', apps); - - expect(results.length).toBe(0); - }); }); describe('scoreApp', () => { diff --git a/x-pack/plugins/global_search_providers/public/providers/get_app_results.ts b/x-pack/plugins/global_search_providers/public/providers/get_app_results.ts index 37d279db15df3..1a1939230105b 100644 --- a/x-pack/plugins/global_search_providers/public/providers/get_app_results.ts +++ b/x-pack/plugins/global_search_providers/public/providers/get_app_results.ts @@ -12,14 +12,10 @@ export const getAppResults = ( term: string, apps: Array ): GlobalSearchProviderResult[] => { - return ( - apps - // remove disabled and chromeless app (to avoid returning the login page for example) - .filter((app) => app.status === 0 && (app.legacy === true || app.chromeless !== true)) - .map((app) => ({ app, score: scoreApp(term, app) })) - .filter(({ score }) => score > 0) - .map(({ app, score }) => appToResult(app, score)) - ); + return apps + .map((app) => ({ app, score: scoreApp(term, app) })) + .filter(({ score }) => score > 0) + .map(({ app, score }) => appToResult(app, score)); }; export const scoreApp = (term: string, { title }: PublicAppInfo | PublicLegacyAppInfo): number => { diff --git a/x-pack/plugins/global_search_providers/public/types.ts b/x-pack/plugins/global_search_providers/public/types.ts deleted file mode 100644 index f3aac002606f5..0000000000000 --- a/x-pack/plugins/global_search_providers/public/types.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface GlobalSearchProvidersPluginSetup {} - -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface GlobalSearchProvidersPluginStart {}