-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathapplication.ts
40 lines (37 loc) · 1.37 KB
/
application.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* 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.
*/
import { from } from 'rxjs';
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';
export const createApplicationResultProvider = (
applicationPromise: Promise<ApplicationStart>
): GlobalSearchResultProvider => {
const searchableApps$ = from(applicationPromise).pipe(
mergeMap((application) => application.applications$),
map((apps) =>
[...apps.values()].filter(
// only include non-chromeless enabled apps with visible navLinks
(app) => app.status === 0 && app.navLinkStatus === 1 && app.chromeless !== true
)
),
shareReplay(1)
);
return {
id: 'application',
find: (term, { aborted$, maxResults }) => {
return searchableApps$.pipe(
takeUntil(aborted$),
take(1),
map((apps) => {
const results = getAppResults(term, [...apps.values()]);
return results.sort((a, b) => b.score - a.score).slice(0, maxResults);
})
);
},
};
};