mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* Use embeddable v2 - fix regression of #39126 * fix PR comment
This commit is contained in:
parent
fb34101bcd
commit
c03698f0d4
3 changed files with 41 additions and 20 deletions
|
@ -18,5 +18,4 @@
|
|||
*/
|
||||
export { DisabledLabEmbeddable } from './disabled_lab_embeddable';
|
||||
export { VisualizeEmbeddable, VisualizeInput } from './visualize_embeddable';
|
||||
export { VisualizeEmbeddableFactory } from './visualize_embeddable_factory';
|
||||
export { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
|
||||
|
|
|
@ -78,10 +78,17 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
|
|||
VisualizeEmbeddable | DisabledLabEmbeddable,
|
||||
VisualizationAttributes
|
||||
> {
|
||||
private visTypes?: VisTypesRegistry;
|
||||
public readonly type = VISUALIZE_EMBEDDABLE_TYPE;
|
||||
|
||||
constructor() {
|
||||
static async createVisualizeEmbeddableFactory(): Promise<VisualizeEmbeddableFactory> {
|
||||
const $injector = await chrome.dangerouslyGetActiveInjector();
|
||||
const Private = $injector.get<IPrivate>('Private');
|
||||
const visTypes = Private(VisTypesRegistryProvider);
|
||||
|
||||
return new VisualizeEmbeddableFactory(visTypes);
|
||||
}
|
||||
|
||||
constructor(private visTypes: VisTypesRegistry) {
|
||||
super({
|
||||
savedObjectMetaData: {
|
||||
name: i18n.translate('kbn.visualize.savedObjectName', { defaultMessage: 'Visualization' }),
|
||||
|
@ -117,7 +124,6 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
|
|||
},
|
||||
},
|
||||
});
|
||||
this.initializeVisTypes();
|
||||
}
|
||||
|
||||
public isEditable() {
|
||||
|
@ -130,12 +136,6 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
|
|||
});
|
||||
}
|
||||
|
||||
public async initializeVisTypes() {
|
||||
const $injector = await chrome.dangerouslyGetActiveInjector();
|
||||
const Private = $injector.get<IPrivate>('Private');
|
||||
this.visTypes = Private(VisTypesRegistryProvider);
|
||||
}
|
||||
|
||||
public async createFromSavedObject(
|
||||
savedObjectId: string,
|
||||
input: Partial<VisualizeInput> & { id: string },
|
||||
|
@ -188,4 +188,6 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
|
|||
}
|
||||
}
|
||||
|
||||
embeddableFactories.set(VISUALIZE_EMBEDDABLE_TYPE, new VisualizeEmbeddableFactory());
|
||||
VisualizeEmbeddableFactory.createVisualizeEmbeddableFactory().then(embeddableFactory => {
|
||||
embeddableFactories.set(VISUALIZE_EMBEDDABLE_TYPE, embeddableFactory);
|
||||
});
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
import _ from 'lodash';
|
||||
import { IndexedArray } from '../indexed_array';
|
||||
|
||||
const notPropsOptNames = IndexedArray.OPT_NAMES.concat('constructor', 'invokeProviders');
|
||||
|
||||
/**
|
||||
|
@ -78,6 +79,10 @@ export function uiRegistry(spec) {
|
|||
const props = _.omit(spec, notPropsOptNames);
|
||||
const providers = [];
|
||||
|
||||
let isInstantiated = false;
|
||||
let getInvokedProviders;
|
||||
let modules;
|
||||
|
||||
/**
|
||||
* This is the Private module that will be instantiated by
|
||||
*
|
||||
|
@ -87,17 +92,21 @@ export function uiRegistry(spec) {
|
|||
* defines how things will be indexed.
|
||||
*/
|
||||
const registry = function (Private, $injector) {
|
||||
// call the registered providers to get their values
|
||||
iaOpts.initialSet = invokeProviders
|
||||
? $injector.invoke(invokeProviders, undefined, { providers })
|
||||
: providers.map(Private);
|
||||
getInvokedProviders = function (newProviders) {
|
||||
let set = invokeProviders
|
||||
? $injector.invoke(invokeProviders, undefined, { providers: newProviders })
|
||||
: newProviders.map(Private);
|
||||
|
||||
if (filter && _.isFunction(filter)) {
|
||||
iaOpts.initialSet = iaOpts.initialSet.filter(item => filter(item));
|
||||
}
|
||||
if (filter && _.isFunction(filter)) {
|
||||
set = set.filter(item => filter(item));
|
||||
}
|
||||
|
||||
// index all of the modules
|
||||
let modules = new IndexedArray(iaOpts);
|
||||
return set;
|
||||
};
|
||||
|
||||
iaOpts.initialSet = getInvokedProviders(providers);
|
||||
|
||||
modules = new IndexedArray(iaOpts);
|
||||
|
||||
// mixin other props
|
||||
_.assign(modules, props);
|
||||
|
@ -107,6 +116,8 @@ export function uiRegistry(spec) {
|
|||
modules = $injector.invoke(constructor, modules) || modules;
|
||||
}
|
||||
|
||||
isInstantiated = true;
|
||||
|
||||
return modules;
|
||||
};
|
||||
|
||||
|
@ -114,6 +125,15 @@ export function uiRegistry(spec) {
|
|||
|
||||
registry.register = function (privateModule) {
|
||||
providers.push(privateModule);
|
||||
|
||||
if (isInstantiated) {
|
||||
const [provider] = getInvokedProviders([privateModule]);
|
||||
|
||||
if (provider) {
|
||||
modules.push(provider);
|
||||
}
|
||||
}
|
||||
|
||||
return registry;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue