Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Nov 12, 2019
1 parent 1d6faa6 commit 38498db
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/core_plugins/kibana/public/dev_tools/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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', {
Expand Down
29 changes: 29 additions & 0 deletions src/plugins/dev_tools/README.md
Original file line number Diff line number Diff line change
@@ -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/<YOUR ID>`.
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. */);
}
}
}
```
18 changes: 12 additions & 6 deletions src/plugins/dev_tools/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface DevToolsStart {
* becomes an implementation detail.
* @deprecated
*/
getSortedDevTools: () => DevTool[];
getSortedDevTools: () => readonly DevTool[];
}

/**
Expand Down Expand Up @@ -87,21 +87,27 @@ export interface DevTool {
}

export class DevToolsPlugin implements Plugin<DevToolsSetup, DevToolsStart> {
private devTools: DevTool[] = [];
private readonly devTools = new Map<string, DevTool>();

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),
};
Expand Down

0 comments on commit 38498db

Please sign in to comment.