From f497b6160d52fdf7d7edabb3977ab7752d9859cf Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Tue, 24 Sep 2019 21:17:33 +0300 Subject: [PATCH] Shim ui/autocomplete_providers into legacy data plugin (#46138) (#46479) * Shim ui/autocomplete_providers into legacy data plugin Fix: #44949 * Fix PR commnets * fix CI * Add comment --- .../components/query_bar_input.test.mocks.ts | 4 --- .../query_bar/components/query_bar_input.tsx | 15 +++++--- .../typeahead/suggestion_component.test.tsx | 2 +- .../typeahead/suggestion_component.tsx | 2 +- .../typeahead/suggestions_component.test.tsx | 2 +- .../typeahead/suggestions_component.tsx | 2 +- .../core_plugins/kibana/public/kibana.js | 1 - .../visualize_embeddable_factory.tsx | 1 - .../ui/ui_exports/ui_export_types/index.js | 1 - .../ui_export_types/ui_app_extensions.js | 1 - src/plugins/data/common/index.ts | 3 +- src/plugins/data/common/types.ts | 4 ++- .../public/autocomplete_provider/index.ts} | 24 +++++++++---- .../public/autocomplete_provider/types.ts} | 11 +++--- src/plugins/data/public/index.ts | 5 +-- src/plugins/data/public/mocks.ts | 15 ++++++-- src/plugins/data/public/plugin.ts | 30 +++++++++++++--- src/plugins/data/public/types.ts | 1 + x-pack/index.js | 4 +-- .../components/shared/KueryBar/index.tsx | 9 ++--- x-pack/legacy/plugins/apm/public/index.tsx | 1 - .../components/autocomplete_field/index.tsx | 3 +- .../autocomplete_field/suggestion_item.tsx | 4 +-- .../public/components/table/table.tsx | 2 +- .../containers/with_kuery_autocompletion.tsx | 2 +- .../adapters/elasticsearch/adapter_types.ts | 2 +- .../lib/adapters/elasticsearch/memory.ts | 2 +- .../public/lib/adapters/elasticsearch/rest.ts | 6 +++- .../public/lib/compose/memory.ts | 3 +- .../public/lib/elasticsearch.ts | 2 +- .../dashboard_mode/public/dashboard_viewer.js | 1 - .../plugins/infra/public/apps/kibana_app.ts | 2 -- .../autocomplete_field/autocomplete_field.tsx | 2 +- .../autocomplete_field/suggestion_item.tsx | 2 +- .../containers/with_kuery_autocompletion.tsx | 8 +++-- .../plugins/kuery_autocomplete/index.js | 18 ---------- .../plugins/kuery_autocomplete/index.ts | 22 ++++++++++++ .../public/autocomplete_providers/index.js | 13 ++++--- .../kuery_autocomplete/public/index.ts | 12 +++++++ .../kuery_autocomplete/public/legacy.ts | 20 +++++++++++ .../kuery_autocomplete/public/plugin.ts | 35 +++++++++++++++++++ x-pack/legacy/plugins/lens/public/index.ts | 2 -- x-pack/legacy/plugins/maps/public/index.js | 1 - x-pack/legacy/plugins/ml/public/app.js | 1 - .../public/components/kql_filter_bar/utils.js | 6 ++-- .../plugins/siem/public/apps/kibana_app.ts | 1 - .../autocomplete_field/index.test.tsx | 2 +- .../components/autocomplete_field/index.tsx | 2 +- .../autocomplete_field/suggestion_item.tsx | 2 +- .../containers/kuery_autocompletion/index.tsx | 7 ++-- .../plugins/uptime/public/apps/start_app.tsx | 1 - .../components/functional/kuery_bar/index.tsx | 6 +++- 52 files changed, 221 insertions(+), 109 deletions(-) rename src/{legacy/ui/public/autocomplete_providers/index.js => plugins/data/public/autocomplete_provider/index.ts} (56%) rename src/{legacy/ui/public/autocomplete_providers/index.d.ts => plugins/data/public/autocomplete_provider/types.ts} (85%) delete mode 100644 x-pack/legacy/plugins/kuery_autocomplete/index.js create mode 100644 x-pack/legacy/plugins/kuery_autocomplete/index.ts create mode 100644 x-pack/legacy/plugins/kuery_autocomplete/public/index.ts create mode 100644 x-pack/legacy/plugins/kuery_autocomplete/public/legacy.ts create mode 100644 x-pack/legacy/plugins/kuery_autocomplete/public/plugin.ts diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.test.mocks.ts b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.test.mocks.ts index 4245362064dd9..683ced28dba97 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.test.mocks.ts +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.test.mocks.ts @@ -41,10 +41,6 @@ export const mockPersistedLogFactory = jest.fn Promise.resolve([])); -const mockAutocompleteProvider = jest.fn(() => mockGetAutocompleteSuggestions); -export const mockGetAutocompleteProvider = jest.fn(() => mockAutocompleteProvider); - export const mockFetchIndexPatterns = jest .fn() .mockReturnValue(Promise.resolve([mockIndexPattern])); diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.tsx index f1a21d31be95d..7a972a6068f6f 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.tsx @@ -23,19 +23,19 @@ import React from 'react'; import { EuiFieldText, EuiOutsideClickDetector, PopoverAnchorPosition } from '@elastic/eui'; import { InjectedIntl, injectI18n } from '@kbn/i18n/react'; -import { - AutocompleteSuggestion, - AutocompleteSuggestionType, - getAutocompleteProvider, -} from 'ui/autocomplete_providers'; import { debounce, compact, isEqual, omit } from 'lodash'; import { PersistedLog } from 'ui/persisted_log'; import { Storage } from 'ui/storage'; +import { npStart } from 'ui/new_platform'; import { UiSettingsClientContract, SavedObjectsClientContract, HttpServiceBase, } from 'src/core/public'; +import { + AutocompleteSuggestion, + AutocompleteSuggestionType, +} from '../../../../../../../plugins/data/public'; import { IndexPattern, StaticIndexPattern } from '../../../index_patterns'; import { Query } from '../index'; import { fromUser, matchPairs, toUser } from '../lib'; @@ -44,6 +44,11 @@ import { SuggestionsComponent } from './typeahead/suggestions_component'; import { getQueryLog } from '../lib/get_query_log'; import { fetchIndexPatterns } from '../lib/fetch_index_patterns'; +// todo: related to https://github.com/elastic/kibana/pull/45762/files +// Will be refactored after merge of related PR +const getAutocompleteProvider = (language: string) => + npStart.plugins.data.autocomplete.getProvider(language); + interface Props { uiSettings: UiSettingsClientContract; indexPatterns: Array; diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestion_component.test.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestion_component.test.tsx index 00f39577bf3e7..dc7ebfc7b37ea 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestion_component.test.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestion_component.test.tsx @@ -19,7 +19,7 @@ import { mount, shallow } from 'enzyme'; import React from 'react'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../../plugins/data/public'; import { SuggestionComponent } from './suggestion_component'; const noop = () => { diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestion_component.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestion_component.tsx index 64c805968e43c..27e3eb1eebd1b 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestion_component.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestion_component.tsx @@ -20,7 +20,7 @@ import { EuiIcon } from '@elastic/eui'; import classNames from 'classnames'; import React, { FunctionComponent } from 'react'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../../plugins/data/public'; function getEuiIconType(type: string) { switch (type) { diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestions_component.test.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestions_component.test.tsx index 3a321dfd86a71..ea360fc8fd72e 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestions_component.test.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestions_component.test.tsx @@ -19,7 +19,7 @@ import { mount, shallow } from 'enzyme'; import React from 'react'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../../plugins/data/public'; import { SuggestionComponent } from './suggestion_component'; import { SuggestionsComponent } from './suggestions_component'; diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestions_component.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestions_component.tsx index f7cd249d3dbb7..32860e7cb390b 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestions_component.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/typeahead/suggestions_component.tsx @@ -19,7 +19,7 @@ import { isEmpty } from 'lodash'; import React, { Component } from 'react'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../../plugins/data/public'; import { SuggestionComponent } from './suggestion_component'; interface Props { diff --git a/src/legacy/core_plugins/kibana/public/kibana.js b/src/legacy/core_plugins/kibana/public/kibana.js index b11d0cac35b23..9a96bf26aede6 100644 --- a/src/legacy/core_plugins/kibana/public/kibana.js +++ b/src/legacy/core_plugins/kibana/public/kibana.js @@ -43,7 +43,6 @@ import 'uiExports/embeddableFactories'; import 'uiExports/embeddableActions'; import 'uiExports/inspectorViews'; import 'uiExports/search'; -import 'uiExports/autocompleteProviders'; import 'uiExports/shareContextMenuExtensions'; import 'ui/autoload/all'; diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx b/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx index 773ab9d8f2b79..d8ebef9a60413 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx @@ -18,7 +18,6 @@ */ import 'ui/registry/field_formats'; -import 'uiExports/autocompleteProviders'; import 'uiExports/contextMenuActions'; import 'uiExports/devTools'; import 'uiExports/docViews'; diff --git a/src/legacy/ui/ui_exports/ui_export_types/index.js b/src/legacy/ui/ui_exports/ui_export_types/index.js index fb7069064d7cf..68ea62edecbf5 100644 --- a/src/legacy/ui/ui_exports/ui_export_types/index.js +++ b/src/legacy/ui/ui_exports/ui_export_types/index.js @@ -63,7 +63,6 @@ export { aliases, visualize, search, - autocompleteProviders, shareContextMenuExtensions, } from './ui_app_extensions'; diff --git a/src/legacy/ui/ui_exports/ui_export_types/ui_app_extensions.js b/src/legacy/ui/ui_exports/ui_export_types/ui_app_extensions.js index 0f11b36a926ff..fe5695d5b3410 100644 --- a/src/legacy/ui/ui_exports/ui_export_types/ui_app_extensions.js +++ b/src/legacy/ui/ui_exports/ui_export_types/ui_app_extensions.js @@ -36,7 +36,6 @@ const appExtension = wrap( export const visTypes = appExtension; export const visEditorTypes = appExtension; -export const autocompleteProviders = appExtension; export const savedObjectTypes = appExtension; export const embeddableActions = appExtension; export const embeddableFactories = appExtension; diff --git a/src/plugins/data/common/index.ts b/src/plugins/data/common/index.ts index 983866722bbd8..1ec39670f87f7 100644 --- a/src/plugins/data/common/index.ts +++ b/src/plugins/data/common/index.ts @@ -17,6 +17,5 @@ * under the License. */ -export * from './timefilter/types'; -export * from './query/types'; +export * from './query'; export * from './field_formats'; diff --git a/src/plugins/data/common/types.ts b/src/plugins/data/common/types.ts index 47b437629d7cf..050b6ff7ae4a5 100644 --- a/src/plugins/data/common/types.ts +++ b/src/plugins/data/common/types.ts @@ -17,4 +17,6 @@ * under the License. */ -export * from '.'; +export * from './field_formats/types'; +export * from './timefilter/types'; +export * from './query/types'; diff --git a/src/legacy/ui/public/autocomplete_providers/index.js b/src/plugins/data/public/autocomplete_provider/index.ts similarity index 56% rename from src/legacy/ui/public/autocomplete_providers/index.js rename to src/plugins/data/public/autocomplete_provider/index.ts index ee297d65421db..6758bd7f379c1 100644 --- a/src/legacy/ui/public/autocomplete_providers/index.js +++ b/src/plugins/data/public/autocomplete_provider/index.ts @@ -16,13 +16,25 @@ * specific language governing permissions and limitations * under the License. */ +import { AutocompleteProvider } from './types'; -const autocompleteProviders = new Map(); +export class AutocompleteProviderRegister { + private readonly registeredProviders: Map = new Map(); -export function addAutocompleteProvider(language, provider) { - autocompleteProviders.set(language, provider); -} + /** @public **/ + public addProvider(language: string, provider: AutocompleteProvider): void { + if (language && provider) { + this.registeredProviders.set(language, provider); + } + } + + /** @public **/ + public getProvider(language: string): AutocompleteProvider | undefined { + return this.registeredProviders.get(language); + } -export function getAutocompleteProvider(language) { - return autocompleteProviders.get(language); + /** @internal **/ + public clearProviders(): void { + this.registeredProviders.clear(); + } } diff --git a/src/legacy/ui/public/autocomplete_providers/index.d.ts b/src/plugins/data/public/autocomplete_provider/types.ts similarity index 85% rename from src/legacy/ui/public/autocomplete_providers/index.d.ts rename to src/plugins/data/public/autocomplete_provider/types.ts index 92061051b1b0e..f168533679ecd 100644 --- a/src/legacy/ui/public/autocomplete_providers/index.d.ts +++ b/src/plugins/data/public/autocomplete_provider/types.ts @@ -17,11 +17,9 @@ * under the License. */ -/** - * WARNING: these typings are incomplete - */ import { StaticIndexPattern } from 'ui/index_patterns'; +/** @public **/ export type AutocompleteProvider = (args: { config: { get(configKey: string): any; @@ -30,12 +28,14 @@ export type AutocompleteProvider = (args: { boolFilter?: any; }) => GetSuggestions; +/** @public **/ export type GetSuggestions = (args: { query: string; selectionStart: number; selectionEnd: number; }) => Promise; +/** @public **/ export type AutocompleteSuggestionType = | 'field' | 'value' @@ -43,6 +43,7 @@ export type AutocompleteSuggestionType = | 'conjunction' | 'recentSearch'; +/** @public **/ export interface AutocompleteSuggestion { description?: string; end: number; @@ -50,7 +51,3 @@ export interface AutocompleteSuggestion { text: string; type: AutocompleteSuggestionType; } - -export function addAutocompleteProvider(language: string, provider: AutocompleteProvider): void; - -export function getAutocompleteProvider(language: string): AutocompleteProvider | undefined; diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index 7b71fb4ebc533..0580c41113ceb 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -20,8 +20,6 @@ import { PluginInitializerContext } from '../../../core/public'; import { DataPublicPlugin } from './plugin'; -export { RefreshInterval, TimeRange, Query } from './types'; - export function plugin(initializerContext: PluginInitializerContext) { return new DataPublicPlugin(initializerContext); } @@ -29,3 +27,6 @@ export function plugin(initializerContext: PluginInitializerContext) { export { DataPublicPlugin as Plugin }; export * from '../common'; + +export * from './autocomplete_provider'; +export * from './types'; diff --git a/src/plugins/data/public/mocks.ts b/src/plugins/data/public/mocks.ts index f33c065d60673..df5b68ac409a0 100644 --- a/src/plugins/data/public/mocks.ts +++ b/src/plugins/data/public/mocks.ts @@ -21,13 +21,24 @@ import { Plugin } from '.'; export type Setup = jest.Mocked>; export type Start = jest.Mocked>; +const autocompleteMock: any = { + addProvider: jest.fn(), + getProvider: jest.fn(), + clearProviders: jest.fn(), +}; + const createSetupContract = (): Setup => { - const setupContract: Setup = {}; + const setupContract: Setup = { + autocomplete: autocompleteMock as Setup['autocomplete'], + }; + return setupContract; }; const createStartContract = (): Start => { - const startContract: Start = undefined; + const startContract: Start = { + autocomplete: autocompleteMock as Start['autocomplete'], + }; return startContract; }; diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index bf5e37a972de7..d1670ccb645db 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -18,14 +18,34 @@ */ import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/public'; +import { AutocompleteProviderRegister } from './autocomplete_provider'; + +export interface DataPublicPluginSetup { + autocomplete: Pick; +} + +export interface DataPublicPluginStart { + autocomplete: Pick; +} + +export class DataPublicPlugin implements Plugin { + private readonly autocomplete = new AutocompleteProviderRegister(); -export class DataPublicPlugin implements Plugin<{}> { constructor(initializerContext: PluginInitializerContext) {} - public setup(core: CoreSetup) { - return {}; + public setup(core: CoreSetup): DataPublicPluginSetup { + return { + autocomplete: this.autocomplete, + }; + } + + public start(core: CoreStart): DataPublicPluginStart { + return { + autocomplete: this.autocomplete, + }; } - public start(core: CoreStart) {} - public stop() {} + public stop() { + this.autocomplete.clearProviders(); + } } diff --git a/src/plugins/data/public/types.ts b/src/plugins/data/public/types.ts index 5678945be99f3..370b8d3ff5ea2 100644 --- a/src/plugins/data/public/types.ts +++ b/src/plugins/data/public/types.ts @@ -18,3 +18,4 @@ */ export * from '../common/types'; +export * from './autocomplete_provider/types'; diff --git a/x-pack/index.js b/x-pack/index.js index c78a50273e324..1aaae50d5a613 100644 --- a/x-pack/index.js +++ b/x-pack/index.js @@ -26,7 +26,7 @@ import { indexManagement } from './legacy/plugins/index_management'; import { indexLifecycleManagement } from './legacy/plugins/index_lifecycle_management'; import { consoleExtensions } from './legacy/plugins/console_extensions'; import { spaces } from './legacy/plugins/spaces'; -import { kueryAutocomplete } from './legacy/plugins/kuery_autocomplete'; +import { kueryAutocompleteInitializer } from './legacy/plugins/kuery_autocomplete'; import { canvas } from './legacy/plugins/canvas'; import { infra } from './legacy/plugins/infra'; import { taskManager } from './legacy/plugins/task_manager'; @@ -72,7 +72,7 @@ module.exports = function (kibana) { indexManagement(kibana), consoleExtensions(kibana), indexLifecycleManagement(kibana), - kueryAutocomplete(kibana), + kueryAutocompleteInitializer(kibana), infra(kibana), taskManager(kibana), rollup(kibana), diff --git a/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/index.tsx b/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/index.tsx index bc5d293220158..ff09990ba269d 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/index.tsx @@ -10,10 +10,7 @@ import { EuiCallOut } from '@elastic/eui'; import styled from 'styled-components'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { - AutocompleteSuggestion, - getAutocompleteProvider -} from 'ui/autocomplete_providers'; +import { npStart } from 'ui/new_platform'; import { StaticIndexPattern, getFromSavedObject } from 'ui/index_patterns'; import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; import { fromQuery, toQuery } from '../Links/url_helpers'; @@ -29,11 +26,15 @@ import { useMatchedRoutes } from '../../../hooks/useMatchedRoutes'; import { RouteName } from '../../app/Main/route_config/route_names'; import { useKibanaCore } from '../../../../../observability/public'; import { getAPMIndexPattern } from '../../../services/rest/savedObjects'; +import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public'; const Container = styled.div` margin-bottom: 10px; `; +const getAutocompleteProvider = (language: string) => + npStart.plugins.data.autocomplete.getProvider(language); + interface State { indexPattern: StaticIndexPattern | null; suggestions: AutocompleteSuggestion[]; diff --git a/x-pack/legacy/plugins/apm/public/index.tsx b/x-pack/legacy/plugins/apm/public/index.tsx index bc1e6f9e714ac..16b8e9527245c 100644 --- a/x-pack/legacy/plugins/apm/public/index.tsx +++ b/x-pack/legacy/plugins/apm/public/index.tsx @@ -13,7 +13,6 @@ import 'ui/autoload/styles'; import chrome from 'ui/chrome'; // @ts-ignore import { uiModules } from 'ui/modules'; -import 'uiExports/autocompleteProviders'; import { GlobalHelpExtension } from './components/app/GlobalHelpExtension'; import { plugin } from './new-platform'; import { REACT_APP_ROOT_ID } from './new-platform/plugin'; diff --git a/x-pack/legacy/plugins/beats_management/public/components/autocomplete_field/index.tsx b/x-pack/legacy/plugins/beats_management/public/components/autocomplete_field/index.tsx index b8f2eb49ba7de..479be32ce1e12 100644 --- a/x-pack/legacy/plugins/beats_management/public/components/autocomplete_field/index.tsx +++ b/x-pack/legacy/plugins/beats_management/public/components/autocomplete_field/index.tsx @@ -13,8 +13,7 @@ import { import React from 'react'; import styled from 'styled-components'; -// @ts-ignore -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; import { composeStateUpdaters } from '../../utils/typed_react'; import { SuggestionItem } from './suggestion_item'; diff --git a/x-pack/legacy/plugins/beats_management/public/components/autocomplete_field/suggestion_item.tsx b/x-pack/legacy/plugins/beats_management/public/components/autocomplete_field/suggestion_item.tsx index 2b0537e11af92..64e7bf6b7f09e 100644 --- a/x-pack/legacy/plugins/beats_management/public/components/autocomplete_field/suggestion_item.tsx +++ b/x-pack/legacy/plugins/beats_management/public/components/autocomplete_field/suggestion_item.tsx @@ -8,8 +8,8 @@ import { EuiIcon } from '@elastic/eui'; import { tint } from 'polished'; import React from 'react'; import styled from 'styled-components'; -// @ts-ignore -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; + +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; interface SuggestionItemProps { isSelected?: boolean; diff --git a/x-pack/legacy/plugins/beats_management/public/components/table/table.tsx b/x-pack/legacy/plugins/beats_management/public/components/table/table.tsx index cd6e871f97d9e..8b101196d21ee 100644 --- a/x-pack/legacy/plugins/beats_management/public/components/table/table.tsx +++ b/x-pack/legacy/plugins/beats_management/public/components/table/table.tsx @@ -8,7 +8,7 @@ import { EuiBasicTable, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eu import { i18n } from '@kbn/i18n'; import React from 'react'; import styled from 'styled-components'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; import { TABLE_CONFIG } from '../../../common/constants'; import { AutocompleteField } from '../autocomplete_field/index'; import { ControlSchema } from './action_schema'; diff --git a/x-pack/legacy/plugins/beats_management/public/containers/with_kuery_autocompletion.tsx b/x-pack/legacy/plugins/beats_management/public/containers/with_kuery_autocompletion.tsx index 4fbf65653a404..2ac20438536c8 100644 --- a/x-pack/legacy/plugins/beats_management/public/containers/with_kuery_autocompletion.tsx +++ b/x-pack/legacy/plugins/beats_management/public/containers/with_kuery_autocompletion.tsx @@ -6,7 +6,7 @@ import React from 'react'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../src/plugins/data/public'; import { FrontendLibs } from '../lib/types'; import { RendererFunction } from '../utils/typed_react'; diff --git a/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/adapter_types.ts b/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/adapter_types.ts index 4940857493275..4f4ce70e817c6 100644 --- a/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/adapter_types.ts +++ b/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/adapter_types.ts @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public'; export interface ElasticsearchAdapter { convertKueryToEsQuery: (kuery: string) => Promise; diff --git a/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/memory.ts b/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/memory.ts index 1b918fb72c809..e001bf6c6e844 100644 --- a/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/memory.ts +++ b/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/memory.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public'; import { ElasticsearchAdapter } from './adapter_types'; export class MemoryElasticsearchAdapter implements ElasticsearchAdapter { diff --git a/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/rest.ts b/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/rest.ts index 8899ddd7976d5..d4a42ba662db4 100644 --- a/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/rest.ts +++ b/x-pack/legacy/plugins/beats_management/public/lib/adapters/elasticsearch/rest.ts @@ -6,9 +6,13 @@ import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; import { isEmpty } from 'lodash'; -import { AutocompleteSuggestion, getAutocompleteProvider } from 'ui/autocomplete_providers'; +import { npStart } from 'ui/new_platform'; import { RestAPIAdapter } from '../rest_api/adapter_types'; import { ElasticsearchAdapter } from './adapter_types'; +import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public'; + +const getAutocompleteProvider = (language: string) => + npStart.plugins.data.autocomplete.getProvider(language); export class RestElasticsearchAdapter implements ElasticsearchAdapter { private cachedIndexPattern: any = null; diff --git a/x-pack/legacy/plugins/beats_management/public/lib/compose/memory.ts b/x-pack/legacy/plugins/beats_management/public/lib/compose/memory.ts index f7d98fefe3847..f357e698afc3a 100644 --- a/x-pack/legacy/plugins/beats_management/public/lib/compose/memory.ts +++ b/x-pack/legacy/plugins/beats_management/public/lib/compose/memory.ts @@ -3,8 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; import 'ui/autoload/all'; // @ts-ignore: path dynamic for kibana import { management } from 'ui/management'; @@ -26,6 +24,7 @@ import { TagsLib } from '../tags'; import { FrontendLibs } from '../types'; import { MemoryElasticsearchAdapter } from './../adapters/elasticsearch/memory'; import { ElasticsearchLib } from './../elasticsearch'; +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; const onKibanaReady = uiModules.get('kibana').run; diff --git a/x-pack/legacy/plugins/beats_management/public/lib/elasticsearch.ts b/x-pack/legacy/plugins/beats_management/public/lib/elasticsearch.ts index dee7f579ed59b..0897dfd9c1392 100644 --- a/x-pack/legacy/plugins/beats_management/public/lib/elasticsearch.ts +++ b/x-pack/legacy/plugins/beats_management/public/lib/elasticsearch.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../src/plugins/data/public'; import { ElasticsearchAdapter } from './adapters/elasticsearch/adapter_types'; interface HiddenFields { diff --git a/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js b/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js index ca29b5ae5c604..d39d3fdaa84b8 100644 --- a/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js +++ b/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js @@ -27,7 +27,6 @@ import 'uiExports/navbarExtensions'; import 'uiExports/docViews'; import 'uiExports/fieldFormats'; import 'uiExports/search'; -import 'uiExports/autocompleteProviders'; import 'uiExports/shareContextMenuExtensions'; import _ from 'lodash'; import 'ui/autoload/all'; diff --git a/x-pack/legacy/plugins/infra/public/apps/kibana_app.ts b/x-pack/legacy/plugins/infra/public/apps/kibana_app.ts index ac705801175f3..5c5687c6c1283 100644 --- a/x-pack/legacy/plugins/infra/public/apps/kibana_app.ts +++ b/x-pack/legacy/plugins/infra/public/apps/kibana_app.ts @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import 'uiExports/autocompleteProviders'; - import { compose } from '../lib/compose/kibana_compose'; import { startApp } from './start_app'; startApp(compose()); diff --git a/x-pack/legacy/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx b/x-pack/legacy/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx index 940d187f2f3a0..54147c24ceec0 100644 --- a/x-pack/legacy/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx +++ b/x-pack/legacy/plugins/infra/public/components/autocomplete_field/autocomplete_field.tsx @@ -12,7 +12,7 @@ import { } from '@elastic/eui'; import React from 'react'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; import euiStyled from '../../../../../common/eui_styled_components'; import { composeStateUpdaters } from '../../utils/typed_react'; diff --git a/x-pack/legacy/plugins/infra/public/components/autocomplete_field/suggestion_item.tsx b/x-pack/legacy/plugins/infra/public/components/autocomplete_field/suggestion_item.tsx index 7c46eb84aec65..ca67aec9642ac 100644 --- a/x-pack/legacy/plugins/infra/public/components/autocomplete_field/suggestion_item.tsx +++ b/x-pack/legacy/plugins/infra/public/components/autocomplete_field/suggestion_item.tsx @@ -8,7 +8,7 @@ import { EuiIcon } from '@elastic/eui'; import { transparentize } from 'polished'; import React from 'react'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; import euiStyled from '../../../../../common/eui_styled_components'; interface SuggestionItemProps { diff --git a/x-pack/legacy/plugins/infra/public/containers/with_kuery_autocompletion.tsx b/x-pack/legacy/plugins/infra/public/containers/with_kuery_autocompletion.tsx index f766cb7bd3e38..8f2ed458cc118 100644 --- a/x-pack/legacy/plugins/infra/public/containers/with_kuery_autocompletion.tsx +++ b/x-pack/legacy/plugins/infra/public/containers/with_kuery_autocompletion.tsx @@ -5,11 +5,13 @@ */ import React from 'react'; - -import { AutocompleteSuggestion, getAutocompleteProvider } from 'ui/autocomplete_providers'; +import { npStart } from 'ui/new_platform'; import { StaticIndexPattern } from 'ui/index_patterns'; - import { RendererFunction } from '../utils/typed_react'; +import { AutocompleteSuggestion } from '../../../../../../src/plugins/data/public'; + +const getAutocompleteProvider = (language: string) => + npStart.plugins.data.autocomplete.getProvider(language); interface WithKueryAutocompletionLifecycleProps { children: RendererFunction<{ diff --git a/x-pack/legacy/plugins/kuery_autocomplete/index.js b/x-pack/legacy/plugins/kuery_autocomplete/index.js deleted file mode 100644 index d78d89e159021..0000000000000 --- a/x-pack/legacy/plugins/kuery_autocomplete/index.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { resolve } from 'path'; - - -export const kueryAutocomplete = (kibana) => new kibana.Plugin({ - id: 'kuery_autocomplete', - publicDir: resolve(__dirname, 'public'), - uiExports: { - autocompleteProviders: [ - 'plugins/kuery_autocomplete/autocomplete_providers' - ], - } -}); diff --git a/x-pack/legacy/plugins/kuery_autocomplete/index.ts b/x-pack/legacy/plugins/kuery_autocomplete/index.ts new file mode 100644 index 0000000000000..5f9d74ed799e6 --- /dev/null +++ b/x-pack/legacy/plugins/kuery_autocomplete/index.ts @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { resolve } from 'path'; +import { Legacy } from 'kibana'; + +import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types'; + +export const kueryAutocompleteInitializer: LegacyPluginInitializer = ({ + Plugin, +}: LegacyPluginApi) => + new Plugin({ + id: 'kuery_autocomplete', + publicDir: resolve(__dirname, 'public'), + uiExports: { + hacks: [resolve(__dirname, 'public/legacy')], + }, + init: (server: Legacy.Server) => ({}), + } as Legacy.PluginSpecOptions); diff --git a/x-pack/legacy/plugins/kuery_autocomplete/public/autocomplete_providers/index.js b/x-pack/legacy/plugins/kuery_autocomplete/public/autocomplete_providers/index.js index 7facc55b5eed0..8a82194470ace 100644 --- a/x-pack/legacy/plugins/kuery_autocomplete/public/autocomplete_providers/index.js +++ b/x-pack/legacy/plugins/kuery_autocomplete/public/autocomplete_providers/index.js @@ -10,11 +10,14 @@ import { getSuggestionsProvider as field } from './field'; import { getSuggestionsProvider as value } from './value'; import { getSuggestionsProvider as operator } from './operator'; import { getSuggestionsProvider as conjunction } from './conjunction'; -import { addAutocompleteProvider } from 'ui/autocomplete_providers'; const cursorSymbol = '@kuery-cursor@'; -addAutocompleteProvider('kuery', ({ config, indexPatterns, boolFilter }) => { +function dedup(suggestions) { + return uniq(suggestions, ({ type, text, start, end }) => [type, text, start, end].join('|')); +} + +export const kueryProvider = ({ config, indexPatterns, boolFilter }) => { const getSuggestionsByType = mapValues({ field, value, operator, conjunction }, provider => { return provider({ config, indexPatterns, boolFilter }); }); @@ -36,8 +39,4 @@ addAutocompleteProvider('kuery', ({ config, indexPatterns, boolFilter }) => { return Promise.all(suggestionsByType) .then(suggestionsByType => dedup(flatten(suggestionsByType))); }; -}); - -function dedup(suggestions) { - return uniq(suggestions, ({ type, text, start, end }) => [type, text, start, end].join('|')); -} +}; diff --git a/x-pack/legacy/plugins/kuery_autocomplete/public/index.ts b/x-pack/legacy/plugins/kuery_autocomplete/public/index.ts new file mode 100644 index 0000000000000..c2241f424511f --- /dev/null +++ b/x-pack/legacy/plugins/kuery_autocomplete/public/index.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { PluginInitializerContext } from 'src/core/public'; +import { KueryAutocompletePlugin as Plugin } from './plugin'; + +export function plugin(initializerContext: PluginInitializerContext) { + return new Plugin(initializerContext); +} diff --git a/x-pack/legacy/plugins/kuery_autocomplete/public/legacy.ts b/x-pack/legacy/plugins/kuery_autocomplete/public/legacy.ts new file mode 100644 index 0000000000000..52abe21c055ee --- /dev/null +++ b/x-pack/legacy/plugins/kuery_autocomplete/public/legacy.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { PluginInitializerContext } from 'src/core/public'; +import { npSetup, npStart } from 'ui/new_platform'; + +import { plugin } from './index'; +import { KueryAutocompletePluginSetupDependencies } from './plugin'; + +const plugins: Readonly = { + data: npSetup.plugins.data, +}; + +const pluginInstance = plugin({} as PluginInitializerContext); + +export const setup = pluginInstance.setup(npSetup.core, plugins); +export const start = pluginInstance.start(npStart.core); diff --git a/x-pack/legacy/plugins/kuery_autocomplete/public/plugin.ts b/x-pack/legacy/plugins/kuery_autocomplete/public/plugin.ts new file mode 100644 index 0000000000000..ded66a7c6e8f0 --- /dev/null +++ b/x-pack/legacy/plugins/kuery_autocomplete/public/plugin.ts @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from 'src/core/public'; +import { Plugin as DataPublicPlugin } from '../../../../../src/plugins/data/public'; + +// @ts-ignore +import { kueryProvider } from './autocomplete_providers'; + +/** @internal */ +export interface KueryAutocompletePluginSetupDependencies { + data: ReturnType; +} + +const KUERY_LANGUAGE_NAME = 'kuery'; + +/** @internal */ +export class KueryAutocompletePlugin implements Plugin, void> { + initializerContext: PluginInitializerContext; + + constructor(initializerContext: PluginInitializerContext) { + this.initializerContext = initializerContext; + } + + public async setup(core: CoreSetup, { data }: KueryAutocompletePluginSetupDependencies) { + data.autocomplete.addProvider(KUERY_LANGUAGE_NAME, kueryProvider); + } + + public start(core: CoreStart) { + // nothing to do here yet + } +} diff --git a/x-pack/legacy/plugins/lens/public/index.ts b/x-pack/legacy/plugins/lens/public/index.ts index 48a37fd5d8656..75f956662ec37 100644 --- a/x-pack/legacy/plugins/lens/public/index.ts +++ b/x-pack/legacy/plugins/lens/public/index.ts @@ -7,8 +7,6 @@ export * from './types'; import 'ui/autoload/all'; -// Used for kuery autocomplete -import 'uiExports/autocompleteProviders'; // Used to run esaggs queries import 'uiExports/fieldFormats'; import 'uiExports/search'; diff --git a/x-pack/legacy/plugins/maps/public/index.js b/x-pack/legacy/plugins/maps/public/index.js index 64f34a05272f5..b6d9c44e17c5a 100644 --- a/x-pack/legacy/plugins/maps/public/index.js +++ b/x-pack/legacy/plugins/maps/public/index.js @@ -10,7 +10,6 @@ import { wrapInI18nContext } from 'ui/i18n'; import { i18n } from '@kbn/i18n'; // import the uiExports that we want to "use" -import 'uiExports/autocompleteProviders'; import 'uiExports/fieldFormats'; import 'uiExports/inspectorViews'; import 'uiExports/search'; diff --git a/x-pack/legacy/plugins/ml/public/app.js b/x-pack/legacy/plugins/ml/public/app.js index 7cea0edaa7df7..6cff4b925c957 100644 --- a/x-pack/legacy/plugins/ml/public/app.js +++ b/x-pack/legacy/plugins/ml/public/app.js @@ -34,7 +34,6 @@ import 'plugins/ml/components/confirm_modal'; import 'plugins/ml/components/navigation_menu'; import 'plugins/ml/components/loading_indicator'; import 'plugins/ml/settings'; -import 'uiExports/autocompleteProviders'; import uiRoutes from 'ui/routes'; diff --git a/x-pack/legacy/plugins/ml/public/components/kql_filter_bar/utils.js b/x-pack/legacy/plugins/ml/public/components/kql_filter_bar/utils.js index 041be6a267d10..16e4a563c33ae 100644 --- a/x-pack/legacy/plugins/ml/public/components/kql_filter_bar/utils.js +++ b/x-pack/legacy/plugins/ml/public/components/kql_filter_bar/utils.js @@ -3,11 +3,11 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - - -import { getAutocompleteProvider } from 'ui/autocomplete_providers'; +import { npStart } from 'ui/new_platform'; import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; +const getAutocompleteProvider = language => npStart.plugins.data.autocomplete.getProvider(language); + export async function getSuggestions( query, selectionStart, diff --git a/x-pack/legacy/plugins/siem/public/apps/kibana_app.ts b/x-pack/legacy/plugins/siem/public/apps/kibana_app.ts index f6bbe30fedb6f..7ce67f3df9ff9 100644 --- a/x-pack/legacy/plugins/siem/public/apps/kibana_app.ts +++ b/x-pack/legacy/plugins/siem/public/apps/kibana_app.ts @@ -6,7 +6,6 @@ import chrome from 'ui/chrome'; import { SiemRootController } from './start_app'; -import 'uiExports/autocompleteProviders'; import 'uiExports/embeddableFactories'; // load the application diff --git a/x-pack/legacy/plugins/siem/public/components/autocomplete_field/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/autocomplete_field/index.test.tsx index 9f8bc2b656806..77a7296e368cf 100644 --- a/x-pack/legacy/plugins/siem/public/components/autocomplete_field/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/autocomplete_field/index.test.tsx @@ -11,7 +11,7 @@ import toJson from 'enzyme-to-json'; import { noop } from 'lodash/fp'; import * as React from 'react'; import { ThemeProvider } from 'styled-components'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; import { TestProviders } from '../../mock'; diff --git a/x-pack/legacy/plugins/siem/public/components/autocomplete_field/index.tsx b/x-pack/legacy/plugins/siem/public/components/autocomplete_field/index.tsx index 53353c4abb8bb..8770048b5b0e8 100644 --- a/x-pack/legacy/plugins/siem/public/components/autocomplete_field/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/autocomplete_field/index.tsx @@ -11,7 +11,7 @@ import { EuiPanel, } from '@elastic/eui'; import React from 'react'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; import euiStyled from '../../../../../common/eui_styled_components'; diff --git a/x-pack/legacy/plugins/siem/public/components/autocomplete_field/suggestion_item.tsx b/x-pack/legacy/plugins/siem/public/components/autocomplete_field/suggestion_item.tsx index 6bc217d6efb4b..997a19b0e8a2e 100644 --- a/x-pack/legacy/plugins/siem/public/components/autocomplete_field/suggestion_item.tsx +++ b/x-pack/legacy/plugins/siem/public/components/autocomplete_field/suggestion_item.tsx @@ -7,9 +7,9 @@ import { EuiIcon } from '@elastic/eui'; import { transparentize } from 'polished'; import React from 'react'; -import { AutocompleteSuggestion } from 'ui/autocomplete_providers'; import styled from 'styled-components'; import euiStyled from '../../../../../common/eui_styled_components'; +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; interface SuggestionItemProps { isSelected?: boolean; diff --git a/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx b/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx index 19d5a8e200da7..9235580563a53 100644 --- a/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx @@ -5,9 +5,9 @@ */ import React from 'react'; - -import { AutocompleteSuggestion, getAutocompleteProvider } from 'ui/autocomplete_providers'; +import { npStart } from 'ui/new_platform'; import { StaticIndexPattern } from 'ui/index_patterns'; +import { AutocompleteSuggestion } from '../../../../../../../src/plugins/data/public'; type RendererResult = React.ReactElement | null; type RendererFunction = (args: RenderArgs) => Result; @@ -33,6 +33,9 @@ interface KueryAutocompletionLifecycleState { suggestions: AutocompleteSuggestion[]; } +const getAutocompleteProvider = (language: string) => + npStart.plugins.data.autocomplete.getProvider(language); + export class KueryAutocompletion extends React.PureComponent< KueryAutocompletionLifecycleProps, KueryAutocompletionLifecycleState diff --git a/x-pack/legacy/plugins/uptime/public/apps/start_app.tsx b/x-pack/legacy/plugins/uptime/public/apps/start_app.tsx index 84172c6e39cde..4b07f936ae363 100644 --- a/x-pack/legacy/plugins/uptime/public/apps/start_app.tsx +++ b/x-pack/legacy/plugins/uptime/public/apps/start_app.tsx @@ -10,7 +10,6 @@ import 'ui/autoload/all'; import 'ui/autoload/styles'; import 'ui/courier'; import 'ui/persisted_log'; -import 'uiExports/autocompleteProviders'; import { createApolloClient } from '../lib/adapters/framework/apollo_client_adapter'; import { UMFrontendLibs } from '../lib/lib'; import { UptimeApp } from '../uptime_app'; diff --git a/x-pack/legacy/plugins/uptime/public/components/functional/kuery_bar/index.tsx b/x-pack/legacy/plugins/uptime/public/components/functional/kuery_bar/index.tsx index 07b77df3e0bec..b979cbf2456bd 100644 --- a/x-pack/legacy/plugins/uptime/public/components/functional/kuery_bar/index.tsx +++ b/x-pack/legacy/plugins/uptime/public/components/functional/kuery_bar/index.tsx @@ -6,10 +6,10 @@ import React, { useState, useEffect, useContext } from 'react'; import { uniqueId, startsWith } from 'lodash'; +import { npStart } from 'ui/new_platform'; import { EuiCallOut } from '@elastic/eui'; import styled from 'styled-components'; import { FormattedMessage } from '@kbn/i18n/react'; -import { AutocompleteSuggestion, getAutocompleteProvider } from 'ui/autocomplete_providers'; import { StaticIndexPattern } from 'ui/index_patterns'; import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; import { Typeahead } from './typeahead'; @@ -17,6 +17,7 @@ import { getIndexPattern } from '../../../lib/adapters/index_pattern'; import { UptimeSettingsContext } from '../../../contexts'; import { useUrlParams } from '../../../hooks'; import { toStaticIndexPattern } from '../../../lib/helper'; +import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public'; const Container = styled.div` margin-bottom: 10px; @@ -27,6 +28,9 @@ interface State { isLoadingIndexPattern: boolean; } +const getAutocompleteProvider = (language: string) => + npStart.plugins.data.autocomplete.getProvider(language); + function convertKueryToEsQuery(kuery: string, indexPattern: StaticIndexPattern) { const ast = fromKueryExpression(kuery); return toElasticsearchQuery(ast, indexPattern);