From 2527603caa338547b05adf42caef190256e4dc7d Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 13 Jul 2020 15:22:21 +0200 Subject: [PATCH] [Discover] Migrate async import of embeddable factory to actual embeddable (#70920) --- .../discover/public/application/embeddable/index.ts | 1 - .../application/embeddable/search_embeddable.ts | 2 +- .../embeddable/search_embeddable_factory.ts | 7 ++++--- .../discover/public/application/embeddable/types.ts | 11 ++++++++++- src/plugins/discover/public/plugin.ts | 8 ++------ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/plugins/discover/public/application/embeddable/index.ts b/src/plugins/discover/public/application/embeddable/index.ts index b86a8daa119c5..1c4e06c7c3ade 100644 --- a/src/plugins/discover/public/application/embeddable/index.ts +++ b/src/plugins/discover/public/application/embeddable/index.ts @@ -20,4 +20,3 @@ export { SEARCH_EMBEDDABLE_TYPE } from './constants'; export * from './types'; export * from './search_embeddable_factory'; -export * from './search_embeddable'; diff --git a/src/plugins/discover/public/application/embeddable/search_embeddable.ts b/src/plugins/discover/public/application/embeddable/search_embeddable.ts index e03a6b938bc4f..9a3dd0d310ff7 100644 --- a/src/plugins/discover/public/application/embeddable/search_embeddable.ts +++ b/src/plugins/discover/public/application/embeddable/search_embeddable.ts @@ -38,7 +38,7 @@ import * as columnActions from '../angular/doc_table/actions/columns'; import searchTemplate from './search_template.html'; import { ISearchEmbeddable, SearchInput, SearchOutput } from './types'; import { SortOrder } from '../angular/doc_table/components/table_header/helpers'; -import { getSortForSearchSource } from '../angular/doc_table/lib/get_sort_for_search_source'; +import { getSortForSearchSource } from '../angular/doc_table'; import { getRequestInspectorStats, getResponseInspectorStats, diff --git a/src/plugins/discover/public/application/embeddable/search_embeddable_factory.ts b/src/plugins/discover/public/application/embeddable/search_embeddable_factory.ts index 1dc5947792d5c..f61fa361f0c0e 100644 --- a/src/plugins/discover/public/application/embeddable/search_embeddable_factory.ts +++ b/src/plugins/discover/public/application/embeddable/search_embeddable_factory.ts @@ -28,8 +28,8 @@ import { } from '../../../../embeddable/public'; import { TimeRange } from '../../../../data/public'; -import { SearchEmbeddable } from './search_embeddable'; -import { SearchInput, SearchOutput } from './types'; + +import { SearchInput, SearchOutput, SearchEmbeddable } from './types'; import { SEARCH_EMBEDDABLE_TYPE } from './constants'; interface StartServices { @@ -92,7 +92,8 @@ export class SearchEmbeddableFactory const savedObject = await getServices().getSavedSearchById(savedObjectId); const indexPattern = savedObject.searchSource.getField('index'); const { executeTriggerActions } = await this.getStartServices(); - return new SearchEmbeddable( + const { SearchEmbeddable: SearchEmbeddableClass } = await import('./search_embeddable'); + return new SearchEmbeddableClass( { savedSearch: savedObject, $rootScope, diff --git a/src/plugins/discover/public/application/embeddable/types.ts b/src/plugins/discover/public/application/embeddable/types.ts index 80576eb4ed7cb..d7fa9b3bc23d3 100644 --- a/src/plugins/discover/public/application/embeddable/types.ts +++ b/src/plugins/discover/public/application/embeddable/types.ts @@ -17,7 +17,12 @@ * under the License. */ -import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from 'src/plugins/embeddable/public'; +import { + Embeddable, + EmbeddableInput, + EmbeddableOutput, + IEmbeddable, +} from 'src/plugins/embeddable/public'; import { SortOrder } from '../angular/doc_table/components/table_header/helpers'; import { Filter, IIndexPattern, TimeRange, Query } from '../../../../data/public'; import { SavedSearch } from '../..'; @@ -40,3 +45,7 @@ export interface SearchOutput extends EmbeddableOutput { export interface ISearchEmbeddable extends IEmbeddable { getSavedSearch(): SavedSearch; } + +export interface SearchEmbeddable extends Embeddable { + type: string; +} diff --git a/src/plugins/discover/public/plugin.ts b/src/plugins/discover/public/plugin.ts index 0e5c5343b6f96..3423ba5657165 100644 --- a/src/plugins/discover/public/plugin.ts +++ b/src/plugins/discover/public/plugin.ts @@ -66,6 +66,7 @@ import { DISCOVER_APP_URL_GENERATOR, DiscoverUrlGenerator, } from './url_generator'; +import { SearchEmbeddableFactory } from './application/embeddable'; declare module '../../share/public' { export interface UrlGeneratorStateMapping { @@ -345,12 +346,7 @@ export class DiscoverPlugin /** * register embeddable with a slimmer embeddable version of inner angular */ - private async registerEmbeddable( - core: CoreSetup, - plugins: DiscoverSetupPlugins - ) { - const { SearchEmbeddableFactory } = await import('./application/embeddable'); - + private registerEmbeddable(core: CoreSetup, plugins: DiscoverSetupPlugins) { if (!this.getEmbeddableInjector) { throw Error('Discover plugin method getEmbeddableInjector is undefined'); }