mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -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 { DisabledLabEmbeddable } from './disabled_lab_embeddable';
|
||||||
export { VisualizeEmbeddable, VisualizeInput } from './visualize_embeddable';
|
export { VisualizeEmbeddable, VisualizeInput } from './visualize_embeddable';
|
||||||
export { VisualizeEmbeddableFactory } from './visualize_embeddable_factory';
|
|
||||||
export { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
|
export { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
|
||||||
|
|
|
@ -78,10 +78,17 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
|
||||||
VisualizeEmbeddable | DisabledLabEmbeddable,
|
VisualizeEmbeddable | DisabledLabEmbeddable,
|
||||||
VisualizationAttributes
|
VisualizationAttributes
|
||||||
> {
|
> {
|
||||||
private visTypes?: VisTypesRegistry;
|
|
||||||
public readonly type = VISUALIZE_EMBEDDABLE_TYPE;
|
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({
|
super({
|
||||||
savedObjectMetaData: {
|
savedObjectMetaData: {
|
||||||
name: i18n.translate('kbn.visualize.savedObjectName', { defaultMessage: 'Visualization' }),
|
name: i18n.translate('kbn.visualize.savedObjectName', { defaultMessage: 'Visualization' }),
|
||||||
|
@ -117,7 +124,6 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.initializeVisTypes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public isEditable() {
|
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(
|
public async createFromSavedObject(
|
||||||
savedObjectId: string,
|
savedObjectId: string,
|
||||||
input: Partial<VisualizeInput> & { id: 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 _ from 'lodash';
|
||||||
import { IndexedArray } from '../indexed_array';
|
import { IndexedArray } from '../indexed_array';
|
||||||
|
|
||||||
const notPropsOptNames = IndexedArray.OPT_NAMES.concat('constructor', 'invokeProviders');
|
const notPropsOptNames = IndexedArray.OPT_NAMES.concat('constructor', 'invokeProviders');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,6 +79,10 @@ export function uiRegistry(spec) {
|
||||||
const props = _.omit(spec, notPropsOptNames);
|
const props = _.omit(spec, notPropsOptNames);
|
||||||
const providers = [];
|
const providers = [];
|
||||||
|
|
||||||
|
let isInstantiated = false;
|
||||||
|
let getInvokedProviders;
|
||||||
|
let modules;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the Private module that will be instantiated by
|
* This is the Private module that will be instantiated by
|
||||||
*
|
*
|
||||||
|
@ -87,17 +92,21 @@ export function uiRegistry(spec) {
|
||||||
* defines how things will be indexed.
|
* defines how things will be indexed.
|
||||||
*/
|
*/
|
||||||
const registry = function (Private, $injector) {
|
const registry = function (Private, $injector) {
|
||||||
// call the registered providers to get their values
|
getInvokedProviders = function (newProviders) {
|
||||||
iaOpts.initialSet = invokeProviders
|
let set = invokeProviders
|
||||||
? $injector.invoke(invokeProviders, undefined, { providers })
|
? $injector.invoke(invokeProviders, undefined, { providers: newProviders })
|
||||||
: providers.map(Private);
|
: newProviders.map(Private);
|
||||||
|
|
||||||
if (filter && _.isFunction(filter)) {
|
if (filter && _.isFunction(filter)) {
|
||||||
iaOpts.initialSet = iaOpts.initialSet.filter(item => filter(item));
|
set = set.filter(item => filter(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
// index all of the modules
|
return set;
|
||||||
let modules = new IndexedArray(iaOpts);
|
};
|
||||||
|
|
||||||
|
iaOpts.initialSet = getInvokedProviders(providers);
|
||||||
|
|
||||||
|
modules = new IndexedArray(iaOpts);
|
||||||
|
|
||||||
// mixin other props
|
// mixin other props
|
||||||
_.assign(modules, props);
|
_.assign(modules, props);
|
||||||
|
@ -107,6 +116,8 @@ export function uiRegistry(spec) {
|
||||||
modules = $injector.invoke(constructor, modules) || modules;
|
modules = $injector.invoke(constructor, modules) || modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isInstantiated = true;
|
||||||
|
|
||||||
return modules;
|
return modules;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,6 +125,15 @@ export function uiRegistry(spec) {
|
||||||
|
|
||||||
registry.register = function (privateModule) {
|
registry.register = function (privateModule) {
|
||||||
providers.push(privateModule);
|
providers.push(privateModule);
|
||||||
|
|
||||||
|
if (isInstantiated) {
|
||||||
|
const [provider] = getInvokedProviders([privateModule]);
|
||||||
|
|
||||||
|
if (provider) {
|
||||||
|
modules.push(provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return registry;
|
return registry;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue