From 14047360b7394fece9652999da534d91914cb2cc Mon Sep 17 00:00:00 2001 From: oatkiller Date: Fri, 6 Dec 2019 10:01:53 -0500 Subject: [PATCH] style nits, register embeddable in setup --- x-pack/plugins/endpoint/public/plugin.ts | 18 +++--- .../applications/resolver_test/index.tsx | 62 +++++++++---------- .../plugins/resolver_test/public/plugin.ts | 16 ++++- 3 files changed, 55 insertions(+), 41 deletions(-) diff --git a/x-pack/plugins/endpoint/public/plugin.ts b/x-pack/plugins/endpoint/public/plugin.ts index 37cb9ee48872e..21bf1b3cdea12 100644 --- a/x-pack/plugins/endpoint/public/plugin.ts +++ b/x-pack/plugins/endpoint/public/plugin.ts @@ -4,18 +4,18 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Plugin, CoreStart } from 'kibana/public'; -import { IEmbeddableStart } from 'src/plugins/embeddable/public'; +import { Plugin, CoreSetup } from 'kibana/public'; +import { IEmbeddableSetup } from 'src/plugins/embeddable/public'; import { ResolverEmbeddableFactory } from './embeddables/resolver'; export type EndpointPluginStart = void; export type EndpointPluginSetup = void; -export interface EndpointPluginSetupDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface - -export interface EndpointPluginStartDependencies { - embeddable: IEmbeddableStart; +export interface EndpointPluginSetupDependencies { + embeddable: IEmbeddableSetup; } +export interface EndpointPluginStartDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface + export class EndpointPlugin implements Plugin< @@ -24,9 +24,7 @@ export class EndpointPlugin EndpointPluginSetupDependencies, EndpointPluginStartDependencies > { - public setup() {} - - public start(_core: CoreStart, plugins: EndpointPluginStartDependencies) { + public setup(_core: CoreSetup, plugins: EndpointPluginSetupDependencies) { const resolverEmbeddableFactory = new ResolverEmbeddableFactory(); plugins.embeddable.registerEmbeddableFactory( resolverEmbeddableFactory.type, @@ -34,5 +32,7 @@ export class EndpointPlugin ); } + public start() {} + public stop() {} } diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx index 67149d94ff69c..98baad6a18411 100644 --- a/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/applications/resolver_test/index.tsx @@ -30,34 +30,34 @@ export function renderApp( }; } -const AppRoot: React.FC<{ - embeddable: Promise; -}> = React.memo(({ embeddable: embeddablePromise }) => { - const [embeddable, setEmbeddable] = React.useState(undefined); - const [renderTarget, setRenderTarget] = React.useState(null); - - useEffect(() => { - let reject; - Promise.race([ - new Promise((...args) => { - reject = args[1]; - }), - embeddablePromise, - ]).then(value => { - setEmbeddable(value); - }); - - return reject; - }, [embeddablePromise]); - - useEffect(() => { - if (embeddable && renderTarget) { - embeddable.render(renderTarget); - return () => { - embeddable.destroy(); - }; - } - }, [embeddable, renderTarget]); - - return
; -}); +const AppRoot = React.memo( + ({ embeddable: embeddablePromise }: { embeddable: Promise }) => { + const [embeddable, setEmbeddable] = React.useState(undefined); + const [renderTarget, setRenderTarget] = React.useState(null); + + useEffect(() => { + let cleanUp; + Promise.race([ + new Promise((_resolve, reject) => { + cleanUp = reject; + }), + embeddablePromise, + ]).then(value => { + setEmbeddable(value); + }); + + return cleanUp; + }, [embeddablePromise]); + + useEffect(() => { + if (embeddable && renderTarget) { + embeddable.render(renderTarget); + return () => { + embeddable.destroy(); + }; + } + }, [embeddable, renderTarget]); + + return
; + } +); diff --git a/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts index c7a81003a51dd..f063271f4b5dd 100644 --- a/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts +++ b/x-pack/test/plugin_functional/plugins/resolver_test/public/plugin.ts @@ -8,7 +8,21 @@ import { Plugin, CoreSetup } from 'kibana/public'; import { i18n } from '@kbn/i18n'; import { IEmbeddable, IEmbeddableStart } from '../../../../../../src/plugins/embeddable/public'; -export class ResolverTestPlugin implements Plugin { +export type ResolverTestPluginSetup = void; +export type ResolverTestPluginStart = void; +export interface ResolverTestPluginSetupDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface +export interface ResolverTestPluginStartDependencies { + embeddable: IEmbeddableStart; +} + +export class ResolverTestPlugin + implements + Plugin< + ResolverTestPluginSetup, + ResolverTestPluginStart, + ResolverTestPluginSetupDependencies, + ResolverTestPluginStartDependencies + > { private resolveEmbeddable!: ( value: IEmbeddable | undefined | PromiseLike | undefined ) => void;