Skip to content

Commit

Permalink
[KibanaLegacy] Remove unused stuff and make things async if it is easy (
Browse files Browse the repository at this point in the history
#104638)

* remove unused stuff and make things async if it is easy

* fix problems

* load bootstrap in monitoring

* load angular bootstrap for saved searches and in  unit tests

* fix vis_type_table tests

* Update x-pack/plugins/monitoring/public/plugin.ts

Co-authored-by: Ester Martí Vilaseca <[email protected]>

* Update x-pack/plugins/monitoring/public/plugin.ts

Co-authored-by: Ester Martí Vilaseca <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Stratoula Kalafateli <[email protected]>
Co-authored-by: Ester Martí Vilaseca <[email protected]>
  • Loading branch information
4 people authored Jul 12, 2021
1 parent 216bb5e commit 832d349
Show file tree
Hide file tree
Showing 28 changed files with 54 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { setScopedHistory, setServices, setDocViewsRegistry } from '../../../../
import { coreMock } from '../../../../../../../core/public/mocks';
import { dataPluginMock } from '../../../../../../data/public/mocks';
import { navigationPluginMock } from '../../../../../../navigation/public/mocks';
import { initAngularBootstrap } from '../../../../../../kibana_legacy/public/angular_bootstrap';
import { getInnerAngularModule } from '../../get_inner_angular';
import { createBrowserHistory } from 'history';

Expand All @@ -41,6 +42,9 @@ describe('Doc Table', () => {
// Stub out a minimal mapping of 4 fields
let mapping;

beforeAll(async () => {
await initAngularBootstrap();
});
beforeAll(() => setScopedHistory(createBrowserHistory()));
beforeEach(() => {
angular.element.prototype.slice = jest.fn(function (index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import hits from '../../../__fixtures__/real_hits';
import { coreMock } from '../../../../../../core/public/mocks';
import { dataPluginMock } from '../../../../../data/public/mocks';
import { navigationPluginMock } from '../../../../../navigation/public/mocks';
import { initAngularBootstrap } from '../../../../../kibana_legacy/public/angular_bootstrap';
import { setScopedHistory, setServices } from '../../../kibana_services';
import { getInnerAngularModule } from '../get_inner_angular';

Expand Down Expand Up @@ -54,6 +55,9 @@ describe('docTable', () => {
const core = coreMock.createStart();
let $elem;

beforeAll(async () => {
await initAngularBootstrap();
});
beforeAll(() => setScopedHistory(createBrowserHistory()));
beforeEach(() => {
angular.element.prototype.slice = jest.fn(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ import { createDocViewerDirective } from './doc_viewer';
import { createDiscoverGridDirective } from './create_discover_grid_directive';
import { createRenderCompleteDirective } from './directives/render_complete';
import {
initAngularBootstrap,
configureAppAngularModule,
PrivateProvider,
PromiseServiceCreator,
registerListenEventListener,
watchMultiDecorator,
} from '../../../../kibana_legacy/public';
import { PromiseServiceCreator } from './helpers';
import { DiscoverStartPlugins } from '../../plugin';
import { getScopedHistory } from '../../kibana_services';
import { createDiscoverDirective } from './create_discover_directive';
Expand All @@ -54,7 +53,6 @@ export function getInnerAngularModule(
deps: DiscoverStartPlugins,
context: PluginInitializerContext
) {
initAngularBootstrap();
const module = initializeInnerAngularModule(name, core, deps.navigation, deps.data);
configureAppAngularModule(module, { core, env: context.env }, true, getScopedHistory);
return module;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

export { formatRow, formatTopLevelObject } from './row_formatter';
export { handleSourceColumnState } from './state_helpers';
export { PromiseServiceCreator } from './promises';
2 changes: 2 additions & 0 deletions src/plugins/discover/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export class DiscoverPlugin
}
// this is used by application mount and tests
const { getInnerAngularModule } = await import('./application/angular/get_inner_angular');
await plugins.kibanaLegacy.loadAngularBootstrap();
const module = getInnerAngularModule(
innerAngularName,
core,
Expand Down Expand Up @@ -473,6 +474,7 @@ export class DiscoverPlugin
throw Error('Discover plugin getEmbeddableInjector: initializeServices is undefined');
}
const { core, plugins } = await this.initializeServices();
await getServices().kibanaLegacy.loadAngularBootstrap();
getServices().kibanaLegacy.loadFontAwesome();
const { getInnerAngularModuleEmbeddable } = await import(
'./application/angular/get_inner_angular'
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/kibana_legacy/public/angular/angular_config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ILocationProvider,
IModule,
IRootScopeService,
IRequestConfig,
} from 'angular';
import $ from 'jquery';
import { set } from '@elastic/safer-lodash-set';
Expand All @@ -22,7 +23,6 @@ import { ChromeBreadcrumb, EnvironmentMode, PackageInfo } from 'kibana/public';
import { History } from 'history';

import { CoreStart } from 'kibana/public';
import { isSystemApiRequest } from '../utils';
import { formatAngularHttpError, isAngularHttpError } from '../notify/lib';

export interface RouteConfiguration {
Expand All @@ -38,6 +38,11 @@ export interface RouteConfiguration {
requireUICapability?: string;
}

function isSystemApiRequest(request: IRequestConfig) {
const { headers } = request;
return headers && !!headers['kbn-system-request'];
}

/**
* Detects whether a given angular route is a dummy route that doesn't
* require any action. There are two ways this can happen:
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/kibana_legacy/public/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* Side Public License, v 1.
*/

// @ts-ignore
export { PromiseServiceCreator } from './promises';
// @ts-ignore
export { watchMultiDecorator } from './watch_multi';
export * from './angular_config';
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana_legacy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const plugin = (initializerContext: PluginInitializerContext) =>

export * from './plugin';

export { initAngularBootstrap } from './angular_bootstrap';
export { PaginateDirectiveProvider, PaginateControlsDirectiveProvider } from './paginate/paginate';
export * from './angular';
export * from './notify';
Expand Down
1 change: 1 addition & 0 deletions src/plugins/kibana_legacy/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const createStartContract = (): Start => ({
getHideWriteControls: jest.fn(),
},
loadFontAwesome: jest.fn(),
loadAngularBootstrap: jest.fn(),
});

export const kibanaLegacyPluginMock = {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana_legacy/public/notify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
* Side Public License, v 1.
*/

export * from './toasts';
export * from './lib';
100 changes: 0 additions & 100 deletions src/plugins/kibana_legacy/public/notify/toasts/TOAST_NOTIFICATIONS.md

This file was deleted.

9 changes: 0 additions & 9 deletions src/plugins/kibana_legacy/public/notify/toasts/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 8 additions & 0 deletions src/plugins/kibana_legacy/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export class KibanaLegacyPlugin {
loadFontAwesome: async () => {
await import('./font_awesome');
},
/**
* Loads angular bootstrap modules. Should be removed once the last consumer has migrated to EUI
* @deprecated
*/
loadAngularBootstrap: async () => {
const { initAngularBootstrap } = await import('./angular_bootstrap');
initAngularBootstrap();
},
/**
* @deprecated
* Just exported for wiring up with dashboard mode, should not be used.
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana_legacy/public/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

export * from './system_api';
// @ts-ignore
export { KbnAccessibleClickProvider } from './kbn_accessible_click';
// @ts-ignore
Expand Down
Loading

0 comments on commit 832d349

Please sign in to comment.