Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[embeddable] remove setCustomEmbeddableFactoryProvider from setup API #203853

Merged
merged 8 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/plugins/embeddable/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ const createSetupContract = (): Setup => {
registerReactEmbeddableFactory: jest.fn().mockImplementation(registerReactEmbeddableFactory),
registerEmbeddableFactory: jest.fn(),
registerEnhancement: jest.fn(),
setCustomEmbeddableFactoryProvider: jest.fn(),
};
return setupContract;
};
Expand Down
77 changes: 0 additions & 77 deletions src/plugins/embeddable/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
28 changes: 2 additions & 26 deletions src/plugins/embeddable/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -111,10 +110,6 @@ export interface EmbeddableSetup {
* @deprecated
*/
registerEnhancement: (enhancement: EnhancementRegistryDefinition) => void;
/**
* @deprecated
*/
setCustomEmbeddableFactoryProvider: (customProvider: EmbeddableFactoryProvider) => void;
}

export interface EmbeddableStart extends PersistableStateService<EmbeddableStateWithType> {
Expand Down Expand Up @@ -153,7 +148,6 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
new Map();
private readonly embeddableFactories: EmbeddableFactoryRegistry = new Map();
private readonly enhancements: EnhancementsRegistry = new Map();
private customEmbeddableFactoryProvider?: EmbeddableFactoryProvider;
private stateTransferService: EmbeddableStateTransfer = {} as EmbeddableStateTransfer;
private isRegistryReady = false;
private appList?: ReadonlyMap<string, PublicAppInfo>;
Expand All @@ -170,25 +164,12 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl

registerEmbeddableFactory: this.registerEmbeddableFactory,
registerEnhancement: this.registerEnhancement,
setCustomEmbeddableFactoryProvider: (provider: EmbeddableFactoryProvider) => {
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) => {
Expand Down Expand Up @@ -329,12 +310,7 @@ export class EmbeddablePublicPlugin implements Plugin<EmbeddableSetup, Embeddabl
if (!this.embeddableFactories.get(type)) {
const def = this.embeddableFactoryDefinitions.get(type);
if (!def) return;
this.embeddableFactories.set(
type,
this.customEmbeddableFactoryProvider
? this.customEmbeddableFactoryProvider(def)
: defaultEmbeddableFactoryProvider(def)
);
this.embeddableFactories.set(type, defaultEmbeddableFactoryProvider(def));
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -15943,7 +15943,6 @@
"xpack.elasticAssistantPlugin.attackDiscovery.defaultAttackDiscoveryGraph.nodes.retriever.helpers.throwIfErrorCountsExceeded.maxGenerationAttemptsErrorMessage": "Nombre maximum de tentatives de génération ({generationAttempts}) atteint. Essayez d'envoyer un nombre d'alertes moins élevé à ce modèle.",
"xpack.elasticAssistantPlugin.attackDiscovery.defaultAttackDiscoveryGraph.nodes.retriever.helpers.throwIfErrorCountsExceeded.maxHallucinationFailuresErrorMessage": "Nombre maximum d'échecs d'hallucinations ({hallucinationFailures}) atteint. Essayez d'envoyer un nombre d'alertes moins élevé à ce modèle.",
"xpack.elasticAssistantPlugin.server.newChat": "Nouveau chat",
"xpack.embeddableEnhanced.Drilldowns": "Explorations",
"xpack.enterpriseSearch.accessControlIndexSelector.p.accessControlSyncsAreLabel": "Les synchronisations de contrôle d'accès maintiennent les informations d'autorisation à jour pour assurer la sécurité au niveau du document (DLS)",
"xpack.enterpriseSearch.actions.backButtonLabel": "Retour",
"xpack.enterpriseSearch.actions.cancelButtonLabel": "Annuler",
Expand Down Expand Up @@ -26138,9 +26137,9 @@
"xpack.lens.app.settingsAriaLabel": "Ouvrir le menu de paramètres Lens",
"xpack.lens.app.share.defaultDashboardTitle": "Visualisation Lens [{date}]",
"xpack.lens.app.shareButtonDisabledWarning": "La visualisation ne comprend aucune donnée à partager.",
"xpack.lens.app.shareModal.title": "Partager cette visualisation Lens",
"xpack.lens.app.shareModal.draftModeCallout.link.warning": "Copiez le lien afin d’obtenir un lien temporaire. Enregistrez la visualisation Lens pour créer un lien permanent.",
"xpack.lens.app.shareModal.draftModeCallout.title": "Modifications non enregistrées",
"xpack.lens.app.shareModal.title": "Partager cette visualisation Lens",
"xpack.lens.app.shareTitle": "Partager",
"xpack.lens.app.shareTitleAria": "Partager la visualisation",
"xpack.lens.app.showUnderlyingDataMultipleLayers": "Impossible d’afficher les données sous-jacentes pour les visualisations avec plusieurs calques.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15806,7 +15806,6 @@
"xpack.elasticAssistantPlugin.attackDiscovery.defaultAttackDiscoveryGraph.nodes.retriever.helpers.throwIfErrorCountsExceeded.maxGenerationAttemptsErrorMessage": "最大生成試行回数({generationAttempts})に達しました。このモデルに送信するアラートの数を減らしてください。",
"xpack.elasticAssistantPlugin.attackDiscovery.defaultAttackDiscoveryGraph.nodes.retriever.helpers.throwIfErrorCountsExceeded.maxHallucinationFailuresErrorMessage": "最大ハルシネーション失敗回数({hallucinationFailures})に達しました。このモデルに送信するアラートの数を減らしてください。",
"xpack.elasticAssistantPlugin.server.newChat": "新しいチャット",
"xpack.embeddableEnhanced.Drilldowns": "ドリルダウン",
"xpack.enterpriseSearch.accessControlIndexSelector.p.accessControlSyncsAreLabel": "アクセス制御の同期により、ドキュメントレベルセキュリティ(DLS)の権限情報が最新の状態に保たれます。",
"xpack.enterpriseSearch.actions.backButtonLabel": "戻る",
"xpack.enterpriseSearch.actions.cancelButtonLabel": "キャンセル",
Expand Down Expand Up @@ -25997,9 +25996,9 @@
"xpack.lens.app.settingsAriaLabel": "Lens設定メニューを開く",
"xpack.lens.app.share.defaultDashboardTitle": "Lensビジュアライゼーション[{date}]",
"xpack.lens.app.shareButtonDisabledWarning": "ビジュアライゼーションには共有するデータがありません。",
"xpack.lens.app.shareModal.title": "このLensビジュアライゼーションを共有",
"xpack.lens.app.shareModal.draftModeCallout.link.warning": "リンクをコピーして、一時リンクを取得します。Lensビジュアライゼーションを保存して、永続リンクを作成します。",
"xpack.lens.app.shareModal.draftModeCallout.title": "保存されていない変更",
"xpack.lens.app.shareModal.title": "このLensビジュアライゼーションを共有",
"xpack.lens.app.shareTitle": "共有",
"xpack.lens.app.shareTitleAria": "ビジュアライゼーションを共有",
"xpack.lens.app.showUnderlyingDataMultipleLayers": "複数レイヤーのビジュアライゼーションでは、基本データを表示できません",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15526,7 +15526,6 @@
"xpack.elasticAssistantPlugin.attackDiscovery.defaultAttackDiscoveryGraph.nodes.retriever.helpers.throwIfErrorCountsExceeded.maxGenerationAttemptsErrorMessage": "已达到最大生成尝试次数 ({generationAttempts})。尝试向此模型发送更少的告警。",
"xpack.elasticAssistantPlugin.attackDiscovery.defaultAttackDiscoveryGraph.nodes.retriever.helpers.throwIfErrorCountsExceeded.maxHallucinationFailuresErrorMessage": "已达到最大幻觉失败次数 ({hallucinationFailures})。尝试向此模型发送更少的告警。",
"xpack.elasticAssistantPlugin.server.newChat": "新聊天",
"xpack.embeddableEnhanced.Drilldowns": "向下钻取",
"xpack.enterpriseSearch.accessControlIndexSelector.p.accessControlSyncsAreLabel": "访问控制同步会使权限信息保持最新以实现文档级别安全性 (DLS)",
"xpack.enterpriseSearch.actions.backButtonLabel": "返回",
"xpack.enterpriseSearch.actions.cancelButtonLabel": "取消",
Expand Down Expand Up @@ -25559,9 +25558,9 @@
"xpack.lens.app.settingsAriaLabel": "打开 Lens 设置菜单",
"xpack.lens.app.share.defaultDashboardTitle": "Lens 可视化 [{date}]",
"xpack.lens.app.shareButtonDisabledWarning": "此可视化没有可共享的数据。",
"xpack.lens.app.shareModal.title": "共享此 Lens 可视化",
"xpack.lens.app.shareModal.draftModeCallout.link.warning": "复制链接以获取临时链接。保存 Lens 可视化以创建永久链接。",
"xpack.lens.app.shareModal.draftModeCallout.title": "未保存的更改",
"xpack.lens.app.shareModal.title": "共享此 Lens 可视化",
"xpack.lens.app.shareTitle": "共享",
"xpack.lens.app.shareTitleAria": "共享可视化",
"xpack.lens.app.showUnderlyingDataMultipleLayers": "无法显示具有多个图层的可视化的底层数据",
Expand Down

This file was deleted.

8 changes: 0 additions & 8 deletions x-pack/plugins/embeddable_enhanced/public/actions/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions x-pack/plugins/embeddable_enhanced/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Loading
Loading