Skip to content

Commit 3ef8b1d

Browse files
committed
remove empty contracts & cache searchable apps
1 parent 0454d35 commit 3ef8b1d

File tree

7 files changed

+47
-63
lines changed

7 files changed

+47
-63
lines changed

x-pack/plugins/global_search_providers/public/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,9 @@
55
*/
66

77
import { PluginInitializer } from 'src/core/public';
8-
import {
9-
GlobalSearchProvidersPlugin,
10-
GlobalSearchProvidersPluginSetupDeps,
11-
GlobalSearchProvidersPluginStartDeps,
12-
} from './plugin';
13-
import { GlobalSearchProvidersPluginSetup, GlobalSearchProvidersPluginStart } from './types';
8+
import { GlobalSearchProvidersPlugin, GlobalSearchProvidersPluginSetupDeps } from './plugin';
149

15-
export const plugin: PluginInitializer<
16-
GlobalSearchProvidersPluginSetup,
17-
GlobalSearchProvidersPluginStart,
18-
GlobalSearchProvidersPluginSetupDeps,
19-
GlobalSearchProvidersPluginStartDeps
20-
> = (context) => new GlobalSearchProvidersPlugin();
10+
export const plugin: PluginInitializer<{}, {}, GlobalSearchProvidersPluginSetupDeps, {}> = () =>
11+
new GlobalSearchProvidersPlugin();
2112

2213
export { GlobalSearchProvidersPluginSetup, GlobalSearchProvidersPluginStart };

x-pack/plugins/global_search_providers/public/plugin.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,8 @@ export interface GlobalSearchProvidersPluginSetupDeps {
1313
globalSearch: GlobalSearchPluginSetup;
1414
}
1515

16-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
17-
export interface GlobalSearchProvidersPluginStartDeps {}
18-
1916
export class GlobalSearchProvidersPlugin
20-
implements
21-
Plugin<
22-
GlobalSearchProvidersPluginSetup,
23-
GlobalSearchProvidersPluginStart,
24-
GlobalSearchProvidersPluginSetupDeps,
25-
GlobalSearchProvidersPluginStartDeps
26-
> {
17+
implements Plugin<{}, {}, GlobalSearchProvidersPluginSetupDeps, {}> {
2718
setup(
2819
{
2920
getStartServices,

x-pack/plugins/global_search_providers/public/providers/application.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,33 @@ describe('applicationResultProvider', () => {
8787
]);
8888
});
8989

90+
it('ignores inaccessible apps', async () => {
91+
application.applications$ = of(
92+
createAppMap([
93+
createApp({ id: 'app1', title: 'App 1' }),
94+
createApp({ id: 'disabled', title: 'disabled', status: AppStatus.inaccessible }),
95+
])
96+
);
97+
const provider = createApplicationResultProvider(Promise.resolve(application));
98+
await provider.find('term', defaultOption).toPromise();
99+
100+
expect(getAppResultsMock).toHaveBeenCalledWith('term', [expectApp('app1')]);
101+
});
102+
103+
it('ignores chromeless apps', async () => {
104+
application.applications$ = of(
105+
createAppMap([
106+
createApp({ id: 'app1', title: 'App 1' }),
107+
createApp({ id: 'chromeless', title: 'chromeless', chromeless: true }),
108+
])
109+
);
110+
111+
const provider = createApplicationResultProvider(Promise.resolve(application));
112+
await provider.find('term', defaultOption).toPromise();
113+
114+
expect(getAppResultsMock).toHaveBeenCalledWith('term', [expectApp('app1')]);
115+
});
116+
90117
it('sorts the results returned by `getAppResults`', async () => {
91118
getAppResultsMock.mockReturnValue([
92119
createResult({ id: 'r60', score: 60 }),
@@ -96,7 +123,6 @@ describe('applicationResultProvider', () => {
96123
]);
97124

98125
const provider = createApplicationResultProvider(Promise.resolve(application));
99-
100126
const results = await provider.find('term', defaultOption).toPromise();
101127

102128
expect(results).toEqual([

x-pack/plugins/global_search_providers/public/providers/application.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@
55
*/
66

77
import { from } from 'rxjs';
8-
import { take, map, takeUntil, mergeMap } from 'rxjs/operators';
8+
import { take, map, takeUntil, mergeMap, shareReplay } from 'rxjs/operators';
99
import { ApplicationStart } from 'src/core/public';
1010
import { GlobalSearchResultProvider } from '../../../global_search/public';
1111
import { getAppResults } from './get_app_results';
1212

1313
export const createApplicationResultProvider = (
1414
applicationPromise: Promise<ApplicationStart>
1515
): GlobalSearchResultProvider => {
16+
const searchableApps$ = from(applicationPromise).pipe(
17+
mergeMap((application) => application.applications$),
18+
map((apps) =>
19+
[...apps.values()].filter(
20+
(app) => app.status === 0 && (app.legacy === true || app.chromeless !== true)
21+
)
22+
),
23+
shareReplay(1)
24+
);
25+
1626
return {
1727
id: 'application',
1828
find: (term, { aborted$, maxResults }) => {
19-
return from(applicationPromise).pipe(
20-
mergeMap((application) => application.applications$),
29+
return searchableApps$.pipe(
2130
takeUntil(aborted$),
2231
take(1),
2332
map((apps) => {

x-pack/plugins/global_search_providers/public/providers/get_app_results.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,6 @@ describe('getAppResults', () => {
4040
expect(results.length).toBe(1);
4141
expect(results[0]).toEqual(expect.objectContaining({ id: 'dashboard', score: 100 }));
4242
});
43-
44-
it('ignores inaccessible apps', () => {
45-
const apps = [
46-
createApp({ id: 'dashboard', title: 'dashboard', status: AppStatus.inaccessible }),
47-
];
48-
49-
const results = getAppResults('dashboard', apps);
50-
51-
expect(results.length).toBe(0);
52-
});
53-
54-
it('ignores chromeless apps', () => {
55-
const apps = [createApp({ id: 'dashboard', title: 'dashboard', chromeless: true })];
56-
57-
const results = getAppResults('dashboard', apps);
58-
59-
expect(results.length).toBe(0);
60-
});
6143
});
6244

6345
describe('scoreApp', () => {

x-pack/plugins/global_search_providers/public/providers/get_app_results.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ export const getAppResults = (
1212
term: string,
1313
apps: Array<PublicAppInfo | PublicLegacyAppInfo>
1414
): GlobalSearchProviderResult[] => {
15-
return (
16-
apps
17-
// remove disabled and chromeless app (to avoid returning the login page for example)
18-
.filter((app) => app.status === 0 && (app.legacy === true || app.chromeless !== true))
19-
.map((app) => ({ app, score: scoreApp(term, app) }))
20-
.filter(({ score }) => score > 0)
21-
.map(({ app, score }) => appToResult(app, score))
22-
);
15+
return apps
16+
.map((app) => ({ app, score: scoreApp(term, app) }))
17+
.filter(({ score }) => score > 0)
18+
.map(({ app, score }) => appToResult(app, score));
2319
};
2420

2521
export const scoreApp = (term: string, { title }: PublicAppInfo | PublicLegacyAppInfo): number => {

x-pack/plugins/global_search_providers/public/types.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)