Skip to content

Commit e817686

Browse files
committed
inject chrome properly
1 parent f112668 commit e817686

6 files changed

Lines changed: 28 additions & 15 deletions

File tree

src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_helpers.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import React from 'react';
2020
import { render } from 'react-dom';
2121
import angular, { ICompileService } from 'angular';
22-
import chrome from 'ui/chrome';
2322
import {
2423
DocViewRenderProps,
2524
AngularScope,
2625
AngularController,
2726
AngularDirective,
2827
} from './doc_views_types';
2928
import { DocViewerError } from '../components/doc_viewer/doc_viewer_render_error';
29+
import { Chrome } from '../kibana_services';
3030

3131
/**
3232
* Compiles and injects the give angular template into the given dom node
@@ -36,7 +36,8 @@ export async function injectAngularElement(
3636
domNode: Element,
3737
template: string,
3838
scopeProps: DocViewRenderProps,
39-
Controller: AngularController
39+
Controller: AngularController,
40+
chrome: Chrome
4041
): Promise<() => void> {
4142
const $injector = await chrome.dangerouslyGetActiveInjector();
4243
const rootScope: AngularScope = $injector.get('$rootScope');
@@ -68,15 +69,16 @@ export async function injectAngularElement(
6869
* Converts a given legacy angular directive to a render function
6970
* for usage in a react component. Note that the rendering is async
7071
*/
71-
export function convertDirectiveToRenderFn(directive: AngularDirective) {
72+
export function convertDirectiveToRenderFn(directive: AngularDirective, chrome: Chrome) {
7273
return (domNode: Element, props: DocViewRenderProps) => {
7374
let rejected = false;
7475

7576
const cleanupFnPromise = injectAngularElement(
7677
domNode,
7778
directive.template,
7879
props,
79-
directive.controller
80+
directive.controller,
81+
chrome
8082
);
8183
cleanupFnPromise.catch(e => {
8284
rejected = true;

src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_registry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@
1818
*/
1919
import { convertDirectiveToRenderFn } from './doc_views_helpers';
2020
import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_views_types';
21+
import { Chrome } from '../kibana_services';
2122

2223
export { DocViewRenderProps, DocView, DocViewRenderFn } from './doc_views_types';
2324

2425
export class DocViewsRegistry {
2526
private docViews: DocView[] = [];
27+
28+
constructor(private legacyChrome: Chrome) {}
29+
2630
/**
2731
* Extends and adds the given doc view to the registry array
2832
*/
2933
addDocView(docViewRaw: DocViewInput | DocViewInputFn) {
3034
const docView = typeof docViewRaw === 'function' ? docViewRaw() : docViewRaw;
3135
if (docView.directive) {
3236
// convert angular directive to render function for backwards compatibility
33-
docView.render = convertDirectiveToRenderFn(docView.directive);
37+
docView.render = convertDirectiveToRenderFn(docView.directive, this.legacyChrome);
3438
}
3539
if (typeof docView.shouldShow !== 'function') {
3640
docView.shouldShow = () => true;

src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function buildServices(
5959
core: CoreStart,
6060
plugins: DiscoverStartPlugins,
6161
docViewsRegistry: DocViewsRegistry
62-
) {
62+
): Promise<DiscoverServices> {
6363
const services = {
6464
savedObjectsClient: core.savedObjects.client,
6565
indexPatterns: plugins.data.indexPatterns,

src/legacy/core_plugins/kibana/public/discover/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
import chrome from 'ui/chrome';
1920
import { PluginInitializer, PluginInitializerContext } from 'kibana/public';
2021
import { npSetup, npStart } from 'ui/new_platform';
2122
import { SavedObjectRegistryProvider } from 'ui/saved_objects';
@@ -28,7 +29,12 @@ export const plugin: PluginInitializer<DiscoverSetup, DiscoverStart> = () => {
2829

2930
// Legacy compatiblity part - to be removed at cutover, replaced by a kibana.json file
3031
export const pluginInstance = plugin({} as PluginInitializerContext);
31-
export const setup = pluginInstance.setup(npSetup.core, npSetup.plugins);
32+
export const setup = pluginInstance.setup(npSetup.core, {
33+
...npSetup.plugins,
34+
__LEGACY: {
35+
chrome,
36+
},
37+
});
3238
export const start = pluginInstance.start(npStart.core, npStart.plugins);
3339

3440
SavedObjectRegistryProvider.register((savedSearches: any) => {

src/legacy/core_plugins/kibana/public/discover/kibana_services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@ export {
8989
} from '../../../../../plugins/data/public';
9090
export { ElasticSearchHit } from './doc_views/doc_views_types';
9191
export { Adapters } from 'ui/inspector/types';
92+
export { Chrome } from 'ui/chrome';

src/legacy/core_plugins/kibana/public/discover/plugin.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { registerFeature } from './helpers/register_feature';
2525
import './kibana_services';
2626
import { IEmbeddableStart, IEmbeddableSetup } from '../../../../../plugins/embeddable/public';
2727
import { getInnerAngularModule, getInnerAngularModuleEmbeddable } from './get_inner_angular';
28-
import { setAngularModule, setServices } from './kibana_services';
28+
import { Chrome, setAngularModule, setServices } from './kibana_services';
2929
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public';
3030
import { EuiUtilsStart } from '../../../../../plugins/eui_utils/public';
3131
import { buildServices } from './helpers/build_services';
@@ -49,6 +49,9 @@ export interface DiscoverSetupPlugins {
4949
uiActions: IUiActionsStart;
5050
embeddable: IEmbeddableSetup;
5151
kibana_legacy: KibanaLegacySetup;
52+
__LEGACY: {
53+
chrome: Chrome;
54+
};
5255
}
5356
export interface DiscoverStartPlugins {
5457
uiActions: IUiActionsStart;
@@ -70,16 +73,16 @@ const embeddableAngularName = 'app/discoverEmbeddable';
7073
export class DiscoverPlugin implements Plugin<DiscoverSetup, DiscoverStart> {
7174
private servicesInitialized: boolean = false;
7275
private innerAngularInitialized: boolean = false;
73-
private readonly docViewsRegistry: DocViewsRegistry;
76+
private docViewsRegistry: DocViewsRegistry | null = null;
7477
/**
7578
* why are those functions public? they are needed for some mocha tests
7679
* can be removed once all is Jest
7780
*/
7881
public initializeInnerAngular?: () => void;
7982
public initializeServices?: () => void;
8083

81-
constructor() {
82-
this.docViewsRegistry = new DocViewsRegistry();
84+
setup(core: CoreSetup, plugins: DiscoverSetupPlugins): DiscoverSetup {
85+
this.docViewsRegistry = new DocViewsRegistry(plugins.__LEGACY.chrome);
8386
this.docViewsRegistry.addDocView({
8487
title: i18n.translate('kbn.discover.docViews.table.tableTitle', {
8588
defaultMessage: 'Table',
@@ -94,9 +97,6 @@ export class DiscoverPlugin implements Plugin<DiscoverSetup, DiscoverStart> {
9497
order: 20,
9598
component: JsonCodeBlock,
9699
});
97-
}
98-
99-
setup(core: CoreSetup, plugins: DiscoverSetupPlugins): DiscoverSetup {
100100
plugins.kibana_legacy.registerLegacyApp({
101101
id: 'discover',
102102
title: 'Discover',
@@ -140,7 +140,7 @@ export class DiscoverPlugin implements Plugin<DiscoverSetup, DiscoverStart> {
140140
if (this.servicesInitialized) {
141141
return;
142142
}
143-
const services = await buildServices(core, plugins, this.docViewsRegistry);
143+
const services = await buildServices(core, plugins, this.docViewsRegistry!);
144144
setServices(services);
145145
this.servicesInitialized = true;
146146
};

0 commit comments

Comments
 (0)