From 38498dba89b3e20490a4acbef6c0452282aad353 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Tue, 12 Nov 2019 11:20:57 +0100 Subject: [PATCH] address review comments --- .../{render_app.tsx => application.tsx} | 6 ++-- .../kibana/public/dev_tools/plugin.ts | 6 ++-- src/plugins/dev_tools/README.md | 29 +++++++++++++++++++ src/plugins/dev_tools/public/plugin.ts | 18 ++++++++---- 4 files changed, 47 insertions(+), 12 deletions(-) rename src/legacy/core_plugins/kibana/public/dev_tools/{render_app.tsx => application.tsx} (98%) create mode 100644 src/plugins/dev_tools/README.md diff --git a/src/legacy/core_plugins/kibana/public/dev_tools/render_app.tsx b/src/legacy/core_plugins/kibana/public/dev_tools/application.tsx similarity index 98% rename from src/legacy/core_plugins/kibana/public/dev_tools/render_app.tsx rename to src/legacy/core_plugins/kibana/public/dev_tools/application.tsx index e29b94e1485b2..3945d8d8dc856 100644 --- a/src/legacy/core_plugins/kibana/public/dev_tools/render_app.tsx +++ b/src/legacy/core_plugins/kibana/public/dev_tools/application.tsx @@ -29,7 +29,7 @@ import { AppMountContext } from 'kibana/public'; import { DevTool } from '../../../../../plugins/dev_tools/public'; interface DevToolsWrapperProps { - devTools: DevTool[]; + devTools: readonly DevTool[]; activeDevTool: DevTool; appMountContext: AppMountContext; updateRoute: (newRoute: string) => void; @@ -145,10 +145,10 @@ export function renderApp( element: HTMLElement, appMountContext: AppMountContext, basePath: string, - devTools: DevTool[] + devTools: readonly DevTool[] ) { if (redirectOnMissingCapabilities(appMountContext)) { - return; + return () => {}; } setBadge(appMountContext); setBreadcrumbs(appMountContext); diff --git a/src/legacy/core_plugins/kibana/public/dev_tools/plugin.ts b/src/legacy/core_plugins/kibana/public/dev_tools/plugin.ts index 066ef92c0c6ad..ec9af1a6acd92 100644 --- a/src/legacy/core_plugins/kibana/public/dev_tools/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/dev_tools/plugin.ts @@ -36,7 +36,7 @@ export interface DevToolsPluginStartDependencies { } export class DevToolsPlugin implements Plugin { - private getSortedDevTools: (() => DevTool[]) | null = null; + private getSortedDevTools: (() => readonly DevTool[]) | null = null; public setup( core: CoreSetup, @@ -49,7 +49,7 @@ export class DevToolsPlugin implements Plugin { if (!this.getSortedDevTools) { throw new Error('not started yet'); } - const { renderApp } = await import('./render_app'); + const { renderApp } = await import('./application'); return renderApp( params.element, appMountContext, @@ -60,7 +60,7 @@ export class DevToolsPlugin implements Plugin { }); } - start(core: CoreStart, { newPlatformDevTools }: DevToolsPluginStartDependencies) { + public start(core: CoreStart, { newPlatformDevTools }: DevToolsPluginStartDependencies) { this.getSortedDevTools = newPlatformDevTools.getSortedDevTools; if (this.getSortedDevTools().length === 0) { core.chrome.navLinks.update('kibana:dev_tools', { diff --git a/src/plugins/dev_tools/README.md b/src/plugins/dev_tools/README.md new file mode 100644 index 0000000000000..1610411b9c98e --- /dev/null +++ b/src/plugins/dev_tools/README.md @@ -0,0 +1,29 @@ +# Dev tools plugin + +The ui/registry/dev_tools is removed in favor of the `dev_tools` plugin which exposes a register method in the setup contract. +Registering app works mostly the same as registering apps in core.application.register. +Routing will be handled by the id of the dev tool - your dev tool will be mounted when the URL matches `/app/kibana#/dev_tools/`. +This API doesn't support angular, for registering angular dev tools, bootstrap a local module on mount into the given HTML element. + +During the migration this plugin exposes the registered dev tools in the start contract. This is necessary to keep the dev tools app +which is still living in the legacy platform working and will be removed once everything is moved over to the new platform. It should +not be used by other plugins. + +## Example registration + +```ts +// For legacy plugins +import { npSetup } from 'ui/new_platform'; +npSetup.plugins.dev_tools.register(/* same details here */); + +// For new plugins: first add 'dev_tools' to the list of `optionalPlugins` +// in your kibana.json file. Then access the plugin directly in `setup`: + +class MyPlugin { + setup(core, plugins) { + if (plugins.dev_tools) { + plugins.dev_tools.register(/* same details here. */); + } + } +} +``` diff --git a/src/plugins/dev_tools/public/plugin.ts b/src/plugins/dev_tools/public/plugin.ts index d913f02b99d21..8098308c0882b 100644 --- a/src/plugins/dev_tools/public/plugin.ts +++ b/src/plugins/dev_tools/public/plugin.ts @@ -43,7 +43,7 @@ export interface DevToolsStart { * becomes an implementation detail. * @deprecated */ - getSortedDevTools: () => DevTool[]; + getSortedDevTools: () => readonly DevTool[]; } /** @@ -87,21 +87,27 @@ export interface DevTool { } export class DevToolsPlugin implements Plugin { - private devTools: DevTool[] = []; + private readonly devTools = new Map(); - private getSortedDevTools() { - return sortBy(this.devTools, 'order'); + private getSortedDevTools(): readonly DevTool[] { + return sortBy([...this.devTools.values()], 'order'); } public setup(core: CoreSetup) { return { register: (devTool: DevTool) => { - this.devTools.push(devTool); + if (this.devTools.has(devTool.id)) { + throw new Error( + `Dev tool with id [${devTool.id}] has already been registered. Use a unique id.` + ); + } + + this.devTools.set(devTool.id, devTool); }, }; } - start() { + public start() { return { getSortedDevTools: this.getSortedDevTools.bind(this), };