mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* remove client side context * update docs * fix tests Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
bb836252f6
commit
f90e4d3018
63 changed files with 60 additions and 1133 deletions
|
@ -25,7 +25,7 @@ export interface App<HistoryLocationState = unknown>
|
|||
| [icon](./kibana-plugin-core-public.app.icon.md) | <code>string</code> | A URL to an image file used as an icon. Used as a fallback if <code>euiIconType</code> is not provided. |
|
||||
| [id](./kibana-plugin-core-public.app.id.md) | <code>string</code> | The unique identifier of the application |
|
||||
| [meta](./kibana-plugin-core-public.app.meta.md) | <code>AppMeta</code> | Meta data for an application that represent additional information for the app. See [AppMeta](./kibana-plugin-core-public.appmeta.md) |
|
||||
| [mount](./kibana-plugin-core-public.app.mount.md) | <code>AppMount<HistoryLocationState> | AppMountDeprecated<HistoryLocationState></code> | A mount function called when the user navigates to this app's route. May have signature of [AppMount](./kibana-plugin-core-public.appmount.md) or [AppMountDeprecated](./kibana-plugin-core-public.appmountdeprecated.md)<!-- -->. |
|
||||
| [mount](./kibana-plugin-core-public.app.mount.md) | <code>AppMount<HistoryLocationState></code> | A mount function called when the user navigates to this app's route. |
|
||||
| [navLinkStatus](./kibana-plugin-core-public.app.navlinkstatus.md) | <code>AppNavLinkStatus</code> | The initial status of the application's navLink. Defaulting to <code>visible</code> if <code>status</code> is <code>accessible</code> and <code>hidden</code> if status is <code>inaccessible</code> See [AppNavLinkStatus](./kibana-plugin-core-public.appnavlinkstatus.md) |
|
||||
| [order](./kibana-plugin-core-public.app.order.md) | <code>number</code> | An ordinal used to sort nav links relative to one another for display. |
|
||||
| [status](./kibana-plugin-core-public.app.status.md) | <code>AppStatus</code> | The initial status of the application. Defaulting to <code>accessible</code> |
|
||||
|
|
|
@ -4,15 +4,10 @@
|
|||
|
||||
## App.mount property
|
||||
|
||||
A mount function called when the user navigates to this app's route. May have signature of [AppMount](./kibana-plugin-core-public.appmount.md) or [AppMountDeprecated](./kibana-plugin-core-public.appmountdeprecated.md)<!-- -->.
|
||||
A mount function called when the user navigates to this app's route.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
mount: AppMount<HistoryLocationState> | AppMountDeprecated<HistoryLocationState>;
|
||||
mount: AppMount<HistoryLocationState>;
|
||||
```
|
||||
|
||||
## Remarks
|
||||
|
||||
When function has two arguments, it will be called with a [context](./kibana-plugin-core-public.appmountcontext.md) as the first argument. This behavior is \*\*deprecated\*\*, and consumers should instead use [CoreSetup.getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md)<!-- -->.
|
||||
|
||||
|
|
|
@ -17,5 +17,4 @@ export interface ApplicationSetup
|
|||
| --- | --- |
|
||||
| [register(app)](./kibana-plugin-core-public.applicationsetup.register.md) | Register an mountable application to the system. |
|
||||
| [registerAppUpdater(appUpdater$)](./kibana-plugin-core-public.applicationsetup.registerappupdater.md) | Register an application updater that can be used to change the [AppUpdatableFields](./kibana-plugin-core-public.appupdatablefields.md) fields of all applications at runtime.<!-- -->This is meant to be used by plugins that needs to updates the whole list of applications. To only updates a specific application, use the <code>updater$</code> property of the registered application instead. |
|
||||
| [registerMountContext(contextName, provider)](./kibana-plugin-core-public.applicationsetup.registermountcontext.md) | Register a context provider for application mounting. Will only be available to applications that depend on the plugin that registered this context. Deprecated, use [CoreSetup.getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md)<!-- -->. |
|
||||
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [ApplicationSetup](./kibana-plugin-core-public.applicationsetup.md) > [registerMountContext](./kibana-plugin-core-public.applicationsetup.registermountcontext.md)
|
||||
|
||||
## ApplicationSetup.registerMountContext() method
|
||||
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
>
|
||||
|
||||
Register a context provider for application mounting. Will only be available to applications that depend on the plugin that registered this context. Deprecated, use [CoreSetup.getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md)<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
registerMountContext<T extends keyof AppMountContext>(contextName: T, provider: IContextProvider<AppMountDeprecated, T>): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| contextName | <code>T</code> | The key of [AppMountContext](./kibana-plugin-core-public.appmountcontext.md) this provider's return value should be attached to. |
|
||||
| provider | <code>IContextProvider<AppMountDeprecated, T></code> | A [IContextProvider](./kibana-plugin-core-public.icontextprovider.md) function |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
`void`
|
||||
|
|
@ -26,5 +26,4 @@ export interface ApplicationStart
|
|||
| [getUrlForApp(appId, options)](./kibana-plugin-core-public.applicationstart.geturlforapp.md) | Returns the absolute path (or URL) to a given app, including the global base path.<!-- -->By default, it returns the absolute path of the application (e.g <code>/basePath/app/my-app</code>). Use the <code>absolute</code> option to generate an absolute url instead (e.g <code>http://host:port/basePath/app/my-app</code>)<!-- -->Note that when generating absolute urls, the origin (protocol, host and port) are determined from the browser's current location. |
|
||||
| [navigateToApp(appId, options)](./kibana-plugin-core-public.applicationstart.navigatetoapp.md) | Navigate to a given app |
|
||||
| [navigateToUrl(url)](./kibana-plugin-core-public.applicationstart.navigatetourl.md) | Navigate to given URL in a SPA friendly way when possible (when the URL will redirect to a valid application within the current basePath).<!-- -->The method resolves pathnames the same way browsers do when resolving a <code><a href></code> value. The provided <code>url</code> can be: - an absolute URL - an absolute path - a path relative to the current URL (window.location.href)<!-- -->If all these criteria are true for the given URL: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The resolved pathname of the provided URL/path starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's <code>appRoute</code> configuration)<!-- -->Then a SPA navigation will be performed using <code>navigateToApp</code> using the corresponding application and path. Otherwise, fallback to a full page reload to navigate to the url using <code>window.location.assign</code> |
|
||||
| [registerMountContext(contextName, provider)](./kibana-plugin-core-public.applicationstart.registermountcontext.md) | Register a context provider for application mounting. Will only be available to applications that depend on the plugin that registered this context. Deprecated, use [CoreSetup.getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md)<!-- -->. |
|
||||
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [ApplicationStart](./kibana-plugin-core-public.applicationstart.md) > [registerMountContext](./kibana-plugin-core-public.applicationstart.registermountcontext.md)
|
||||
|
||||
## ApplicationStart.registerMountContext() method
|
||||
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
>
|
||||
|
||||
Register a context provider for application mounting. Will only be available to applications that depend on the plugin that registered this context. Deprecated, use [CoreSetup.getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md)<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
registerMountContext<T extends keyof AppMountContext>(contextName: T, provider: IContextProvider<AppMountDeprecated, T>): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| contextName | <code>T</code> | The key of [AppMountContext](./kibana-plugin-core-public.appmountcontext.md) this provider's return value should be attached to. |
|
||||
| provider | <code>IContextProvider<AppMountDeprecated, T></code> | A [IContextProvider](./kibana-plugin-core-public.icontextprovider.md) function |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
`void`
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [AppMountContext](./kibana-plugin-core-public.appmountcontext.md) > [core](./kibana-plugin-core-public.appmountcontext.core.md)
|
||||
|
||||
## AppMountContext.core property
|
||||
|
||||
Core service APIs available to mounted applications.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
core: {
|
||||
application: Pick<ApplicationStart, 'capabilities' | 'navigateToApp'>;
|
||||
chrome: ChromeStart;
|
||||
docLinks: DocLinksStart;
|
||||
http: HttpStart;
|
||||
i18n: I18nStart;
|
||||
notifications: NotificationsStart;
|
||||
overlays: OverlayStart;
|
||||
savedObjects: SavedObjectsStart;
|
||||
uiSettings: IUiSettingsClient;
|
||||
injectedMetadata: {
|
||||
getInjectedVar: (name: string, defaultValue?: any) => unknown;
|
||||
};
|
||||
};
|
||||
```
|
|
@ -1,24 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [AppMountContext](./kibana-plugin-core-public.appmountcontext.md)
|
||||
|
||||
## AppMountContext interface
|
||||
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
>
|
||||
|
||||
The context object received when applications are mounted to the DOM. Deprecated, use [CoreSetup.getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md)<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface AppMountContext
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [core](./kibana-plugin-core-public.appmountcontext.core.md) | <code>{</code><br/><code> application: Pick<ApplicationStart, 'capabilities' | 'navigateToApp'>;</code><br/><code> chrome: ChromeStart;</code><br/><code> docLinks: DocLinksStart;</code><br/><code> http: HttpStart;</code><br/><code> i18n: I18nStart;</code><br/><code> notifications: NotificationsStart;</code><br/><code> overlays: OverlayStart;</code><br/><code> savedObjects: SavedObjectsStart;</code><br/><code> uiSettings: IUiSettingsClient;</code><br/><code> injectedMetadata: {</code><br/><code> getInjectedVar: (name: string, defaultValue?: any) => unknown;</code><br/><code> };</code><br/><code> }</code> | Core service APIs available to mounted applications. |
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [AppMountDeprecated](./kibana-plugin-core-public.appmountdeprecated.md)
|
||||
|
||||
## AppMountDeprecated type
|
||||
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
>
|
||||
|
||||
A mount function called when the user navigates to this app's route.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type AppMountDeprecated<HistoryLocationState = unknown> = (context: AppMountContext, params: AppMountParameters<HistoryLocationState>) => AppUnmount | Promise<AppUnmount>;
|
||||
```
|
||||
|
||||
## Remarks
|
||||
|
||||
When function has two arguments, it will be called with a [context](./kibana-plugin-core-public.appmountcontext.md) as the first argument. This behavior is \*\*deprecated\*\*, and consumers should instead use [CoreSetup.getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md)<!-- -->.
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [ContextSetup](./kibana-plugin-core-public.contextsetup.md) > [createContextContainer](./kibana-plugin-core-public.contextsetup.createcontextcontainer.md)
|
||||
|
||||
## ContextSetup.createContextContainer() method
|
||||
|
||||
Creates a new [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md) for a service owner.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
createContextContainer<THandler extends HandlerFunction<any>>(): IContextContainer<THandler>;
|
||||
```
|
||||
<b>Returns:</b>
|
||||
|
||||
`IContextContainer<THandler>`
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [ContextSetup](./kibana-plugin-core-public.contextsetup.md)
|
||||
|
||||
## ContextSetup interface
|
||||
|
||||
An object that handles registration of context providers and configuring handlers with context.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface ContextSetup
|
||||
```
|
||||
|
||||
## Remarks
|
||||
|
||||
A [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md) can be used by any Core service or plugin (known as the "service owner") which wishes to expose APIs in a handler function. The container object will manage registering context providers and configuring a handler with all of the contexts that should be exposed to the handler's plugin. This is dependent on the dependencies that the handler's plugin declares.
|
||||
|
||||
Contexts providers are executed in the order they were registered. Each provider gets access to context values provided by any plugins that it depends on.
|
||||
|
||||
In order to configure a handler with context, you must call the [IContextContainer.createHandler()](./kibana-plugin-core-public.icontextcontainer.createhandler.md) function and use the returned handler which will automatically build a context object when called.
|
||||
|
||||
When registering context or creating handlers, the \_calling plugin's opaque id\_ must be provided. This id is passed in via the plugin's initializer and can be accessed from the [PluginInitializerContext.opaqueId](./kibana-plugin-core-public.plugininitializercontext.opaqueid.md) Note this should NOT be the context service owner's id, but the plugin that is actually registering the context or handler.
|
||||
|
||||
```ts
|
||||
// Correct
|
||||
class MyPlugin {
|
||||
private readonly handlers = new Map();
|
||||
|
||||
setup(core) {
|
||||
this.contextContainer = core.context.createContextContainer();
|
||||
return {
|
||||
registerContext(pluginOpaqueId, contextName, provider) {
|
||||
this.contextContainer.registerContext(pluginOpaqueId, contextName, provider);
|
||||
},
|
||||
registerRoute(pluginOpaqueId, path, handler) {
|
||||
this.handlers.set(
|
||||
path,
|
||||
this.contextContainer.createHandler(pluginOpaqueId, handler)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Incorrect
|
||||
class MyPlugin {
|
||||
private readonly handlers = new Map();
|
||||
|
||||
constructor(private readonly initContext: PluginInitializerContext) {}
|
||||
|
||||
setup(core) {
|
||||
this.contextContainer = core.context.createContextContainer();
|
||||
return {
|
||||
registerContext(contextName, provider) {
|
||||
// BUG!
|
||||
// This would leak this context to all handlers rather that only plugins that depend on the calling plugin.
|
||||
this.contextContainer.registerContext(this.initContext.opaqueId, contextName, provider);
|
||||
},
|
||||
registerRoute(path, handler) {
|
||||
this.handlers.set(
|
||||
path,
|
||||
// BUG!
|
||||
// This handler will not receive any contexts provided by other dependencies of the calling plugin.
|
||||
this.contextContainer.createHandler(this.initContext.opaqueId, handler)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
Say we're creating a plugin for rendering visualizations that allows new rendering methods to be registered. If we want to offer context to these rendering methods, we can leverage the ContextService to manage these contexts.
|
||||
|
||||
```ts
|
||||
export interface VizRenderContext {
|
||||
core: {
|
||||
i18n: I18nStart;
|
||||
uiSettings: IUiSettingsClient;
|
||||
}
|
||||
[contextName: string]: unknown;
|
||||
}
|
||||
|
||||
export type VizRenderer = (context: VizRenderContext, domElement: HTMLElement) => () => void;
|
||||
// When a renderer is bound via `contextContainer.createHandler` this is the type that will be returned.
|
||||
type BoundVizRenderer = (domElement: HTMLElement) => () => void;
|
||||
|
||||
class VizRenderingPlugin {
|
||||
private readonly contextContainer?: IContextContainer<VizRenderer>;
|
||||
private readonly vizRenderers = new Map<string, BoundVizRenderer>();
|
||||
|
||||
constructor(private readonly initContext: PluginInitializerContext) {}
|
||||
|
||||
setup(core) {
|
||||
this.contextContainer = core.context.createContextContainer();
|
||||
|
||||
return {
|
||||
registerContext: this.contextContainer.registerContext,
|
||||
registerVizRenderer: (plugin: PluginOpaqueId, renderMethod: string, renderer: VizTypeRenderer) =>
|
||||
this.vizRenderers.set(renderMethod, this.contextContainer.createHandler(plugin, renderer)),
|
||||
};
|
||||
}
|
||||
|
||||
start(core) {
|
||||
// Register the core context available to all renderers. Use the VizRendererContext's opaqueId as the first arg.
|
||||
this.contextContainer.registerContext(this.initContext.opaqueId, 'core', () => ({
|
||||
i18n: core.i18n,
|
||||
uiSettings: core.uiSettings
|
||||
}));
|
||||
|
||||
return {
|
||||
registerContext: this.contextContainer.registerContext,
|
||||
|
||||
renderVizualization: (renderMethod: string, domElement: HTMLElement) => {
|
||||
if (!this.vizRenderer.has(renderMethod)) {
|
||||
throw new Error(`Render method '${renderMethod}' has not been registered`);
|
||||
}
|
||||
|
||||
// The handler can now be called directly with only an `HTMLElement` and will automatically
|
||||
// have a new `context` object created and populated by the context container.
|
||||
const handler = this.vizRenderers.get(renderMethod)
|
||||
return handler(domElement);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
| Method | Description |
|
||||
| --- | --- |
|
||||
| [createContextContainer()](./kibana-plugin-core-public.contextsetup.createcontextcontainer.md) | Creates a new [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md) for a service owner. |
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [CoreSetup](./kibana-plugin-core-public.coresetup.md) > [context](./kibana-plugin-core-public.coresetup.context.md)
|
||||
|
||||
## CoreSetup.context property
|
||||
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
>
|
||||
|
||||
[ContextSetup](./kibana-plugin-core-public.contextsetup.md)
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
context: ContextSetup;
|
||||
```
|
|
@ -17,7 +17,6 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
|
|||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [application](./kibana-plugin-core-public.coresetup.application.md) | <code>ApplicationSetup</code> | [ApplicationSetup](./kibana-plugin-core-public.applicationsetup.md) |
|
||||
| [context](./kibana-plugin-core-public.coresetup.context.md) | <code>ContextSetup</code> | [ContextSetup](./kibana-plugin-core-public.contextsetup.md) |
|
||||
| [fatalErrors](./kibana-plugin-core-public.coresetup.fatalerrors.md) | <code>FatalErrorsSetup</code> | [FatalErrorsSetup](./kibana-plugin-core-public.fatalerrorssetup.md) |
|
||||
| [getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md) | <code>StartServicesAccessor<TPluginsStart, TStart></code> | [StartServicesAccessor](./kibana-plugin-core-public.startservicesaccessor.md) |
|
||||
| [http](./kibana-plugin-core-public.coresetup.http.md) | <code>HttpSetup</code> | [HttpSetup](./kibana-plugin-core-public.httpsetup.md) |
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [HandlerContextType](./kibana-plugin-core-public.handlercontexttype.md)
|
||||
|
||||
## HandlerContextType type
|
||||
|
||||
Extracts the type of the first argument of a [HandlerFunction](./kibana-plugin-core-public.handlerfunction.md) to represent the type of the context.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type HandlerContextType<T extends HandlerFunction<any>> = T extends HandlerFunction<infer U> ? U : never;
|
||||
```
|
|
@ -1,13 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [HandlerFunction](./kibana-plugin-core-public.handlerfunction.md)
|
||||
|
||||
## HandlerFunction type
|
||||
|
||||
A function that accepts a context object and an optional number of additional arguments. Used for the generic types in [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md)
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type HandlerFunction<T extends object> = (context: T, ...args: any[]) => any;
|
||||
```
|
|
@ -1,13 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [HandlerParameters](./kibana-plugin-core-public.handlerparameters.md)
|
||||
|
||||
## HandlerParameters type
|
||||
|
||||
Extracts the types of the additional arguments of a [HandlerFunction](./kibana-plugin-core-public.handlerfunction.md)<!-- -->, excluding the [HandlerContextType](./kibana-plugin-core-public.handlercontexttype.md)<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type HandlerParameters<T extends HandlerFunction<any>> = T extends (context: any, ...args: infer U) => any ? U : never;
|
||||
```
|
|
@ -1,27 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md) > [createHandler](./kibana-plugin-core-public.icontextcontainer.createhandler.md)
|
||||
|
||||
## IContextContainer.createHandler() method
|
||||
|
||||
Create a new handler function pre-wired to context for the plugin.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
createHandler(pluginOpaqueId: PluginOpaqueId, handler: THandler): (...rest: HandlerParameters<THandler>) => ShallowPromise<ReturnType<THandler>>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| pluginOpaqueId | <code>PluginOpaqueId</code> | The plugin opaque ID for the plugin that registers this handler. |
|
||||
| handler | <code>THandler</code> | Handler function to pass context object to. |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
`(...rest: HandlerParameters<THandler>) => ShallowPromise<ReturnType<THandler>>`
|
||||
|
||||
A function that takes `THandlerParameters`<!-- -->, calls `handler` with a new context, and returns a Promise of the `handler` return value.
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md)
|
||||
|
||||
## IContextContainer interface
|
||||
|
||||
An object that handles registration of context providers and configuring handlers with context.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface IContextContainer<THandler extends HandlerFunction<any>>
|
||||
```
|
||||
|
||||
## Remarks
|
||||
|
||||
A [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md) can be used by any Core service or plugin (known as the "service owner") which wishes to expose APIs in a handler function. The container object will manage registering context providers and configuring a handler with all of the contexts that should be exposed to the handler's plugin. This is dependent on the dependencies that the handler's plugin declares.
|
||||
|
||||
Contexts providers are executed in the order they were registered. Each provider gets access to context values provided by any plugins that it depends on.
|
||||
|
||||
In order to configure a handler with context, you must call the [IContextContainer.createHandler()](./kibana-plugin-core-public.icontextcontainer.createhandler.md) function and use the returned handler which will automatically build a context object when called.
|
||||
|
||||
When registering context or creating handlers, the \_calling plugin's opaque id\_ must be provided. This id is passed in via the plugin's initializer and can be accessed from the [PluginInitializerContext.opaqueId](./kibana-plugin-core-public.plugininitializercontext.opaqueid.md) Note this should NOT be the context service owner's id, but the plugin that is actually registering the context or handler.
|
||||
|
||||
```ts
|
||||
// Correct
|
||||
class MyPlugin {
|
||||
private readonly handlers = new Map();
|
||||
|
||||
setup(core) {
|
||||
this.contextContainer = core.context.createContextContainer();
|
||||
return {
|
||||
registerContext(pluginOpaqueId, contextName, provider) {
|
||||
this.contextContainer.registerContext(pluginOpaqueId, contextName, provider);
|
||||
},
|
||||
registerRoute(pluginOpaqueId, path, handler) {
|
||||
this.handlers.set(
|
||||
path,
|
||||
this.contextContainer.createHandler(pluginOpaqueId, handler)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Incorrect
|
||||
class MyPlugin {
|
||||
private readonly handlers = new Map();
|
||||
|
||||
constructor(private readonly initContext: PluginInitializerContext) {}
|
||||
|
||||
setup(core) {
|
||||
this.contextContainer = core.context.createContextContainer();
|
||||
return {
|
||||
registerContext(contextName, provider) {
|
||||
// BUG!
|
||||
// This would leak this context to all handlers rather that only plugins that depend on the calling plugin.
|
||||
this.contextContainer.registerContext(this.initContext.opaqueId, contextName, provider);
|
||||
},
|
||||
registerRoute(path, handler) {
|
||||
this.handlers.set(
|
||||
path,
|
||||
// BUG!
|
||||
// This handler will not receive any contexts provided by other dependencies of the calling plugin.
|
||||
this.contextContainer.createHandler(this.initContext.opaqueId, handler)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
| Method | Description |
|
||||
| --- | --- |
|
||||
| [createHandler(pluginOpaqueId, handler)](./kibana-plugin-core-public.icontextcontainer.createhandler.md) | Create a new handler function pre-wired to context for the plugin. |
|
||||
| [registerContext(pluginOpaqueId, contextName, provider)](./kibana-plugin-core-public.icontextcontainer.registercontext.md) | Register a new context provider. |
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md) > [registerContext](./kibana-plugin-core-public.icontextcontainer.registercontext.md)
|
||||
|
||||
## IContextContainer.registerContext() method
|
||||
|
||||
Register a new context provider.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
registerContext<TContextName extends keyof HandlerContextType<THandler>>(pluginOpaqueId: PluginOpaqueId, contextName: TContextName, provider: IContextProvider<THandler, TContextName>): this;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| pluginOpaqueId | <code>PluginOpaqueId</code> | The plugin opaque ID for the plugin that registers this context. |
|
||||
| contextName | <code>TContextName</code> | The key of the <code>TContext</code> object this provider supplies the value for. |
|
||||
| provider | <code>IContextProvider<THandler, TContextName></code> | A [IContextProvider](./kibana-plugin-core-public.icontextprovider.md) to be called each time a new context is created. |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
`this`
|
||||
|
||||
The [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md) for method chaining.
|
||||
|
||||
## Remarks
|
||||
|
||||
The value (or resolved Promise value) returned by the `provider` function will be attached to the context object on the key specified by `contextName`<!-- -->.
|
||||
|
||||
Throws an exception if more than one provider is registered for the same `contextName`<!-- -->.
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [IContextProvider](./kibana-plugin-core-public.icontextprovider.md)
|
||||
|
||||
## IContextProvider type
|
||||
|
||||
A function that returns a context value for a specific key of given context type.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type IContextProvider<THandler extends HandlerFunction<any>, TContextName extends keyof HandlerContextType<THandler>> = (context: PartialExceptFor<HandlerContextType<THandler>, 'core'>, ...rest: HandlerParameters<THandler>) => Promise<HandlerContextType<THandler>[TContextName]> | HandlerContextType<THandler>[TContextName];
|
||||
```
|
||||
|
||||
## Remarks
|
||||
|
||||
This function will be called each time a new context is built for a handler invocation.
|
||||
|
|
@ -38,7 +38,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
|
|||
| [ApplicationSetup](./kibana-plugin-core-public.applicationsetup.md) | |
|
||||
| [ApplicationStart](./kibana-plugin-core-public.applicationstart.md) | |
|
||||
| [AppMeta](./kibana-plugin-core-public.appmeta.md) | Input type for meta data for an application.<!-- -->Meta fields include <code>keywords</code> and <code>searchDeepLinks</code> Keywords is an array of string with which to associate the app, must include at least one unique string as an array. <code>searchDeepLinks</code> is an array of links that represent secondary in-app locations for the app. |
|
||||
| [AppMountContext](./kibana-plugin-core-public.appmountcontext.md) | The context object received when applications are mounted to the DOM. Deprecated, use [CoreSetup.getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md)<!-- -->. |
|
||||
| [AppMountParameters](./kibana-plugin-core-public.appmountparameters.md) | |
|
||||
| [Capabilities](./kibana-plugin-core-public.capabilities.md) | The read-only set of capabilities available for the current UI session. Capabilities are simple key-value pairs of (string, boolean), where the string denotes the capability ID, and the boolean is a flag indicating if the capability is enabled or disabled. |
|
||||
| [ChromeBadge](./kibana-plugin-core-public.chromebadge.md) | |
|
||||
|
@ -56,7 +55,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
|
|||
| [ChromeRecentlyAccessed](./kibana-plugin-core-public.chromerecentlyaccessed.md) | [APIs](./kibana-plugin-core-public.chromerecentlyaccessed.md) for recently accessed history. |
|
||||
| [ChromeRecentlyAccessedHistoryItem](./kibana-plugin-core-public.chromerecentlyaccessedhistoryitem.md) | |
|
||||
| [ChromeStart](./kibana-plugin-core-public.chromestart.md) | ChromeStart allows plugins to customize the global chrome header UI and enrich the UX with additional information about the current location of the browser. |
|
||||
| [ContextSetup](./kibana-plugin-core-public.contextsetup.md) | An object that handles registration of context providers and configuring handlers with context. |
|
||||
| [CoreSetup](./kibana-plugin-core-public.coresetup.md) | Core services exposed to the <code>Plugin</code> setup lifecycle |
|
||||
| [CoreStart](./kibana-plugin-core-public.corestart.md) | Core services exposed to the <code>Plugin</code> start lifecycle |
|
||||
| [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md) | |
|
||||
|
@ -77,7 +75,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
|
|||
| [I18nStart](./kibana-plugin-core-public.i18nstart.md) | I18nStart.Context is required by any localizable React component from @<!-- -->kbn/i18n and @<!-- -->elastic/eui packages and is supposed to be used as the topmost component for any i18n-compatible React tree. |
|
||||
| [IAnonymousPaths](./kibana-plugin-core-public.ianonymouspaths.md) | APIs for denoting paths as not requiring authentication |
|
||||
| [IBasePath](./kibana-plugin-core-public.ibasepath.md) | APIs for manipulating the basePath on URL segments. |
|
||||
| [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md) | An object that handles registration of context providers and configuring handlers with context. |
|
||||
| [IExternalUrl](./kibana-plugin-core-public.iexternalurl.md) | APIs for working with external URLs. |
|
||||
| [IExternalUrlPolicy](./kibana-plugin-core-public.iexternalurlpolicy.md) | A policy describing whether access to an external destination is allowed. |
|
||||
| [IHttpFetchError](./kibana-plugin-core-public.ihttpfetcherror.md) | |
|
||||
|
@ -144,7 +141,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
|
|||
| [AppLeaveAction](./kibana-plugin-core-public.appleaveaction.md) | Possible actions to return from a [AppLeaveHandler](./kibana-plugin-core-public.appleavehandler.md)<!-- -->See [AppLeaveConfirmAction](./kibana-plugin-core-public.appleaveconfirmaction.md) and [AppLeaveDefaultAction](./kibana-plugin-core-public.appleavedefaultaction.md) |
|
||||
| [AppLeaveHandler](./kibana-plugin-core-public.appleavehandler.md) | A handler that will be executed before leaving the application, either when going to another application or when closing the browser tab or manually changing the url. Should return <code>confirm</code> to to prompt a message to the user before leaving the page, or <code>default</code> to keep the default behavior (doing nothing).<!-- -->See [AppMountParameters](./kibana-plugin-core-public.appmountparameters.md) for detailed usage examples. |
|
||||
| [AppMount](./kibana-plugin-core-public.appmount.md) | A mount function called when the user navigates to this app's route. |
|
||||
| [AppMountDeprecated](./kibana-plugin-core-public.appmountdeprecated.md) | A mount function called when the user navigates to this app's route. |
|
||||
| [AppSearchDeepLink](./kibana-plugin-core-public.appsearchdeeplink.md) | Input type for registering secondary in-app locations for an application.<!-- -->Deep links must include at least one of <code>path</code> or <code>searchDeepLinks</code>. A deep link that does not have a <code>path</code> represents a topological level in the application's hierarchy, but does not have a destination URL that is user-accessible. |
|
||||
| [AppUnmount](./kibana-plugin-core-public.appunmount.md) | A function called when an application should be unmounted from the page. This function should be synchronous. |
|
||||
| [AppUpdatableFields](./kibana-plugin-core-public.appupdatablefields.md) | Defines the list of fields that can be updated via an [AppUpdater](./kibana-plugin-core-public.appupdater.md)<!-- -->. |
|
||||
|
@ -154,11 +150,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
|
|||
| [ChromeHelpExtensionMenuLink](./kibana-plugin-core-public.chromehelpextensionmenulink.md) | |
|
||||
| [ChromeNavLinkUpdateableFields](./kibana-plugin-core-public.chromenavlinkupdateablefields.md) | |
|
||||
| [FatalErrorsStart](./kibana-plugin-core-public.fatalerrorsstart.md) | FatalErrors stop the Kibana Public Core and displays a fatal error screen with details about the Kibana build and the error. |
|
||||
| [HandlerContextType](./kibana-plugin-core-public.handlercontexttype.md) | Extracts the type of the first argument of a [HandlerFunction](./kibana-plugin-core-public.handlerfunction.md) to represent the type of the context. |
|
||||
| [HandlerFunction](./kibana-plugin-core-public.handlerfunction.md) | A function that accepts a context object and an optional number of additional arguments. Used for the generic types in [IContextContainer](./kibana-plugin-core-public.icontextcontainer.md) |
|
||||
| [HandlerParameters](./kibana-plugin-core-public.handlerparameters.md) | Extracts the types of the additional arguments of a [HandlerFunction](./kibana-plugin-core-public.handlerfunction.md)<!-- -->, excluding the [HandlerContextType](./kibana-plugin-core-public.handlercontexttype.md)<!-- -->. |
|
||||
| [HttpStart](./kibana-plugin-core-public.httpstart.md) | See [HttpSetup](./kibana-plugin-core-public.httpsetup.md) |
|
||||
| [IContextProvider](./kibana-plugin-core-public.icontextprovider.md) | A function that returns a context value for a specific key of given context type. |
|
||||
| [IToasts](./kibana-plugin-core-public.itoasts.md) | Methods for adding and removing global toast messages. See [ToastsApi](./kibana-plugin-core-public.toastsapi.md)<!-- -->. |
|
||||
| [MountPoint](./kibana-plugin-core-public.mountpoint.md) | A function that should mount DOM content inside the provided container element and return a handler to unmount it. |
|
||||
| [NavType](./kibana-plugin-core-public.navtype.md) | |
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
| [IndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.md) | |
|
||||
| [OptionedParamType](./kibana-plugin-plugins-data-server.optionedparamtype.md) | |
|
||||
| [Plugin](./kibana-plugin-plugins-data-server.plugin.md) | |
|
||||
| [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) | The OSS session service. See data\_enhanced in X-Pack for the background session service. |
|
||||
| [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) | The OSS session service. See data\_enhanced in X-Pack for the search session service. |
|
||||
|
||||
## Enumerations
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
## SessionService class
|
||||
|
||||
The OSS session service. See data\_enhanced in X-Pack for the background session service.
|
||||
The OSS session service. See data\_enhanced in X-Pack for the search session service.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import { EmbeddableStart } from '../../../src/plugins/embeddable/public';
|
|||
import { UiActionsStart } from '../../../src/plugins/ui_actions/public';
|
||||
import { Start as InspectorStartContract } from '../../../src/plugins/inspector/public';
|
||||
import {
|
||||
AppMountContext,
|
||||
AppMountParameters,
|
||||
CoreStart,
|
||||
SavedObjectsStart,
|
||||
|
@ -47,7 +46,7 @@ interface PageDef {
|
|||
}
|
||||
|
||||
type NavProps = RouteComponentProps & {
|
||||
navigateToApp: AppMountContext['core']['application']['navigateToApp'];
|
||||
navigateToApp: CoreStart['application']['navigateToApp'];
|
||||
pages: PageDef[];
|
||||
};
|
||||
|
||||
|
|
|
@ -34,13 +34,11 @@ import { ApplicationServiceContract } from './test_types';
|
|||
const createSetupContractMock = (): jest.Mocked<ApplicationSetup> => ({
|
||||
register: jest.fn(),
|
||||
registerAppUpdater: jest.fn(),
|
||||
registerMountContext: jest.fn(),
|
||||
});
|
||||
|
||||
const createInternalSetupContractMock = (): jest.Mocked<InternalApplicationSetup> => ({
|
||||
register: jest.fn(),
|
||||
registerAppUpdater: jest.fn(),
|
||||
registerMountContext: jest.fn(),
|
||||
});
|
||||
|
||||
const createStartContractMock = (): jest.Mocked<ApplicationStart> => {
|
||||
|
@ -53,7 +51,6 @@ const createStartContractMock = (): jest.Mocked<ApplicationStart> => {
|
|||
navigateToApp: jest.fn(),
|
||||
navigateToUrl: jest.fn(),
|
||||
getUrlForApp: jest.fn(),
|
||||
registerMountContext: jest.fn(),
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -91,7 +88,6 @@ const createInternalStartContractMock = (): jest.Mocked<InternalApplicationStart
|
|||
getUrlForApp: jest.fn(),
|
||||
navigateToApp: jest.fn().mockImplementation((appId) => currentAppId$.next(appId)),
|
||||
navigateToUrl: jest.fn(),
|
||||
registerMountContext: jest.fn(),
|
||||
history: createHistoryMock(),
|
||||
};
|
||||
};
|
||||
|
|
|
@ -28,7 +28,6 @@ import { BehaviorSubject, Subject } from 'rxjs';
|
|||
import { bufferCount, take, takeUntil } from 'rxjs/operators';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
|
||||
import { contextServiceMock } from '../context/context_service.mock';
|
||||
import { httpServiceMock } from '../http/http_service.mock';
|
||||
import { overlayServiceMock } from '../overlays/overlay_service.mock';
|
||||
import { MockLifecycle } from './test_types';
|
||||
|
@ -54,7 +53,6 @@ describe('#setup()', () => {
|
|||
const http = httpServiceMock.createSetupContract({ basePath: '/base-path' });
|
||||
setupDeps = {
|
||||
http,
|
||||
context: contextServiceMock.createSetupContract(),
|
||||
redirectTo: jest.fn(),
|
||||
};
|
||||
startDeps = { http, overlays: overlayServiceMock.createStartContract() };
|
||||
|
@ -367,16 +365,6 @@ describe('#setup()', () => {
|
|||
MockHistory.push.mockClear();
|
||||
});
|
||||
});
|
||||
|
||||
it("`registerMountContext` calls context container's registerContext", () => {
|
||||
const { registerMountContext } = service.setup(setupDeps);
|
||||
const container = setupDeps.context.createContextContainer.mock.results[0].value;
|
||||
const pluginId = Symbol();
|
||||
|
||||
const appMount = () => () => undefined;
|
||||
registerMountContext(pluginId, 'test' as any, appMount);
|
||||
expect(container.registerContext).toHaveBeenCalledWith(pluginId, 'test', appMount);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#start()', () => {
|
||||
|
@ -384,7 +372,6 @@ describe('#start()', () => {
|
|||
const http = httpServiceMock.createSetupContract({ basePath: '/base-path' });
|
||||
setupDeps = {
|
||||
http,
|
||||
context: contextServiceMock.createSetupContract(),
|
||||
redirectTo: jest.fn(),
|
||||
};
|
||||
startDeps = { http, overlays: overlayServiceMock.createStartContract() };
|
||||
|
@ -869,7 +856,6 @@ describe('#stop()', () => {
|
|||
const http = httpServiceMock.createSetupContract({ basePath: '/test' });
|
||||
setupDeps = {
|
||||
http,
|
||||
context: contextServiceMock.createSetupContract(),
|
||||
};
|
||||
startDeps = { http, overlays: overlayServiceMock.createStartContract() };
|
||||
service = new ApplicationService();
|
||||
|
|
|
@ -25,7 +25,6 @@ import { createBrowserHistory, History } from 'history';
|
|||
import { MountPoint } from '../types';
|
||||
import { HttpSetup, HttpStart } from '../http';
|
||||
import { OverlayStart } from '../overlays';
|
||||
import { ContextSetup, IContextContainer } from '../context';
|
||||
import { PluginOpaqueId } from '../plugins';
|
||||
import { AppRouter } from './ui';
|
||||
import { Capabilities, CapabilitiesService } from './capabilities';
|
||||
|
@ -33,7 +32,6 @@ import {
|
|||
App,
|
||||
AppLeaveHandler,
|
||||
AppMount,
|
||||
AppMountDeprecated,
|
||||
AppNavLinkStatus,
|
||||
AppStatus,
|
||||
AppUpdatableFields,
|
||||
|
@ -47,7 +45,6 @@ import { getLeaveAction, isConfirmAction } from './application_leave';
|
|||
import { appendAppPath, parseAppUrl, relativeToAbsolute, getAppInfo } from './utils';
|
||||
|
||||
interface SetupDeps {
|
||||
context: ContextSetup;
|
||||
http: HttpSetup;
|
||||
history?: History<any>;
|
||||
/** Used to redirect to external urls */
|
||||
|
@ -59,9 +56,6 @@ interface StartDeps {
|
|||
overlays: OverlayStart;
|
||||
}
|
||||
|
||||
// Mount functions with two arguments are assumed to expect deprecated `context` object.
|
||||
const isAppMountDeprecated = (mount: (...args: any[]) => any): mount is AppMountDeprecated =>
|
||||
mount.length === 2;
|
||||
function filterAvailable<T>(m: Map<string, T>, capabilities: Capabilities) {
|
||||
return new Map(
|
||||
[...m].filter(
|
||||
|
@ -107,12 +101,10 @@ export class ApplicationService {
|
|||
private stop$ = new Subject();
|
||||
private registrationClosed = false;
|
||||
private history?: History<any>;
|
||||
private mountContext?: IContextContainer<AppMountDeprecated>;
|
||||
private navigate?: (url: string, state: unknown, replace: boolean) => void;
|
||||
private redirectTo?: (url: string) => void;
|
||||
|
||||
public setup({
|
||||
context,
|
||||
http: { basePath },
|
||||
redirectTo = (path: string) => {
|
||||
window.location.assign(path);
|
||||
|
@ -128,7 +120,6 @@ export class ApplicationService {
|
|||
};
|
||||
|
||||
this.redirectTo = redirectTo;
|
||||
this.mountContext = context.createContextContainer();
|
||||
|
||||
const registerStatusUpdater = (application: string, updater$: Observable<AppUpdater>) => {
|
||||
const updaterId = Symbol();
|
||||
|
@ -144,26 +135,13 @@ export class ApplicationService {
|
|||
};
|
||||
|
||||
const wrapMount = (plugin: PluginOpaqueId, app: App<any>): AppMount => {
|
||||
let handler: AppMount;
|
||||
if (isAppMountDeprecated(app.mount)) {
|
||||
handler = this.mountContext!.createHandler(plugin, app.mount);
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`App [${app.id}] is using deprecated mount context. Use core.getStartServices() instead.`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
handler = app.mount;
|
||||
}
|
||||
return async (params) => {
|
||||
this.currentAppId$.next(app.id);
|
||||
return handler(params);
|
||||
return app.mount(params);
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
registerMountContext: this.mountContext!.registerContext,
|
||||
register: (plugin, app: App<any>) => {
|
||||
app = { appRoute: `/app/${app.id}`, ...app };
|
||||
|
||||
|
@ -202,7 +180,7 @@ export class ApplicationService {
|
|||
}
|
||||
|
||||
public async start({ http, overlays }: StartDeps): Promise<InternalApplicationStart> {
|
||||
if (!this.mountContext) {
|
||||
if (!this.redirectTo) {
|
||||
throw new Error('ApplicationService#setup() must be invoked before start.');
|
||||
}
|
||||
|
||||
|
@ -278,7 +256,6 @@ export class ApplicationService {
|
|||
takeUntil(this.stop$)
|
||||
),
|
||||
history: this.history!,
|
||||
registerMountContext: this.mountContext.registerContext,
|
||||
getUrlForApp: (
|
||||
appId,
|
||||
{ path, absolute = false }: { path?: string; absolute?: boolean } = {}
|
||||
|
|
|
@ -23,9 +23,7 @@ export { ScopedHistory } from './scoped_history';
|
|||
export {
|
||||
App,
|
||||
AppMount,
|
||||
AppMountDeprecated,
|
||||
AppUnmount,
|
||||
AppMountContext,
|
||||
AppMountParameters,
|
||||
AppStatus,
|
||||
AppNavLinkStatus,
|
||||
|
|
|
@ -24,7 +24,6 @@ import { createMemoryHistory, MemoryHistory } from 'history';
|
|||
import { createRenderer } from './utils';
|
||||
import { ApplicationService } from '../application_service';
|
||||
import { httpServiceMock } from '../../http/http_service.mock';
|
||||
import { contextServiceMock } from '../../context/context_service.mock';
|
||||
import { MockLifecycle } from '../test_types';
|
||||
import { overlayServiceMock } from '../../overlays/overlay_service.mock';
|
||||
import { AppMountParameters } from '../types';
|
||||
|
@ -53,7 +52,6 @@ describe('ApplicationService', () => {
|
|||
|
||||
setupDeps = {
|
||||
http,
|
||||
context: contextServiceMock.createSetupContract(),
|
||||
history: history as any,
|
||||
};
|
||||
startDeps = { http, overlays: overlayServiceMock.createStartContract() };
|
||||
|
|
|
@ -23,16 +23,7 @@ import { RecursiveReadonly } from '@kbn/utility-types';
|
|||
|
||||
import { MountPoint } from '../types';
|
||||
import { Capabilities } from './capabilities';
|
||||
import { ChromeStart } from '../chrome';
|
||||
import { IContextProvider } from '../context';
|
||||
import { DocLinksStart } from '../doc_links';
|
||||
import { HttpStart } from '../http';
|
||||
import { I18nStart } from '../i18n';
|
||||
import { NotificationsStart } from '../notifications';
|
||||
import { OverlayStart } from '../overlays';
|
||||
import { PluginOpaqueId } from '../plugins';
|
||||
import { IUiSettingsClient } from '../ui_settings';
|
||||
import { SavedObjectsStart } from '../saved_objects';
|
||||
import { AppCategory } from '../../types';
|
||||
import { ScopedHistory } from './scoped_history';
|
||||
|
||||
|
@ -202,14 +193,9 @@ export interface App<HistoryLocationState = unknown> {
|
|||
chromeless?: boolean;
|
||||
|
||||
/**
|
||||
* A mount function called when the user navigates to this app's route. May have signature of {@link AppMount} or
|
||||
* {@link AppMountDeprecated}.
|
||||
*
|
||||
* @remarks
|
||||
* When function has two arguments, it will be called with a {@link AppMountContext | context} as the first argument.
|
||||
* This behavior is **deprecated**, and consumers should instead use {@link CoreSetup.getStartServices}.
|
||||
* A mount function called when the user navigates to this app's route.
|
||||
*/
|
||||
mount: AppMount<HistoryLocationState> | AppMountDeprecated<HistoryLocationState>;
|
||||
mount: AppMount<HistoryLocationState>;
|
||||
|
||||
/**
|
||||
* Override the application's routing path from `/app/${id}`.
|
||||
|
@ -370,67 +356,6 @@ export type AppMount<HistoryLocationState = unknown> = (
|
|||
*/
|
||||
export type AppUnmount = () => void;
|
||||
|
||||
/**
|
||||
* A mount function called when the user navigates to this app's route.
|
||||
*
|
||||
* @remarks
|
||||
* When function has two arguments, it will be called with a {@link AppMountContext | context} as the first argument.
|
||||
* This behavior is **deprecated**, and consumers should instead use {@link CoreSetup.getStartServices}.
|
||||
*
|
||||
* @param context The mount context for this app. Deprecated, use {@link CoreSetup.getStartServices}.
|
||||
* @param params {@link AppMountParameters}
|
||||
* @returns An unmounting function that will be called to unmount the application. See {@link AppUnmount}.
|
||||
*
|
||||
* @deprecated
|
||||
* @public
|
||||
*/
|
||||
export type AppMountDeprecated<HistoryLocationState = unknown> = (
|
||||
context: AppMountContext,
|
||||
params: AppMountParameters<HistoryLocationState>
|
||||
) => AppUnmount | Promise<AppUnmount>;
|
||||
|
||||
/**
|
||||
* The context object received when applications are mounted to the DOM. Deprecated, use
|
||||
* {@link CoreSetup.getStartServices}.
|
||||
*
|
||||
* @deprecated
|
||||
* @public
|
||||
*/
|
||||
export interface AppMountContext {
|
||||
/**
|
||||
* Core service APIs available to mounted applications.
|
||||
*/
|
||||
core: {
|
||||
/** {@link ApplicationStart} */
|
||||
application: Pick<ApplicationStart, 'capabilities' | 'navigateToApp'>;
|
||||
/** {@link ChromeStart} */
|
||||
chrome: ChromeStart;
|
||||
/** {@link DocLinksStart} */
|
||||
docLinks: DocLinksStart;
|
||||
/** {@link HttpStart} */
|
||||
http: HttpStart;
|
||||
/** {@link I18nStart} */
|
||||
i18n: I18nStart;
|
||||
/** {@link NotificationsStart} */
|
||||
notifications: NotificationsStart;
|
||||
/** {@link OverlayStart} */
|
||||
overlays: OverlayStart;
|
||||
/** {@link SavedObjectsStart} */
|
||||
savedObjects: SavedObjectsStart;
|
||||
/** {@link IUiSettingsClient} */
|
||||
uiSettings: IUiSettingsClient;
|
||||
/**
|
||||
* exposed temporarily until https://github.com/elastic/kibana/issues/41990 done
|
||||
* use *only* to retrieve config values. There is no way to set injected values
|
||||
* in the new platform. Use the legacy platform API instead.
|
||||
* @deprecated
|
||||
* */
|
||||
injectedMetadata: {
|
||||
getInjectedVar: (name: string, defaultValue?: any) => unknown;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface AppMountParameters<HistoryLocationState = unknown> {
|
||||
/**
|
||||
|
@ -735,19 +660,6 @@ export interface ApplicationSetup {
|
|||
* ```
|
||||
*/
|
||||
registerAppUpdater(appUpdater$: Observable<AppUpdater>): void;
|
||||
|
||||
/**
|
||||
* Register a context provider for application mounting. Will only be available to applications that depend on the
|
||||
* plugin that registered this context. Deprecated, use {@link CoreSetup.getStartServices}.
|
||||
*
|
||||
* @deprecated
|
||||
* @param contextName - The key of {@link AppMountContext} this provider's return value should be attached to.
|
||||
* @param provider - A {@link IContextProvider} function
|
||||
*/
|
||||
registerMountContext<T extends keyof AppMountContext>(
|
||||
contextName: T,
|
||||
provider: IContextProvider<AppMountDeprecated, T>
|
||||
): void;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
@ -761,21 +673,6 @@ export interface InternalApplicationSetup extends Pick<ApplicationSetup, 'regist
|
|||
plugin: PluginOpaqueId,
|
||||
app: App<HistoryLocationState>
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Register a context provider for application mounting. Will only be available to applications that depend on the
|
||||
* plugin that registered this context. Deprecated, use {@link CoreSetup.getStartServices}.
|
||||
*
|
||||
* @deprecated
|
||||
* @param pluginOpaqueId - The opaque ID of the plugin that is registering the context.
|
||||
* @param contextName - The key of {@link AppMountContext} this provider's return value should be attached to.
|
||||
* @param provider - A {@link IContextProvider} function
|
||||
*/
|
||||
registerMountContext<T extends keyof AppMountContext>(
|
||||
pluginOpaqueId: PluginOpaqueId,
|
||||
contextName: T,
|
||||
provider: IContextProvider<AppMountDeprecated, T>
|
||||
): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -873,19 +770,6 @@ export interface ApplicationStart {
|
|||
*/
|
||||
getUrlForApp(appId: string, options?: { path?: string; absolute?: boolean }): string;
|
||||
|
||||
/**
|
||||
* Register a context provider for application mounting. Will only be available to applications that depend on the
|
||||
* plugin that registered this context. Deprecated, use {@link CoreSetup.getStartServices}.
|
||||
*
|
||||
* @deprecated
|
||||
* @param contextName - The key of {@link AppMountContext} this provider's return value should be attached to.
|
||||
* @param provider - A {@link IContextProvider} function
|
||||
*/
|
||||
registerMountContext<T extends keyof AppMountContext>(
|
||||
contextName: T,
|
||||
provider: IContextProvider<AppMountDeprecated, T>
|
||||
): void;
|
||||
|
||||
/**
|
||||
* An observable that emits the current application id and each subsequent id update.
|
||||
*/
|
||||
|
@ -893,22 +777,7 @@ export interface ApplicationStart {
|
|||
}
|
||||
|
||||
/** @internal */
|
||||
export interface InternalApplicationStart extends Omit<ApplicationStart, 'registerMountContext'> {
|
||||
/**
|
||||
* Register a context provider for application mounting. Will only be available to applications that depend on the
|
||||
* plugin that registered this context. Deprecated, use {@link CoreSetup.getStartServices}.
|
||||
*
|
||||
* @deprecated
|
||||
* @param pluginOpaqueId - The opaque ID of the plugin that is registering the context.
|
||||
* @param contextName - The key of {@link AppMountContext} this provider's return value should be attached to.
|
||||
* @param provider - A {@link IContextProvider} function
|
||||
*/
|
||||
registerMountContext<T extends keyof AppMountContext>(
|
||||
pluginOpaqueId: PluginOpaqueId,
|
||||
contextName: T,
|
||||
provider: IContextProvider<AppMountDeprecated, T>
|
||||
): void;
|
||||
|
||||
export interface InternalApplicationStart extends ApplicationStart {
|
||||
// Internal APIs
|
||||
getComponent(): JSX.Element | null;
|
||||
|
||||
|
|
|
@ -186,7 +186,6 @@ exports[`Header renders 1`] = `
|
|||
},
|
||||
"navigateToApp": [MockFunction],
|
||||
"navigateToUrl": [MockFunction],
|
||||
"registerMountContext": [MockFunction],
|
||||
}
|
||||
}
|
||||
badge$={
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||
import { ContextService, ContextSetup } from './context_service';
|
||||
import { contextMock } from '../../utils/context.mock';
|
||||
|
||||
const createSetupContractMock = () => {
|
||||
const setupContract: jest.Mocked<ContextSetup> = {
|
||||
createContextContainer: jest.fn().mockImplementation(() => contextMock.create()),
|
||||
};
|
||||
return setupContract;
|
||||
};
|
||||
|
||||
type ContextServiceContract = PublicMethodsOf<ContextService>;
|
||||
const createMock = () => {
|
||||
const mocked: jest.Mocked<ContextServiceContract> = {
|
||||
setup: jest.fn(),
|
||||
};
|
||||
mocked.setup.mockReturnValue(createSetupContractMock());
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const contextServiceMock = {
|
||||
create: createMock,
|
||||
createSetupContract: createSetupContractMock,
|
||||
};
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { contextMock } from '../../utils/context.mock';
|
||||
|
||||
export const MockContextConstructor = jest.fn(contextMock.create);
|
||||
jest.doMock('../../utils/context', () => ({
|
||||
ContextContainer: MockContextConstructor,
|
||||
}));
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { PluginOpaqueId } from '../../server';
|
||||
import { MockContextConstructor } from './context_service.test.mocks';
|
||||
import { ContextService } from './context_service';
|
||||
import { coreMock } from '../mocks';
|
||||
|
||||
const pluginDependencies = new Map<PluginOpaqueId, PluginOpaqueId[]>();
|
||||
|
||||
describe('ContextService', () => {
|
||||
describe('#setup()', () => {
|
||||
test('createContextContainer returns a new container configured with pluginDependencies', () => {
|
||||
const context = coreMock.createCoreContext();
|
||||
const service = new ContextService(context);
|
||||
const setup = service.setup({ pluginDependencies });
|
||||
expect(setup.createContextContainer()).toBeDefined();
|
||||
expect(MockContextConstructor).toHaveBeenCalledWith(pluginDependencies, context.coreId);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { PluginOpaqueId } from '../../server';
|
||||
import { IContextContainer, ContextContainer, HandlerFunction } from '../../utils/context';
|
||||
import { CoreContext } from '../core_system';
|
||||
|
||||
interface StartDeps {
|
||||
pluginDependencies: ReadonlyMap<PluginOpaqueId, PluginOpaqueId[]>;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export class ContextService {
|
||||
constructor(private readonly core: CoreContext) {}
|
||||
|
||||
public setup({ pluginDependencies }: StartDeps): ContextSetup {
|
||||
return {
|
||||
createContextContainer: <THandler extends HandlerFunction<any>>() =>
|
||||
new ContextContainer<THandler>(pluginDependencies, this.core.coreId),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc IContextContainer}
|
||||
*
|
||||
* @example
|
||||
* Say we're creating a plugin for rendering visualizations that allows new rendering methods to be registered. If we
|
||||
* want to offer context to these rendering methods, we can leverage the ContextService to manage these contexts.
|
||||
* ```ts
|
||||
* export interface VizRenderContext {
|
||||
* core: {
|
||||
* i18n: I18nStart;
|
||||
* uiSettings: IUiSettingsClient;
|
||||
* }
|
||||
* [contextName: string]: unknown;
|
||||
* }
|
||||
*
|
||||
* export type VizRenderer = (context: VizRenderContext, domElement: HTMLElement) => () => void;
|
||||
* // When a renderer is bound via `contextContainer.createHandler` this is the type that will be returned.
|
||||
* type BoundVizRenderer = (domElement: HTMLElement) => () => void;
|
||||
*
|
||||
* class VizRenderingPlugin {
|
||||
* private readonly contextContainer?: IContextContainer<VizRenderer>;
|
||||
* private readonly vizRenderers = new Map<string, BoundVizRenderer>();
|
||||
*
|
||||
* constructor(private readonly initContext: PluginInitializerContext) {}
|
||||
*
|
||||
* setup(core) {
|
||||
* this.contextContainer = core.context.createContextContainer();
|
||||
*
|
||||
* return {
|
||||
* registerContext: this.contextContainer.registerContext,
|
||||
* registerVizRenderer: (plugin: PluginOpaqueId, renderMethod: string, renderer: VizTypeRenderer) =>
|
||||
* this.vizRenderers.set(renderMethod, this.contextContainer.createHandler(plugin, renderer)),
|
||||
* };
|
||||
* }
|
||||
*
|
||||
* start(core) {
|
||||
* // Register the core context available to all renderers. Use the VizRendererContext's opaqueId as the first arg.
|
||||
* this.contextContainer.registerContext(this.initContext.opaqueId, 'core', () => ({
|
||||
* i18n: core.i18n,
|
||||
* uiSettings: core.uiSettings
|
||||
* }));
|
||||
*
|
||||
* return {
|
||||
* registerContext: this.contextContainer.registerContext,
|
||||
*
|
||||
* renderVizualization: (renderMethod: string, domElement: HTMLElement) => {
|
||||
* if (!this.vizRenderer.has(renderMethod)) {
|
||||
* throw new Error(`Render method '${renderMethod}' has not been registered`);
|
||||
* }
|
||||
*
|
||||
* // The handler can now be called directly with only an `HTMLElement` and will automatically
|
||||
* // have a new `context` object created and populated by the context container.
|
||||
* const handler = this.vizRenderers.get(renderMethod)
|
||||
* return handler(domElement);
|
||||
* }
|
||||
* };
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ContextSetup {
|
||||
/**
|
||||
* Creates a new {@link IContextContainer} for a service owner.
|
||||
*/
|
||||
createContextContainer<THandler extends HandlerFunction<any>>(): IContextContainer<THandler>;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
export { ContextService, ContextSetup } from './context_service';
|
||||
export {
|
||||
IContextContainer,
|
||||
IContextProvider,
|
||||
HandlerFunction,
|
||||
HandlerContextType,
|
||||
HandlerParameters,
|
||||
} from '../../utils/context';
|
|
@ -29,7 +29,6 @@ import { pluginsServiceMock } from './plugins/plugins_service.mock';
|
|||
import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
||||
import { docLinksServiceMock } from './doc_links/doc_links_service.mock';
|
||||
import { renderingServiceMock } from './rendering/rendering_service.mock';
|
||||
import { contextServiceMock } from './context/context_service.mock';
|
||||
import { integrationsServiceMock } from './integrations/integrations_service.mock';
|
||||
import { coreAppMock } from './core_app/core_app.mock';
|
||||
|
||||
|
@ -115,12 +114,6 @@ jest.doMock('./rendering', () => ({
|
|||
RenderingService: RenderingServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockContextService = contextServiceMock.create();
|
||||
export const ContextServiceConstructor = jest.fn().mockImplementation(() => MockContextService);
|
||||
jest.doMock('./context', () => ({
|
||||
ContextService: ContextServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockIntegrationsService = integrationsServiceMock.create();
|
||||
export const IntegrationsServiceConstructor = jest
|
||||
.fn()
|
||||
|
|
|
@ -39,7 +39,6 @@ import {
|
|||
MockDocLinksService,
|
||||
MockRenderingService,
|
||||
RenderingServiceConstructor,
|
||||
MockContextService,
|
||||
IntegrationsServiceConstructor,
|
||||
MockIntegrationsService,
|
||||
CoreAppConstructor,
|
||||
|
@ -149,29 +148,6 @@ describe('#setup()', () => {
|
|||
expect(MockApplicationService.setup).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls context#setup()', async () => {
|
||||
await setupCore();
|
||||
expect(MockContextService.setup).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('injects legacy dependency to context#setup()', async () => {
|
||||
const pluginA = Symbol();
|
||||
const pluginB = Symbol();
|
||||
const pluginDependencies = new Map<symbol, symbol[]>([
|
||||
[pluginA, []],
|
||||
[pluginB, [pluginA]],
|
||||
]);
|
||||
MockPluginsService.getOpaqueIds.mockReturnValue(pluginDependencies);
|
||||
await setupCore();
|
||||
|
||||
expect(MockContextService.setup).toHaveBeenCalledWith({
|
||||
pluginDependencies: new Map([
|
||||
[pluginA, []],
|
||||
[pluginB, [pluginA]],
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
it('calls injectedMetadata#setup()', async () => {
|
||||
await setupCore();
|
||||
expect(MockInjectedMetadataService.setup).toHaveBeenCalledTimes(1);
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { pick } from '@kbn/std';
|
||||
import { CoreId } from '../server';
|
||||
import { PackageInfo, EnvironmentMode } from '../server/types';
|
||||
import { CoreSetup, CoreStart } from '.';
|
||||
|
@ -39,7 +38,6 @@ import { ApplicationService } from './application';
|
|||
import { DocLinksService } from './doc_links';
|
||||
import { RenderingService } from './rendering';
|
||||
import { SavedObjectsService } from './saved_objects';
|
||||
import { ContextService } from './context';
|
||||
import { IntegrationsService } from './integrations';
|
||||
import { CoreApp } from './core_app';
|
||||
import type { InternalApplicationSetup, InternalApplicationStart } from './application/types';
|
||||
|
@ -93,7 +91,6 @@ export class CoreSystem {
|
|||
private readonly application: ApplicationService;
|
||||
private readonly docLinks: DocLinksService;
|
||||
private readonly rendering: RenderingService;
|
||||
private readonly context: ContextService;
|
||||
private readonly integrations: IntegrationsService;
|
||||
private readonly coreApp: CoreApp;
|
||||
|
||||
|
@ -129,8 +126,6 @@ export class CoreSystem {
|
|||
this.integrations = new IntegrationsService();
|
||||
|
||||
this.coreContext = { coreId: Symbol('core'), env: injectedMetadata.env };
|
||||
|
||||
this.context = new ContextService(this.coreContext);
|
||||
this.plugins = new PluginsService(this.coreContext, injectedMetadata.uiPlugins);
|
||||
this.coreApp = new CoreApp(this.coreContext);
|
||||
}
|
||||
|
@ -150,16 +145,11 @@ export class CoreSystem {
|
|||
const uiSettings = this.uiSettings.setup({ http, injectedMetadata });
|
||||
const notifications = this.notifications.setup({ uiSettings });
|
||||
|
||||
const pluginDependencies = this.plugins.getOpaqueIds();
|
||||
const context = this.context.setup({
|
||||
pluginDependencies: new Map([...pluginDependencies]),
|
||||
});
|
||||
const application = this.application.setup({ context, http });
|
||||
const application = this.application.setup({ http });
|
||||
this.coreApp.setup({ application, http, injectedMetadata, notifications });
|
||||
|
||||
const core: InternalCoreSetup = {
|
||||
application,
|
||||
context,
|
||||
fatalErrors: this.fatalErrorsSetup,
|
||||
http,
|
||||
injectedMetadata,
|
||||
|
@ -220,19 +210,6 @@ export class CoreSystem {
|
|||
|
||||
this.coreApp.start({ application, http, notifications, uiSettings });
|
||||
|
||||
application.registerMountContext(this.coreContext.coreId, 'core', () => ({
|
||||
application: pick(application, ['capabilities', 'navigateToApp']),
|
||||
chrome,
|
||||
docLinks,
|
||||
http,
|
||||
i18n,
|
||||
injectedMetadata: pick(injectedMetadata, ['getInjectedVar']),
|
||||
notifications,
|
||||
overlays,
|
||||
savedObjects,
|
||||
uiSettings,
|
||||
}));
|
||||
|
||||
const core: InternalCoreStart = {
|
||||
application,
|
||||
chrome,
|
||||
|
|
|
@ -69,14 +69,6 @@ import { UiSettingsState, IUiSettingsClient } from './ui_settings';
|
|||
import { ApplicationSetup, Capabilities, ApplicationStart } from './application';
|
||||
import { DocLinksStart } from './doc_links';
|
||||
import { SavedObjectsStart } from './saved_objects';
|
||||
import {
|
||||
IContextContainer,
|
||||
IContextProvider,
|
||||
ContextSetup,
|
||||
HandlerFunction,
|
||||
HandlerContextType,
|
||||
HandlerParameters,
|
||||
} from './context';
|
||||
|
||||
export { PackageInfo, EnvironmentMode, IExternalUrlPolicy } from '../server/types';
|
||||
/** @interal */
|
||||
|
@ -98,9 +90,7 @@ export {
|
|||
ApplicationStart,
|
||||
App,
|
||||
AppMount,
|
||||
AppMountDeprecated,
|
||||
AppUnmount,
|
||||
AppMountContext,
|
||||
AppMountParameters,
|
||||
AppLeaveHandler,
|
||||
AppLeaveActionType,
|
||||
|
@ -218,11 +208,6 @@ export { URL_MAX_LENGTH } from './core_app';
|
|||
export interface CoreSetup<TPluginsStart extends object = object, TStart = unknown> {
|
||||
/** {@link ApplicationSetup} */
|
||||
application: ApplicationSetup;
|
||||
/**
|
||||
* {@link ContextSetup}
|
||||
* @deprecated
|
||||
*/
|
||||
context: ContextSetup;
|
||||
/** {@link FatalErrorsSetup} */
|
||||
fatalErrors: FatalErrorsSetup;
|
||||
/** {@link HttpSetup} */
|
||||
|
@ -318,12 +303,6 @@ export {
|
|||
ChromeRecentlyAccessed,
|
||||
ChromeRecentlyAccessedHistoryItem,
|
||||
ChromeStart,
|
||||
IContextContainer,
|
||||
HandlerFunction,
|
||||
HandlerContextType,
|
||||
HandlerParameters,
|
||||
IContextProvider,
|
||||
ContextSetup,
|
||||
DocLinksStart,
|
||||
FatalErrorInfo,
|
||||
FatalErrorsSetup,
|
||||
|
|
|
@ -33,7 +33,6 @@ import { notificationServiceMock } from './notifications/notifications_service.m
|
|||
import { overlayServiceMock } from './overlays/overlay_service.mock';
|
||||
import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
||||
import { savedObjectsServiceMock } from './saved_objects/saved_objects_service.mock';
|
||||
import { contextServiceMock } from './context/context_service.mock';
|
||||
import { injectedMetadataServiceMock } from './injected_metadata/injected_metadata_service.mock';
|
||||
|
||||
export { chromeServiceMock } from './chrome/chrome_service.mock';
|
||||
|
@ -60,7 +59,6 @@ function createCoreSetupMock({
|
|||
} = {}) {
|
||||
const mock = {
|
||||
application: applicationServiceMock.createSetupContract(),
|
||||
context: contextServiceMock.createSetupContract(),
|
||||
docLinks: docLinksServiceMock.createSetupContract(),
|
||||
fatalErrors: fatalErrorsServiceMock.createSetupContract(),
|
||||
getStartServices: jest.fn<Promise<[ReturnType<typeof createCoreStartMock>, any, any]>, []>(() =>
|
||||
|
|
|
@ -97,10 +97,7 @@ export function createPluginSetupContext<
|
|||
application: {
|
||||
register: (app) => deps.application.register(plugin.opaqueId, app),
|
||||
registerAppUpdater: (statusUpdater$) => deps.application.registerAppUpdater(statusUpdater$),
|
||||
registerMountContext: (contextName, provider) =>
|
||||
deps.application.registerMountContext(plugin.opaqueId, contextName, provider),
|
||||
},
|
||||
context: deps.context,
|
||||
fatalErrors: deps.fatalErrors,
|
||||
http: deps.http,
|
||||
notifications: deps.notifications,
|
||||
|
@ -140,8 +137,6 @@ export function createPluginStartContext<
|
|||
navigateToApp: deps.application.navigateToApp,
|
||||
navigateToUrl: deps.application.navigateToUrl,
|
||||
getUrlForApp: deps.application.getUrlForApp,
|
||||
registerMountContext: (contextName, provider) =>
|
||||
deps.application.registerMountContext(plugin.opaqueId, contextName, provider),
|
||||
},
|
||||
docLinks: deps.docLinks,
|
||||
http: deps.http,
|
||||
|
|
|
@ -45,7 +45,6 @@ import { httpServiceMock } from '../http/http_service.mock';
|
|||
import { CoreSetup, CoreStart, PluginInitializerContext } from '..';
|
||||
import { docLinksServiceMock } from '../doc_links/doc_links_service.mock';
|
||||
import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock';
|
||||
import { contextServiceMock } from '../context/context_service.mock';
|
||||
|
||||
export let mockPluginInitializers: Map<PluginName, MockedPluginInitializer>;
|
||||
|
||||
|
@ -89,7 +88,6 @@ describe('PluginsService', () => {
|
|||
];
|
||||
mockSetupDeps = {
|
||||
application: applicationServiceMock.createInternalSetupContract(),
|
||||
context: contextServiceMock.createSetupContract(),
|
||||
fatalErrors: fatalErrorsServiceMock.createSetupContract(),
|
||||
http: httpServiceMock.createSetupContract(),
|
||||
injectedMetadata: injectedMetadataServiceMock.createStartContract(),
|
||||
|
|
|
@ -32,7 +32,6 @@ import { PublicUiSettingsParams as PublicUiSettingsParams_2 } from 'src/core/ser
|
|||
import React from 'react';
|
||||
import { RecursiveReadonly } from '@kbn/utility-types';
|
||||
import * as Rx from 'rxjs';
|
||||
import { ShallowPromise } from '@kbn/utility-types';
|
||||
import { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
|
||||
import { TransportRequestParams } from '@elastic/elasticsearch/lib/Transport';
|
||||
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
|
||||
|
@ -57,7 +56,7 @@ export interface App<HistoryLocationState = unknown> {
|
|||
icon?: string;
|
||||
id: string;
|
||||
meta?: AppMeta;
|
||||
mount: AppMount<HistoryLocationState> | AppMountDeprecated<HistoryLocationState>;
|
||||
mount: AppMount<HistoryLocationState>;
|
||||
navLinkStatus?: AppNavLinkStatus;
|
||||
order?: number;
|
||||
status?: AppStatus;
|
||||
|
@ -117,8 +116,6 @@ export type AppLeaveHandler = (factory: AppLeaveActionFactory, nextAppId?: strin
|
|||
export interface ApplicationSetup {
|
||||
register<HistoryLocationState = unknown>(app: App<HistoryLocationState>): void;
|
||||
registerAppUpdater(appUpdater$: Observable<AppUpdater>): void;
|
||||
// @deprecated
|
||||
registerMountContext<T extends keyof AppMountContext>(contextName: T, provider: IContextProvider<AppMountDeprecated, T>): void;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
|
@ -132,8 +129,6 @@ export interface ApplicationStart {
|
|||
}): string;
|
||||
navigateToApp(appId: string, options?: NavigateToAppOptions): Promise<void>;
|
||||
navigateToUrl(url: string): Promise<void>;
|
||||
// @deprecated
|
||||
registerMountContext<T extends keyof AppMountContext>(contextName: T, provider: IContextProvider<AppMountDeprecated, T>): void;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
@ -145,27 +140,6 @@ export interface AppMeta {
|
|||
// @public
|
||||
export type AppMount<HistoryLocationState = unknown> = (params: AppMountParameters<HistoryLocationState>) => AppUnmount | Promise<AppUnmount>;
|
||||
|
||||
// @public @deprecated
|
||||
export interface AppMountContext {
|
||||
core: {
|
||||
application: Pick<ApplicationStart, 'capabilities' | 'navigateToApp'>;
|
||||
chrome: ChromeStart;
|
||||
docLinks: DocLinksStart;
|
||||
http: HttpStart;
|
||||
i18n: I18nStart;
|
||||
notifications: NotificationsStart;
|
||||
overlays: OverlayStart;
|
||||
savedObjects: SavedObjectsStart;
|
||||
uiSettings: IUiSettingsClient;
|
||||
injectedMetadata: {
|
||||
getInjectedVar: (name: string, defaultValue?: any) => unknown;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// @public @deprecated
|
||||
export type AppMountDeprecated<HistoryLocationState = unknown> = (context: AppMountContext, params: AppMountParameters<HistoryLocationState>) => AppUnmount | Promise<AppUnmount>;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface AppMountParameters<HistoryLocationState = unknown> {
|
||||
// @deprecated
|
||||
|
@ -392,11 +366,6 @@ export interface ChromeStart {
|
|||
setIsVisible(isVisible: boolean): void;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface ContextSetup {
|
||||
createContextContainer<THandler extends HandlerFunction<any>>(): IContextContainer<THandler>;
|
||||
}
|
||||
|
||||
// @internal (undocumented)
|
||||
export interface CoreContext {
|
||||
// Warning: (ae-forgotten-export) The symbol "CoreId" needs to be exported by the entry point index.d.ts
|
||||
|
@ -414,8 +383,6 @@ export interface CoreContext {
|
|||
export interface CoreSetup<TPluginsStart extends object = object, TStart = unknown> {
|
||||
// (undocumented)
|
||||
application: ApplicationSetup;
|
||||
// @deprecated (undocumented)
|
||||
context: ContextSetup;
|
||||
// (undocumented)
|
||||
fatalErrors: FatalErrorsSetup;
|
||||
// (undocumented)
|
||||
|
@ -649,15 +616,6 @@ export interface FatalErrorsSetup {
|
|||
// @public
|
||||
export type FatalErrorsStart = FatalErrorsSetup;
|
||||
|
||||
// @public
|
||||
export type HandlerContextType<T extends HandlerFunction<any>> = T extends HandlerFunction<infer U> ? U : never;
|
||||
|
||||
// @public
|
||||
export type HandlerFunction<T extends object> = (context: T, ...args: any[]) => any;
|
||||
|
||||
// @public
|
||||
export type HandlerParameters<T extends HandlerFunction<any>> = T extends (context: any, ...args: infer U) => any ? U : never;
|
||||
|
||||
// @internal (undocumented)
|
||||
export class HttpFetchError extends Error implements IHttpFetchError {
|
||||
constructor(message: string, name: string, request: Request, response?: Response | undefined, body?: any);
|
||||
|
@ -814,17 +772,6 @@ export interface IBasePath {
|
|||
readonly serverBasePath: string;
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface IContextContainer<THandler extends HandlerFunction<any>> {
|
||||
createHandler(pluginOpaqueId: PluginOpaqueId, handler: THandler): (...rest: HandlerParameters<THandler>) => ShallowPromise<ReturnType<THandler>>;
|
||||
registerContext<TContextName extends keyof HandlerContextType<THandler>>(pluginOpaqueId: PluginOpaqueId, contextName: TContextName, provider: IContextProvider<THandler, TContextName>): this;
|
||||
}
|
||||
|
||||
// Warning: (ae-forgotten-export) The symbol "PartialExceptFor" needs to be exported by the entry point index.d.ts
|
||||
//
|
||||
// @public
|
||||
export type IContextProvider<THandler extends HandlerFunction<any>, TContextName extends keyof HandlerContextType<THandler>> = (context: PartialExceptFor<HandlerContextType<THandler>, 'core'>, ...rest: HandlerParameters<THandler>) => Promise<HandlerContextType<THandler>[TContextName]> | HandlerContextType<THandler>[TContextName];
|
||||
|
||||
// @public
|
||||
export interface IExternalUrl {
|
||||
validateUrl(relativeOrAbsoluteUrl: string): URL | null;
|
||||
|
@ -1555,6 +1502,6 @@ export interface UserProvidedValues<T = any> {
|
|||
|
||||
// Warnings were encountered during analysis:
|
||||
//
|
||||
// src/core/public/core_system.ts:185:21 - (ae-forgotten-export) The symbol "InternalApplicationStart" needs to be exported by the entry point index.d.ts
|
||||
// src/core/public/core_system.ts:175:21 - (ae-forgotten-export) The symbol "InternalApplicationStart" needs to be exported by the entry point index.d.ts
|
||||
|
||||
```
|
||||
|
|
|
@ -48,7 +48,6 @@ import * as Rx from 'rxjs';
|
|||
import { SavedObjectAttributes } from 'kibana/server';
|
||||
import { SavedObjectAttributes as SavedObjectAttributes_2 } from 'src/core/public';
|
||||
import { SavedObjectAttributes as SavedObjectAttributes_3 } from 'kibana/public';
|
||||
import { ShallowPromise } from '@kbn/utility-types';
|
||||
import { SimpleSavedObject as SimpleSavedObject_2 } from 'src/core/public';
|
||||
import { Start as Start_2 } from 'src/plugins/inspector/public';
|
||||
import { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
|
||||
|
|
|
@ -108,7 +108,6 @@ exports[`SavedObjectsTable should render normally 1`] = `
|
|||
"getUrlForApp": [MockFunction],
|
||||
"navigateToApp": [MockFunction],
|
||||
"navigateToUrl": [MockFunction],
|
||||
"registerMountContext": [MockFunction],
|
||||
}
|
||||
}
|
||||
>
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
|
||||
import React from 'react';
|
||||
import { render, unmountComponentAtNode } from 'react-dom';
|
||||
import { AppMountContext, AppMountParameters } from 'kibana/public';
|
||||
import { AppMountParameters } from 'kibana/public';
|
||||
import { Main } from './components/main';
|
||||
|
||||
export const renderApp = (context: AppMountContext, { element }: AppMountParameters) => {
|
||||
export const renderApp = ({ element }: AppMountParameters) => {
|
||||
render(<Main />, element);
|
||||
return () => unmountComponentAtNode(element);
|
||||
};
|
||||
|
|
|
@ -32,9 +32,9 @@ export class Plugin {
|
|||
application.register({
|
||||
id: 'kbn_tp_run_pipeline',
|
||||
title: 'Run Pipeline',
|
||||
async mount(context, params) {
|
||||
async mount(params) {
|
||||
const { renderApp } = await import('./app/app');
|
||||
return renderApp(context, params);
|
||||
return renderApp(params);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ import {
|
|||
EuiSideNav,
|
||||
} from '@elastic/eui';
|
||||
|
||||
import { AppMountContext, AppMountParameters } from 'kibana/public';
|
||||
import { CoreStart, AppMountParameters } from 'kibana/public';
|
||||
|
||||
const Home = () => (
|
||||
<EuiPageBody data-test-subj="fooAppHome">
|
||||
|
@ -83,7 +83,7 @@ const PageA = () => (
|
|||
);
|
||||
|
||||
type NavProps = RouteComponentProps & {
|
||||
navigateToApp: AppMountContext['core']['application']['navigateToApp'];
|
||||
navigateToApp: CoreStart['application']['navigateToApp'];
|
||||
};
|
||||
const Nav = withRouter(({ history, navigateToApp }: NavProps) => (
|
||||
<EuiSideNav
|
||||
|
@ -116,11 +116,11 @@ const Nav = withRouter(({ history, navigateToApp }: NavProps) => (
|
|||
/>
|
||||
));
|
||||
|
||||
const FooApp = ({ history, context }: { history: History; context: AppMountContext }) => (
|
||||
const FooApp = ({ history, coreStart }: { history: History; coreStart: CoreStart }) => (
|
||||
<Router history={history}>
|
||||
<EuiPage>
|
||||
<EuiPageSideBar>
|
||||
<Nav navigateToApp={context.core.application.navigateToApp} />
|
||||
<Nav navigateToApp={coreStart.application.navigateToApp} />
|
||||
</EuiPageSideBar>
|
||||
<Route path="/" exact render={() => <Redirect to="/home" />} />
|
||||
<Route path="/home" exact component={Home} />
|
||||
|
@ -129,8 +129,8 @@ const FooApp = ({ history, context }: { history: History; context: AppMountConte
|
|||
</Router>
|
||||
);
|
||||
|
||||
export const renderApp = (context: AppMountContext, { history, element }: AppMountParameters) => {
|
||||
ReactDOM.render(<FooApp history={history} context={context} />, element);
|
||||
export const renderApp = (coreStart: CoreStart, { history, element }: AppMountParameters) => {
|
||||
ReactDOM.render(<FooApp history={history} coreStart={coreStart} />, element);
|
||||
|
||||
return () => ReactDOM.unmountComponentAtNode(element);
|
||||
};
|
||||
|
|
|
@ -24,9 +24,10 @@ export class CorePluginAPlugin implements Plugin<CorePluginAPluginSetup, CorePlu
|
|||
core.application.register({
|
||||
id: 'foo',
|
||||
title: 'Foo',
|
||||
async mount(context, params) {
|
||||
async mount(params) {
|
||||
const { renderApp } = await import('./application');
|
||||
return renderApp(context, params);
|
||||
const [coreStart] = await core.getStartServices();
|
||||
return renderApp(coreStart, params);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ export class CoreAppLeavePlugin
|
|||
core.application.register({
|
||||
id: 'appleave1',
|
||||
title: 'AppLeave 1',
|
||||
async mount(context, params) {
|
||||
async mount(params) {
|
||||
const { renderApp } = await import('./application');
|
||||
params.onAppLeave((actions) => actions.confirm('confirm-message', 'confirm-title'));
|
||||
return renderApp('AppLeave 1', params);
|
||||
|
@ -34,7 +34,7 @@ export class CoreAppLeavePlugin
|
|||
core.application.register({
|
||||
id: 'appleave2',
|
||||
title: 'AppLeave 2',
|
||||
async mount(context, params) {
|
||||
async mount(params) {
|
||||
const { renderApp } = await import('./application');
|
||||
params.onAppLeave((actions) => actions.default());
|
||||
return renderApp('AppLeave 2', params);
|
||||
|
|
|
@ -36,7 +36,7 @@ import {
|
|||
EuiSideNav,
|
||||
} from '@elastic/eui';
|
||||
|
||||
import { AppMountContext, AppMountParameters } from 'kibana/public';
|
||||
import { CoreStart, AppMountParameters } from 'kibana/public';
|
||||
|
||||
const Home = () => (
|
||||
<EuiPageBody data-test-subj="barAppHome">
|
||||
|
@ -90,7 +90,7 @@ const PageB = ({ location }: RouteComponentProps) => {
|
|||
};
|
||||
|
||||
type NavProps = RouteComponentProps & {
|
||||
navigateToApp: AppMountContext['core']['application']['navigateToApp'];
|
||||
navigateToApp: CoreStart['application']['navigateToApp'];
|
||||
};
|
||||
const Nav = withRouter(({ history, navigateToApp }: NavProps) => (
|
||||
<EuiSideNav
|
||||
|
@ -123,11 +123,11 @@ const Nav = withRouter(({ history, navigateToApp }: NavProps) => (
|
|||
/>
|
||||
));
|
||||
|
||||
const BarApp = ({ history, context }: { history: History; context: AppMountContext }) => (
|
||||
const BarApp = ({ history, coreStart }: { history: History; coreStart: CoreStart }) => (
|
||||
<Router history={history}>
|
||||
<EuiPage>
|
||||
<EuiPageSideBar>
|
||||
<Nav navigateToApp={context.core.application.navigateToApp} />
|
||||
<Nav navigateToApp={coreStart.application.navigateToApp} />
|
||||
</EuiPageSideBar>
|
||||
<Route path="/" exact component={Home} />
|
||||
<Route path="/page-b" component={PageB} />
|
||||
|
@ -135,8 +135,8 @@ const BarApp = ({ history, context }: { history: History; context: AppMountConte
|
|||
</Router>
|
||||
);
|
||||
|
||||
export const renderApp = (context: AppMountContext, { history, element }: AppMountParameters) => {
|
||||
ReactDOM.render(<BarApp history={history} context={context} />, element);
|
||||
export const renderApp = (coreStart: CoreStart, { history, element }: AppMountParameters) => {
|
||||
ReactDOM.render(<BarApp history={history} coreStart={coreStart} />, element);
|
||||
|
||||
return () => ReactDOM.unmountComponentAtNode(element);
|
||||
};
|
||||
|
|
|
@ -39,9 +39,10 @@ export class CorePluginBPlugin
|
|||
core.application.register({
|
||||
id: 'bar',
|
||||
title: 'Bar',
|
||||
async mount(context, params) {
|
||||
async mount(params) {
|
||||
const { renderApp } = await import('./application');
|
||||
return renderApp(context, params);
|
||||
const [coreStart] = await core.getStartServices();
|
||||
return renderApp(coreStart, params);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import {
|
|||
EuiTitle,
|
||||
} from '@elastic/eui';
|
||||
|
||||
import { AppMountContext, AppMountParameters } from 'kibana/public';
|
||||
import { AppMountParameters } from 'kibana/public';
|
||||
|
||||
const Home = () => (
|
||||
<EuiPageBody data-test-subj="chromelessAppHome">
|
||||
|
@ -56,7 +56,7 @@ const Home = () => (
|
|||
</EuiPageBody>
|
||||
);
|
||||
|
||||
const ChromelessApp = ({ basename }: { basename: string; context: AppMountContext }) => (
|
||||
const ChromelessApp = ({ basename }: { basename: string }) => (
|
||||
<Router basename={basename}>
|
||||
<EuiPage>
|
||||
<Route path="/" component={Home} />
|
||||
|
@ -64,11 +64,8 @@ const ChromelessApp = ({ basename }: { basename: string; context: AppMountContex
|
|||
</Router>
|
||||
);
|
||||
|
||||
export const renderApp = (
|
||||
context: AppMountContext,
|
||||
{ appBasePath, element }: AppMountParameters
|
||||
) => {
|
||||
render(<ChromelessApp basename={appBasePath} context={context} />, element);
|
||||
export const renderApp = ({ appBasePath, element }: AppMountParameters) => {
|
||||
render(<ChromelessApp basename={appBasePath} />, element);
|
||||
|
||||
return () => unmountComponentAtNode(element);
|
||||
};
|
||||
|
|
|
@ -26,9 +26,9 @@ export class CorePluginChromelessPlugin
|
|||
id: 'chromeless',
|
||||
title: 'Chromeless',
|
||||
chromeless: true,
|
||||
async mount(context, params) {
|
||||
async mount(params) {
|
||||
const { renderApp } = await import('./application');
|
||||
return renderApp(context, params);
|
||||
return renderApp(params);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ export class CoreHelpMenuPlugin
|
|||
core.application.register({
|
||||
id: 'core_help_menu',
|
||||
title: 'Help Menu Test App',
|
||||
async mount(context, params) {
|
||||
async mount(params) {
|
||||
const [{ chrome, http }] = await core.getStartServices();
|
||||
|
||||
chrome.setHelpExtension({
|
||||
|
|
|
@ -27,7 +27,7 @@ export class RenderingPlugin implements Plugin {
|
|||
id: 'rendering',
|
||||
title: 'Rendering',
|
||||
appRoute: '/render/core',
|
||||
async mount(context, { element }) {
|
||||
async mount({ element }) {
|
||||
render(<h1 data-test-subj="renderingHeader">rendering service</h1>, element);
|
||||
|
||||
return () => unmountComponentAtNode(element);
|
||||
|
@ -38,7 +38,7 @@ export class RenderingPlugin implements Plugin {
|
|||
id: 'custom-app-route',
|
||||
title: 'Custom App Route',
|
||||
appRoute: '/custom/appRoute',
|
||||
async mount(context, { element }) {
|
||||
async mount({ element }) {
|
||||
render(<h1 data-test-subj="customAppRouteHeader">Custom App Route</h1>, element);
|
||||
|
||||
return () => unmountComponentAtNode(element);
|
||||
|
|
|
@ -20,7 +20,6 @@ import 'angular-sanitize';
|
|||
import 'angular-route';
|
||||
// type imports
|
||||
import {
|
||||
AppMountContext,
|
||||
ChromeStart,
|
||||
CoreStart,
|
||||
PluginInitializerContext,
|
||||
|
@ -55,10 +54,10 @@ import { SavedObjectsStart } from '../../../../src/plugins/saved_objects/public'
|
|||
export interface GraphDependencies {
|
||||
pluginInitializerContext: PluginInitializerContext;
|
||||
core: CoreStart;
|
||||
coreStart: CoreStart;
|
||||
element: HTMLElement;
|
||||
appBasePath: string;
|
||||
capabilities: Record<string, boolean | Record<string, boolean>>;
|
||||
coreStart: AppMountContext['core'];
|
||||
navigation: NavigationStart;
|
||||
licensing: LicensingPluginStart;
|
||||
chrome: ChromeStart;
|
||||
|
@ -91,12 +90,12 @@ export const renderApp = ({ appBasePath, element, kibanaLegacy, ...deps }: Graph
|
|||
const licenseAllowsToShowThisPage = info.showAppLink && info.enableAppLink;
|
||||
|
||||
if (!licenseAllowsToShowThisPage) {
|
||||
deps.coreStart.notifications.toasts.addDanger(info.message);
|
||||
deps.core.notifications.toasts.addDanger(info.message);
|
||||
// This has to happen in the next tick because otherwise the original navigation
|
||||
// bringing us to the graph app in the first place
|
||||
// never completes and the browser enters are redirect loop
|
||||
setTimeout(() => {
|
||||
deps.coreStart.application.navigateToApp('home');
|
||||
deps.core.application.navigateToApp('home');
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -87,6 +87,7 @@ export class GraphPlugin
|
|||
pluginInitializerContext: this.initializerContext,
|
||||
licensing: pluginsStart.licensing,
|
||||
core: coreStart,
|
||||
coreStart,
|
||||
navigation: pluginsStart.navigation,
|
||||
data: pluginsStart.data,
|
||||
kibanaLegacy: pluginsStart.kibanaLegacy,
|
||||
|
@ -97,7 +98,6 @@ export class GraphPlugin
|
|||
graphSavePolicy: config.savePolicy,
|
||||
storage: new Storage(window.localStorage),
|
||||
capabilities: coreStart.application.capabilities.graph,
|
||||
coreStart,
|
||||
chrome: coreStart.chrome,
|
||||
toastNotifications: coreStart.notifications.toasts,
|
||||
indexPatterns: pluginsStart.data!.indexPatterns,
|
||||
|
|
|
@ -12,7 +12,7 @@ import 'angular-route';
|
|||
import '../index.scss';
|
||||
import { upperFirst } from 'lodash';
|
||||
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
|
||||
import { AppMountContext } from 'kibana/public';
|
||||
import { CoreStart } from 'kibana/public';
|
||||
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
|
||||
import {
|
||||
createTopNavDirective,
|
||||
|
@ -218,7 +218,7 @@ function createLocalI18nModule() {
|
|||
.directive('i18nId', i18nDirective);
|
||||
}
|
||||
|
||||
function createHrefModule(core: AppMountContext['core']) {
|
||||
function createHrefModule(core: CoreStart) {
|
||||
const name: string = 'kbnHref';
|
||||
angular.module('monitoring/href', []).directive(name, function () {
|
||||
return {
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { AppMountContext } from 'kibana/public';
|
||||
import { CoreStart } from 'kibana/public';
|
||||
import { ISection } from '../../typings/section';
|
||||
|
||||
export const getEmptySections = ({ core }: { core: AppMountContext['core'] }): ISection[] => {
|
||||
export const getEmptySections = ({ core }: { core: CoreStart }): ISection[] => {
|
||||
return [
|
||||
{
|
||||
id: 'infra_logs',
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { getNewsFeed } from './get_news_feed';
|
||||
import { AppMountContext } from 'kibana/public';
|
||||
import { CoreStart } from 'kibana/public';
|
||||
|
||||
describe('getNewsFeed', () => {
|
||||
const originalConsole = global.console;
|
||||
|
@ -23,7 +23,7 @@ describe('getNewsFeed', () => {
|
|||
throw new Error('Boom');
|
||||
},
|
||||
},
|
||||
} as unknown) as AppMountContext['core'];
|
||||
} as unknown) as CoreStart;
|
||||
|
||||
const newsFeed = await getNewsFeed({ core });
|
||||
expect(newsFeed.items).toEqual([]);
|
||||
|
@ -99,7 +99,7 @@ describe('getNewsFeed', () => {
|
|||
};
|
||||
},
|
||||
},
|
||||
} as unknown) as AppMountContext['core'];
|
||||
} as unknown) as CoreStart;
|
||||
|
||||
const newsFeed = await getNewsFeed({ core });
|
||||
expect(newsFeed.items.length).toEqual(3);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { AppMountContext } from 'kibana/public';
|
||||
import { CoreStart } from 'kibana/public';
|
||||
|
||||
export interface NewsItem {
|
||||
title: { en: string };
|
||||
|
@ -16,7 +16,7 @@ interface NewsFeed {
|
|||
items: NewsItem[];
|
||||
}
|
||||
|
||||
export async function getNewsFeed({ core }: { core: AppMountContext['core'] }): Promise<NewsFeed> {
|
||||
export async function getNewsFeed({ core }: { core: CoreStart }): Promise<NewsFeed> {
|
||||
try {
|
||||
return await core.http.get('https://feeds.elastic.co/observability-solution/v8.0.0.json');
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue