Skip to content

Commit

Permalink
style nits, register embeddable in setup
Browse files Browse the repository at this point in the history
  • Loading branch information
oatkiller committed Dec 6, 2019
1 parent bdd633d commit 1404736
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 41 deletions.
18 changes: 9 additions & 9 deletions x-pack/plugins/endpoint/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand All @@ -24,15 +24,15 @@ 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,
resolverEmbeddableFactory
);
}

public start() {}

public stop() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ export function renderApp(
};
}

const AppRoot: React.FC<{
embeddable: Promise<IEmbeddable | undefined>;
}> = React.memo(({ embeddable: embeddablePromise }) => {
const [embeddable, setEmbeddable] = React.useState<IEmbeddable | undefined>(undefined);
const [renderTarget, setRenderTarget] = React.useState<HTMLDivElement | null>(null);

useEffect(() => {
let reject;
Promise.race([
new Promise<never>((...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 <div data-test-subj="resolverEmbeddableContainer" ref={setRenderTarget} />;
});
const AppRoot = React.memo(
({ embeddable: embeddablePromise }: { embeddable: Promise<IEmbeddable | undefined> }) => {
const [embeddable, setEmbeddable] = React.useState<IEmbeddable | undefined>(undefined);
const [renderTarget, setRenderTarget] = React.useState<HTMLDivElement | null>(null);

useEffect(() => {
let cleanUp;
Promise.race([
new Promise<never>((_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 <div data-test-subj="resolverEmbeddableContainer" ref={setRenderTarget} />;
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEmbeddable | undefined> | undefined
) => void;
Expand Down

0 comments on commit 1404736

Please sign in to comment.