From 6a6caf5a80404a835bcbf7f1d480bdcc822b69d9 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 6 Apr 2020 18:40:29 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20EnhancedEmbeddable?= =?UTF-8?q?=20interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/lib/embeddables/i_embeddable.ts | 5 +++ .../embeddable_enhanced/public/plugin.ts | 36 ++++++++++++++----- .../embeddable_enhanced/public/types.ts | 17 +++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 x-pack/plugins/embeddable_enhanced/public/types.ts diff --git a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts index 9a4452aceba0..b1b904d215cf 100644 --- a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts +++ b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts @@ -91,6 +91,11 @@ export interface IEmbeddable< */ readonly runtimeId?: number; + /** + * Extra abilities added to Embeddable by `*_enhanced` plugins. + */ + enhancements?: object; + /** * Default implementation of dynamic action API for embeddables. */ diff --git a/x-pack/plugins/embeddable_enhanced/public/plugin.ts b/x-pack/plugins/embeddable_enhanced/public/plugin.ts index b3938b10f89f..60f67905af95 100644 --- a/x-pack/plugins/embeddable_enhanced/public/plugin.ts +++ b/x-pack/plugins/embeddable_enhanced/public/plugin.ts @@ -17,6 +17,7 @@ import { IEmbeddable, defaultEmbeddableFactoryProvider, } from '../../../../src/plugins/embeddable/public'; +import { EnhancedEmbeddable } from './types'; export interface SetupDependencies { embeddable: EmbeddableSetup; @@ -39,6 +40,18 @@ export class EmbeddableEnhancedPlugin constructor(protected readonly context: PluginInitializerContext) {} public setup(core: CoreSetup, plugins: SetupDependencies): SetupContract { + this.setCustomEmbeddableFactoryProvider(plugins); + + return {}; + } + + public start(core: CoreStart, plugins: StartDependencies): StartContract { + return {}; + } + + public stop() {} + + private setCustomEmbeddableFactoryProvider(plugins: SetupDependencies) { plugins.embeddable.setCustomEmbeddableFactoryProvider( < I extends EmbeddableInput = EmbeddableInput, @@ -55,22 +68,29 @@ export class EmbeddableEnhancedPlugin ...factory, create: async (...args) => { const embeddable = await factory.create(...args); - return embeddable; + if (!embeddable) return embeddable; + return this.enhanceEmbeddableWithDynamicActions(embeddable); }, createFromSavedObject: async (...args) => { const embeddable = await factory.createFromSavedObject(...args); - return embeddable; + if (!embeddable) return embeddable; + return this.enhanceEmbeddableWithDynamicActions(embeddable); }, }; } ); - - return {}; } - public start(core: CoreStart, plugins: StartDependencies): StartContract { - return {}; - } + private enhanceEmbeddableWithDynamicActions( + embeddable: E + ): EnhancedEmbeddable { + const enhancedEmbeddable = embeddable as EnhancedEmbeddable; - public stop() {} + enhancedEmbeddable.enhancements = { + ...enhancedEmbeddable.enhancements, + dynamicActions: {} as any, + }; + + return enhancedEmbeddable; + } } diff --git a/x-pack/plugins/embeddable_enhanced/public/types.ts b/x-pack/plugins/embeddable_enhanced/public/types.ts new file mode 100644 index 000000000000..54d49e06e9d9 --- /dev/null +++ b/x-pack/plugins/embeddable_enhanced/public/types.ts @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { IEmbeddable } from '../../../../src/plugins/embeddable/public'; +import { UiActionsDynamicActionManager } from '../../../../src/plugins/ui_actions/public'; + +export type EnhancedEmbeddable = E & { + enhancements: { + /** + * Default implementation of dynamic action manager for embeddables. + */ + dynamicActions: UiActionsDynamicActionManager; + }; +};