Skip to content

Commit

Permalink
expose search fn on StartContract... tested locally only
Browse files Browse the repository at this point in the history
  • Loading branch information
stacey-gammon committed Oct 9, 2019
1 parent 8621708 commit 1678aec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class DataPublicPlugin implements Plugin<DataPublicPluginSetup, DataPubli
return {
autocomplete: this.autocomplete,
getSuggestions: getSuggestionsProvider(core.uiSettings, core.http),
search: this.searchService.start(core),
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ export { IEsSearchResponse, IEsSearchRequest, ES_SEARCH_STRATEGY } from '../../c
export { SYNC_SEARCH_STRATEGY } from './sync_search_strategy';

export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search';

export { ISearchStart } from './search_service';
20 changes: 17 additions & 3 deletions src/plugins/data/public/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from './i_search_strategy';
import { TStrategyTypes } from './strategy_types';
import { esSearchService } from './es_search';
import { ISearchGeneric } from './i_search';

/**
* Extends the AppMountContext so other plugins have access
Expand All @@ -47,6 +48,10 @@ declare module 'kibana/public' {
}
}

export interface ISearchStart {
search: ISearchGeneric;
}

/**
* The search plugin exposes two registration methods for other plugins:
* - registerSearchStrategyProvider for plugins to add their own custom
Expand All @@ -56,7 +61,7 @@ declare module 'kibana/public' {
*
* It also comes with two search strategy implementations - SYNC_SEARCH_STRATEGY and ES_SEARCH_STRATEGY.
*/
export class SearchService implements Plugin<ISearchSetup, void> {
export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
/**
* A mapping of search strategies keyed by a unique identifier. Plugins can use this unique identifier
* to override certain strategy implementations.
Expand All @@ -68,11 +73,14 @@ export class SearchService implements Plugin<ISearchSetup, void> {
*/
private contextContainer?: IContextContainer<TSearchStrategyProvider<any>>;

private search?: ISearchGeneric;

constructor(private initializerContext: PluginInitializerContext) {}

public setup(core: CoreSetup): ISearchSetup {
const search = (this.search = createAppMountSearchContext(this.searchStrategies).search);
core.application.registerMountContext<'search'>('search', () => {
return createAppMountSearchContext(this.searchStrategies);
return { search };
});

this.contextContainer = core.context.createContextContainer();
Expand Down Expand Up @@ -107,6 +115,12 @@ export class SearchService implements Plugin<ISearchSetup, void> {
return api;
}

public start(core: CoreStart) {}
public start(core: CoreStart) {
if (!this.search) {
throw new Error('Search should always be defined');
}
return { search: this.search };
}

public stop() {}
}
3 changes: 2 additions & 1 deletion src/plugins/data/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
export * from './autocomplete_provider/types';

import { AutocompletePublicPluginSetup, AutocompletePublicPluginStart } from '.';
import { ISearchSetup } from './search';
import { ISearchSetup, ISearchStart } from './search';
import { IGetSuggestions } from './suggestions_provider/types';
export interface DataPublicPluginSetup {
autocomplete: AutocompletePublicPluginSetup;
Expand All @@ -30,6 +30,7 @@ export interface DataPublicPluginSetup {
export interface DataPublicPluginStart {
autocomplete: AutocompletePublicPluginStart;
getSuggestions: IGetSuggestions;
search: ISearchStart;
}

export { IGetSuggestions } from './suggestions_provider/types';

0 comments on commit 1678aec

Please sign in to comment.