Skip to content

Commit

Permalink
feat: 🎸 add EnhancedEmbeddable interface
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Apr 6, 2020
1 parent bd60130 commit 6a6caf5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
36 changes: 28 additions & 8 deletions x-pack/plugins/embeddable_enhanced/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
IEmbeddable,
defaultEmbeddableFactoryProvider,
} from '../../../../src/plugins/embeddable/public';
import { EnhancedEmbeddable } from './types';

export interface SetupDependencies {
embeddable: EmbeddableSetup;
Expand All @@ -39,6 +40,18 @@ export class EmbeddableEnhancedPlugin
constructor(protected readonly context: PluginInitializerContext) {}

public setup(core: CoreSetup<StartDependencies>, 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,
Expand All @@ -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<E extends IEmbeddable>(
embeddable: E
): EnhancedEmbeddable<E> {
const enhancedEmbeddable = embeddable as EnhancedEmbeddable<E>;

public stop() {}
enhancedEmbeddable.enhancements = {
...enhancedEmbeddable.enhancements,
dynamicActions: {} as any,
};

return enhancedEmbeddable;
}
}
17 changes: 17 additions & 0 deletions x-pack/plugins/embeddable_enhanced/public/types.ts
Original file line number Diff line number Diff line change
@@ -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 extends IEmbeddable = IEmbeddable> = E & {
enhancements: {
/**
* Default implementation of dynamic action manager for embeddables.
*/
dynamicActions: UiActionsDynamicActionManager;
};
};

0 comments on commit 6a6caf5

Please sign in to comment.