diff --git a/src/plugins/embeddable/public/mocks.tsx b/src/plugins/embeddable/public/mocks.tsx index ec1a272bbe574..7db4efd34e48e 100644 --- a/src/plugins/embeddable/public/mocks.tsx +++ b/src/plugins/embeddable/public/mocks.tsx @@ -99,7 +99,6 @@ const createSetupContract = (): Setup => { registerReactEmbeddableFactory: jest.fn().mockImplementation(registerReactEmbeddableFactory), registerEmbeddableFactory: jest.fn(), registerEnhancement: jest.fn(), - setCustomEmbeddableFactoryProvider: jest.fn(), }; return setupContract; }; diff --git a/src/plugins/embeddable/public/plugin.test.ts b/src/plugins/embeddable/public/plugin.test.ts index b51b7e7488a68..00a19f8e9f561 100644 --- a/src/plugins/embeddable/public/plugin.test.ts +++ b/src/plugins/embeddable/public/plugin.test.ts @@ -9,83 +9,6 @@ import { coreMock } from '@kbn/core/public/mocks'; import { testPlugin } from './tests/test_plugin'; -import { EmbeddableFactoryProvider } from './types'; -import { defaultEmbeddableFactoryProvider } from './lib'; -import { HelloWorldEmbeddable } from './tests/fixtures'; - -test('can set custom embeddable factory provider', async () => { - const coreSetup = coreMock.createSetup(); - const coreStart = coreMock.createStart(); - const { setup, doStart } = testPlugin(coreSetup, coreStart); - - const customProvider: EmbeddableFactoryProvider = (def) => ({ - ...defaultEmbeddableFactoryProvider(def), - getDisplayName: () => 'Intercepted!', - }); - - setup.setCustomEmbeddableFactoryProvider(customProvider); - setup.registerEmbeddableFactory('test', { - type: 'test', - latestVersion: '1.0.0', - create: () => Promise.resolve(undefined), - getDisplayName: () => 'Test', - isEditable: () => Promise.resolve(true), - }); - - const start = doStart(); - const factory = start.getEmbeddableFactory('test'); - expect(factory!.getDisplayName()).toEqual('Intercepted!'); -}); - -test('custom embeddable factory provider test for intercepting embeddable creation and destruction', async () => { - const coreSetup = coreMock.createSetup(); - const coreStart = coreMock.createStart(); - const { setup, doStart } = testPlugin(coreSetup, coreStart); - - let updateCount = 0; - const customProvider: EmbeddableFactoryProvider = (def) => { - return { - ...defaultEmbeddableFactoryProvider(def), - create: async (input, parent) => { - const embeddable = await defaultEmbeddableFactoryProvider(def).create(input, parent); - if (embeddable) { - const subscription = embeddable.getInput$().subscribe( - () => { - updateCount++; - }, - () => {}, - () => { - subscription.unsubscribe(); - updateCount = 0; - } - ); - } - return embeddable; - }, - }; - }; - - setup.setCustomEmbeddableFactoryProvider(customProvider); - setup.registerEmbeddableFactory('test', { - type: 'test', - latestVersion: '1.0.0', - create: (input, parent) => Promise.resolve(new HelloWorldEmbeddable(input, parent)), - getDisplayName: () => 'Test', - isEditable: () => Promise.resolve(true), - }); - - const start = doStart(); - const factory = start.getEmbeddableFactory('test'); - - const embeddable = await factory?.create({ id: '123' }); - embeddable!.updateInput({ title: 'boo' }); - // initial subscription, plus the second update. - expect(updateCount).toEqual(2); - - embeddable!.destroy(); - await new Promise((resolve) => process.nextTick(resolve)); - expect(updateCount).toEqual(0); -}); describe('embeddable factory', () => { const coreSetup = coreMock.createSetup(); diff --git a/src/plugins/embeddable/public/plugin.tsx b/src/plugins/embeddable/public/plugin.tsx index b3b363edd949d..ef339e5bacc2c 100644 --- a/src/plugins/embeddable/public/plugin.tsx +++ b/src/plugins/embeddable/public/plugin.tsx @@ -27,7 +27,6 @@ import type { ContentManagementPublicStart } from '@kbn/content-management-plugi import type { SavedObjectTaggingOssPluginStart } from '@kbn/saved-objects-tagging-oss-plugin/public'; import { EmbeddableFactoryRegistry, - EmbeddableFactoryProvider, EnhancementsRegistry, EnhancementRegistryDefinition, EnhancementRegistryItem, @@ -108,10 +107,6 @@ export interface EmbeddableSetup { * @deprecated */ registerEnhancement: (enhancement: EnhancementRegistryDefinition) => void; - /** - * @deprecated - */ - setCustomEmbeddableFactoryProvider: (customProvider: EmbeddableFactoryProvider) => void; } export interface EmbeddableStart extends PersistableStateService { @@ -137,7 +132,6 @@ export class EmbeddablePublicPlugin implements Plugin; @@ -154,25 +148,12 @@ export class EmbeddablePublicPlugin implements Plugin { - if (this.customEmbeddableFactoryProvider) { - throw new Error( - 'Custom embeddable factory provider is already set, and can only be set once' - ); - } - this.customEmbeddableFactoryProvider = provider; - }, }; } public start(core: CoreStart, deps: EmbeddableStartDependencies): EmbeddableStart { this.embeddableFactoryDefinitions.forEach((def) => { - this.embeddableFactories.set( - def.type, - this.customEmbeddableFactoryProvider - ? this.customEmbeddableFactoryProvider(def) - : defaultEmbeddableFactoryProvider(def) - ); + this.embeddableFactories.set(def.type, defaultEmbeddableFactoryProvider(def)); }); this.appListSubscription = core.application.applications$.subscribe((appList) => { @@ -311,12 +292,7 @@ export class EmbeddablePublicPlugin implements Plugin - i18n.translate('xpack.embeddableEnhanced.Drilldowns', { - defaultMessage: 'Drilldowns', - }), - getIconType: () => 'symlink', - order: 25, - }, -]; diff --git a/x-pack/plugins/embeddable_enhanced/public/actions/index.ts b/x-pack/plugins/embeddable_enhanced/public/actions/index.ts deleted file mode 100644 index c351935bbf8bb..0000000000000 --- a/x-pack/plugins/embeddable_enhanced/public/actions/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export * from './drilldown_grouping'; diff --git a/x-pack/plugins/embeddable_enhanced/public/index.ts b/x-pack/plugins/embeddable_enhanced/public/index.ts index e14c8629ced9b..c0242fecc0948 100644 --- a/x-pack/plugins/embeddable_enhanced/public/index.ts +++ b/x-pack/plugins/embeddable_enhanced/public/index.ts @@ -19,9 +19,7 @@ export function plugin(context: PluginInitializerContext) { return new EmbeddableEnhancedPlugin(context); } -export type { EnhancedEmbeddable, EnhancedEmbeddableContext } from './types'; export { type HasDynamicActions, apiHasDynamicActions, } from './embeddables/interfaces/has_dynamic_actions'; -export { drilldownGrouping as embeddableEnhancedDrilldownGrouping } from './actions'; diff --git a/x-pack/plugins/embeddable_enhanced/public/plugin.ts b/x-pack/plugins/embeddable_enhanced/public/plugin.ts index a76f33f095951..0e374070c00d1 100644 --- a/x-pack/plugins/embeddable_enhanced/public/plugin.ts +++ b/x-pack/plugins/embeddable_enhanced/public/plugin.ts @@ -6,23 +6,12 @@ */ import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public'; -import { - defaultEmbeddableFactoryProvider, - EmbeddableContext, - EmbeddableFactory, - EmbeddableFactoryDefinition, - EmbeddableInput, - EmbeddableOutput, - EmbeddableSetup, - EmbeddableStart, - IEmbeddable, -} from '@kbn/embeddable-plugin/public'; +import { EmbeddableSetup, EmbeddableStart } from '@kbn/embeddable-plugin/public'; import { apiHasUniqueId, EmbeddableApiContext, StateComparators, } from '@kbn/presentation-publishing'; -import type { FinderAttributes } from '@kbn/saved-objects-finder-plugin/common'; import { AdvancedUiActionsSetup, AdvancedUiActionsStart, @@ -30,13 +19,12 @@ import { UiActionsEnhancedDynamicActionManager as DynamicActionManager, } from '@kbn/ui-actions-enhanced-plugin/public'; import deepEqual from 'react-fast-compare'; -import { BehaviorSubject, distinctUntilChanged } from 'rxjs'; +import { BehaviorSubject } from 'rxjs'; import { DynamicActionStorage, type DynamicActionStorageApi, } from './embeddables/dynamic_action_storage'; import { HasDynamicActions } from './embeddables/interfaces/has_dynamic_actions'; -import { EnhancedEmbeddable } from './types'; import { getDynamicActionsState } from './get_dynamic_actions_state'; export interface SetupDependencies { @@ -79,8 +67,6 @@ export class EmbeddableEnhancedPlugin private uiActions?: StartDependencies['uiActionsEnhanced']; public setup(core: CoreSetup, plugins: SetupDependencies): SetupContract { - this.setCustomEmbeddableFactoryProvider(plugins); - return {}; } @@ -94,45 +80,6 @@ export class EmbeddableEnhancedPlugin public stop() {} - private setCustomEmbeddableFactoryProvider(plugins: SetupDependencies) { - plugins.embeddable.setCustomEmbeddableFactoryProvider( - < - I extends EmbeddableInput = EmbeddableInput, - O extends EmbeddableOutput = EmbeddableOutput, - E extends IEmbeddable = IEmbeddable, - T extends FinderAttributes = {} - >( - def: EmbeddableFactoryDefinition - ): EmbeddableFactory => { - const factory: EmbeddableFactory = defaultEmbeddableFactoryProvider( - def - ); - return { - ...factory, - create: async (...args) => { - const embeddable = await factory.create(...args); - if (!embeddable) return embeddable; - return this.enhanceEmbeddableWithDynamicActions(embeddable); - }, - createFromSavedObject: async (...args) => { - const embeddable = await factory.createFromSavedObject(...args); - if (!embeddable) return embeddable; - return this.enhanceEmbeddableWithDynamicActions(embeddable); - }, - }; - } - ); - } - - private readonly isEmbeddableContext = (context: unknown): context is EmbeddableContext => { - if (!(context as EmbeddableContext)?.embeddable) { - // eslint-disable-next-line no-console - console.warn('For drilldowns to work action context should contain .embeddable field.'); - return false; - } - return true; - }; - private initializeDynamicActions( uuid: string, getTitle: () => string | undefined, @@ -183,77 +130,6 @@ export class EmbeddableEnhancedPlugin }; } - /** - * TODO: Remove this entire enhanceEmbeddableWithDynamicActions method once the embeddable refactor work is complete - */ - private enhanceEmbeddableWithDynamicActions( - embeddable: E - ): EnhancedEmbeddable { - const enhancedEmbeddable = embeddable as EnhancedEmbeddable; - - const dynamicActionsState$ = new BehaviorSubject( - { - dynamicActions: { events: [] }, - ...(embeddable.getInput().enhancements ?? {}), - } - ); - const api = { - dynamicActionsState$, - setDynamicActions: (newState: DynamicActionsSerializedState['enhancements']) => { - embeddable.updateInput({ enhancements: newState }); - }, - }; - - /** - * Keep the dynamicActionsState$ publishing subject in sync with changes to the embeddable's input. - */ - embeddable - .getInput$() - .pipe( - distinctUntilChanged(({ enhancements: old }, { enhancements: updated }) => - deepEqual(old, updated) - ) - ) - .subscribe((input) => { - dynamicActionsState$.next({ - dynamicActions: { events: [] }, - ...(input.enhancements ?? {}), - } as DynamicActionsSerializedState['enhancements']); - }); - - const storage = new DynamicActionStorage( - String(embeddable.runtimeId), - embeddable.getTitle, - api - ); - const dynamicActions = new DynamicActionManager({ - isCompatible: async (context: unknown) => { - if (!this.isEmbeddableContext(context)) return false; - return context.embeddable.runtimeId === embeddable.runtimeId; - }, - storage, - uiActions: this.uiActions!, - }); - - const stop = this.startDynamicActions(dynamicActions); - embeddable.getInput$().subscribe({ - next: () => { - storage.reload$.next(); - }, - error: stop, - complete: stop, - }); - - enhancedEmbeddable.enhancements = { - ...enhancedEmbeddable.enhancements, - dynamicActions, - }; - enhancedEmbeddable.dynamicActionsState$ = api.dynamicActionsState$; - enhancedEmbeddable.setDynamicActions = api.setDynamicActions; - - return enhancedEmbeddable; - } - private startDynamicActions(dynamicActions: DynamicActionManager) { dynamicActions.start().catch((error) => { /* eslint-disable no-console */ diff --git a/x-pack/plugins/embeddable_enhanced/public/types.ts b/x-pack/plugins/embeddable_enhanced/public/types.ts deleted file mode 100644 index c065e3b89060e..0000000000000 --- a/x-pack/plugins/embeddable_enhanced/public/types.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { IEmbeddable } from '@kbn/embeddable-plugin/public'; -import { HasDynamicActions } from './embeddables/interfaces/has_dynamic_actions'; - -export type EnhancedEmbeddable = E & HasDynamicActions; - -/** - * @deprecated use `EmbeddableApiContext` from `@kbn/presentation-publishing` - */ -export interface EnhancedEmbeddableContext { - embeddable: EnhancedEmbeddable; -} diff --git a/x-pack/plugins/embeddable_enhanced/tsconfig.json b/x-pack/plugins/embeddable_enhanced/tsconfig.json index 7aa9a6a2f42a6..a065672b9162a 100644 --- a/x-pack/plugins/embeddable_enhanced/tsconfig.json +++ b/x-pack/plugins/embeddable_enhanced/tsconfig.json @@ -9,12 +9,9 @@ "kbn_references": [ "@kbn/core", "@kbn/embeddable-plugin", - "@kbn/ui-actions-plugin", "@kbn/ui-actions-enhanced-plugin", - "@kbn/i18n", "@kbn/kibana-utils-plugin", "@kbn/data-plugin", - "@kbn/saved-objects-finder-plugin", "@kbn/presentation-publishing", ], "exclude": [