-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Data Plugin] combine autocomplete provider and suggestions provider (#…
…54451) (#55224) * [Data Plugin] combine autocomplete provider and suggestions provider Closes: #52843 * [Data Plugin] combine autocomplete provider and suggestions provider - add skeleton for SuggestionsProvider * autocomplete_provider -> autocomplete * value_suggestions.ts - change getSuggestions method * remove suggestions_provider folder * fix PR comments * fix PR comments * fix CI * fix CI * getFieldSuggestions -> getValueSuggestions * update Jest snaphots Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
587f64f
commit 1a3d74f
Showing
59 changed files
with
571 additions
and
547 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
src/plugins/data/public/autocomplete/autocomplete_service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { CoreSetup } from 'src/core/public'; | ||
import { QuerySuggestionsGetFn } from './providers/query_suggestion_provider'; | ||
import { | ||
setupValueSuggestionProvider, | ||
ValueSuggestionsGetFn, | ||
} from './providers/value_suggestion_provider'; | ||
|
||
export class AutocompleteService { | ||
private readonly querySuggestionProviders: Map<string, QuerySuggestionsGetFn> = new Map(); | ||
private getValueSuggestions?: ValueSuggestionsGetFn; | ||
|
||
private addQuerySuggestionProvider = ( | ||
language: string, | ||
provider: QuerySuggestionsGetFn | ||
): void => { | ||
if (language && provider) { | ||
this.querySuggestionProviders.set(language, provider); | ||
} | ||
}; | ||
|
||
private getQuerySuggestions: QuerySuggestionsGetFn = args => { | ||
const { language } = args; | ||
const provider = this.querySuggestionProviders.get(language); | ||
|
||
if (provider) { | ||
return provider(args); | ||
} | ||
}; | ||
|
||
private hasQuerySuggestions = (language: string) => this.querySuggestionProviders.has(language); | ||
|
||
/** @public **/ | ||
public setup(core: CoreSetup) { | ||
this.getValueSuggestions = setupValueSuggestionProvider(core); | ||
|
||
return { | ||
addQuerySuggestionProvider: this.addQuerySuggestionProvider, | ||
|
||
/** @obsolete **/ | ||
/** please use "getProvider" only from the start contract **/ | ||
getQuerySuggestions: this.getQuerySuggestions, | ||
}; | ||
} | ||
|
||
/** @public **/ | ||
public start() { | ||
return { | ||
getQuerySuggestions: this.getQuerySuggestions, | ||
hasQuerySuggestions: this.hasQuerySuggestions, | ||
getValueSuggestions: this.getValueSuggestions!, | ||
}; | ||
} | ||
|
||
/** @internal **/ | ||
public clearProviders(): void { | ||
this.querySuggestionProviders.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.