Skip to content

Commit 8fe3814

Browse files
authored
[GS] add application result provider (#68488) (#70192)
* add application result provider * remove empty contracts & cache searchable apps * fix types
1 parent 1c59796 commit 8fe3814

File tree

18 files changed

+558
-0
lines changed

18 files changed

+558
-0
lines changed

docs/development/core/public/kibana-plugin-core-public.publicappinfo.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ Public information about a registered [application](./kibana-plugin-core-public.
1111
```typescript
1212
export declare type PublicAppInfo = Omit<App, 'mount' | 'updater$'> & {
1313
legacy: false;
14+
status: AppStatus;
15+
navLinkStatus: AppNavLinkStatus;
16+
appRoute: string;
1417
};
1518
```

docs/development/core/public/kibana-plugin-core-public.publiclegacyappinfo.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ Information about a registered [legacy application](./kibana-plugin-core-public.
1111
```typescript
1212
export declare type PublicLegacyAppInfo = Omit<LegacyApp, 'updater$'> & {
1313
legacy: true;
14+
status: AppStatus;
15+
navLinkStatus: AppNavLinkStatus;
1416
};
1517
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
"inline-style": "^2.0.0",
200200
"joi": "^13.5.2",
201201
"jquery": "^3.5.0",
202+
"js-levenshtein": "^1.1.6",
202203
"js-yaml": "3.13.1",
203204
"json-stable-stringify": "^1.0.1",
204205
"json-stringify-pretty-compact": "1.2.0",

src/core/public/application/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ export interface LegacyApp extends AppBase {
269269
*/
270270
export type PublicAppInfo = Omit<App, 'mount' | 'updater$'> & {
271271
legacy: false;
272+
// remove optional on fields populated with default values
273+
status: AppStatus;
274+
navLinkStatus: AppNavLinkStatus;
275+
appRoute: string;
272276
};
273277

274278
/**
@@ -278,6 +282,9 @@ export type PublicAppInfo = Omit<App, 'mount' | 'updater$'> & {
278282
*/
279283
export type PublicLegacyAppInfo = Omit<LegacyApp, 'updater$'> & {
280284
legacy: true;
285+
// remove optional on fields populated with default values
286+
status: AppStatus;
287+
navLinkStatus: AppNavLinkStatus;
281288
};
282289

283290
/**

src/core/public/application/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,17 @@ export function getAppInfo(app: App<unknown> | LegacyApp): PublicAppInfo | Publi
120120
const { updater$, ...infos } = app;
121121
return {
122122
...infos,
123+
status: app.status!,
124+
navLinkStatus: app.navLinkStatus!,
123125
legacy: true,
124126
};
125127
} else {
126128
const { updater$, mount, ...infos } = app;
127129
return {
128130
...infos,
131+
status: app.status!,
132+
navLinkStatus: app.navLinkStatus!,
133+
appRoute: app.appRoute!,
129134
legacy: false,
130135
};
131136
}

src/core/public/public.api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,11 +1143,16 @@ export type PluginOpaqueId = symbol;
11431143
// @public
11441144
export type PublicAppInfo = Omit<App, 'mount' | 'updater$'> & {
11451145
legacy: false;
1146+
status: AppStatus;
1147+
navLinkStatus: AppNavLinkStatus;
1148+
appRoute: string;
11461149
};
11471150

11481151
// @public
11491152
export type PublicLegacyAppInfo = Omit<LegacyApp, 'updater$'> & {
11501153
legacy: true;
1154+
status: AppStatus;
1155+
navLinkStatus: AppNavLinkStatus;
11511156
};
11521157

11531158
// @public
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "globalSearchProviders",
3+
"version": "8.0.0",
4+
"kibanaVersion": "kibana",
5+
"server": false,
6+
"ui": true,
7+
"requiredPlugins": ["globalSearch"],
8+
"optionalPlugins": [],
9+
"configPath": ["xpack", "global_search_providers"]
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { PluginInitializer } from 'src/core/public';
8+
import { GlobalSearchProvidersPlugin, GlobalSearchProvidersPluginSetupDeps } from './plugin';
9+
10+
export const plugin: PluginInitializer<{}, {}, GlobalSearchProvidersPluginSetupDeps, {}> = () =>
11+
new GlobalSearchProvidersPlugin();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { coreMock } from '../../../../src/core/public/mocks';
8+
import { globalSearchPluginMock } from '../../global_search/public/mocks';
9+
import { GlobalSearchProvidersPlugin } from './plugin';
10+
11+
describe('GlobalSearchProvidersPlugin', () => {
12+
let plugin: GlobalSearchProvidersPlugin;
13+
let globalSearchSetup: ReturnType<typeof globalSearchPluginMock.createSetupContract>;
14+
15+
beforeEach(() => {
16+
globalSearchSetup = globalSearchPluginMock.createSetupContract();
17+
plugin = new GlobalSearchProvidersPlugin();
18+
});
19+
20+
describe('#setup', () => {
21+
it('registers the `application` result provider', () => {
22+
const coreSetup = coreMock.createSetup();
23+
plugin.setup(coreSetup, { globalSearch: globalSearchSetup });
24+
25+
expect(globalSearchSetup.registerResultProvider).toHaveBeenCalledTimes(1);
26+
expect(globalSearchSetup.registerResultProvider).toHaveBeenCalledWith(
27+
expect.objectContaining({
28+
id: 'application',
29+
})
30+
);
31+
});
32+
});
33+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { CoreSetup, Plugin } from 'src/core/public';
8+
import { GlobalSearchPluginSetup } from '../../global_search/public';
9+
import { createApplicationResultProvider } from './providers';
10+
11+
export interface GlobalSearchProvidersPluginSetupDeps {
12+
globalSearch: GlobalSearchPluginSetup;
13+
}
14+
15+
export class GlobalSearchProvidersPlugin
16+
implements Plugin<{}, {}, GlobalSearchProvidersPluginSetupDeps, {}> {
17+
setup(
18+
{ getStartServices }: CoreSetup<{}, {}>,
19+
{ globalSearch }: GlobalSearchProvidersPluginSetupDeps
20+
) {
21+
const applicationPromise = getStartServices().then(([core]) => core.application);
22+
globalSearch.registerResultProvider(createApplicationResultProvider(applicationPromise));
23+
return {};
24+
}
25+
26+
start() {
27+
return {};
28+
}
29+
}

0 commit comments

Comments
 (0)