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

Use embeddable v2 - fix regression of #39126 #41221

Merged
merged 2 commits into from
Jul 18, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

alexwizp marked this conversation as resolved.
Show resolved Hide resolved
constructor(private visTypes: VisTypesRegistry) {
super({
savedObjectMetaData: {
name: i18n.translate('kbn.visualize.savedObjectName', { defaultMessage: 'Visualization' }),
Expand Down Expand Up @@ -117,7 +124,6 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
},
},
});
this.initializeVisTypes();
}

public isEditable() {
Expand All @@ -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 },
Expand Down Expand Up @@ -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);
});
38 changes: 29 additions & 9 deletions src/legacy/ui/public/registry/_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import _ from 'lodash';
import { IndexedArray } from '../indexed_array';

const notPropsOptNames = IndexedArray.OPT_NAMES.concat('constructor', 'invokeProviders');

/**
Expand Down Expand Up @@ -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
*
Expand All @@ -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));
}

return set;
};

iaOpts.initialSet = getInvokedProviders(providers);

// index all of the modules
let modules = new IndexedArray(iaOpts);
modules = new IndexedArray(iaOpts);

// mixin other props
_.assign(modules, props);
Expand All @@ -107,13 +116,24 @@ export function uiRegistry(spec) {
modules = $injector.invoke(constructor, modules) || modules;
}

isInstantiated = true;

return modules;
};

registry.displayName = '[registry ' + props.name + ']';

registry.register = function (privateModule) {
providers.push(privateModule);

if (isInstantiated) {
const [provider] = getInvokedProviders([privateModule]);

if (provider) {
modules.push(provider);
}
}

return registry;
};

Expand Down