diff --git a/x-pack/legacy/plugins/uptime/public/apps/plugin.ts b/x-pack/legacy/plugins/uptime/public/apps/plugin.ts index 97d996a21b3487..bc4e30b79cb157 100644 --- a/x-pack/legacy/plugins/uptime/public/apps/plugin.ts +++ b/x-pack/legacy/plugins/uptime/public/apps/plugin.ts @@ -29,8 +29,16 @@ export class Plugin { this.chrome = chrome; } - public start({ core }: StartObject): void { - const libs: UMFrontendLibs = { framework: getKibanaFrameworkAdapter(core) }; + public start(start: StartObject): void { + const { + core, + plugins: { + data: { autocomplete }, + }, + } = start; + const libs: UMFrontendLibs = { + framework: getKibanaFrameworkAdapter(core, autocomplete), + }; // @ts-ignore improper type description this.chrome.setRootTemplate(template); const checkForRoot = () => { 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 b979cbf2456bd2..f529c9cd9d53fc 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,18 +6,17 @@ 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 { StaticIndexPattern } from 'ui/index_patterns'; import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; +import { AutocompleteProviderRegister, AutocompleteSuggestion } from 'src/plugins/data/public'; +import { StaticIndexPattern } from 'src/legacy/core_plugins/data/public/index_patterns/index_patterns'; import { Typeahead } from './typeahead'; 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; @@ -28,10 +27,7 @@ interface State { isLoadingIndexPattern: boolean; } -const getAutocompleteProvider = (language: string) => - npStart.plugins.data.autocomplete.getProvider(language); - -function convertKueryToEsQuery(kuery: string, indexPattern: StaticIndexPattern) { +function convertKueryToEsQuery(kuery: string, indexPattern: unknown) { const ast = fromKueryExpression(kuery); return toElasticsearchQuery(ast, indexPattern); } @@ -39,9 +35,10 @@ function convertKueryToEsQuery(kuery: string, indexPattern: StaticIndexPattern) function getSuggestions( query: string, selectionStart: number, - apmIndexPattern: StaticIndexPattern + apmIndexPattern: StaticIndexPattern, + autocomplete: Pick ) { - const autocompleteProvider = getAutocompleteProvider('kuery'); + const autocompleteProvider = autocomplete.getProvider('kuery'); if (!autocompleteProvider) { return []; } @@ -62,7 +59,11 @@ function getSuggestions( return suggestions; } -export function KueryBar() { +interface Props { + autocomplete: Pick; +} + +export function KueryBar({ autocomplete }: Props) { const [state, setState] = useState({ suggestions: [], isLoadingIndexPattern: true, @@ -94,7 +95,12 @@ export function KueryBar() { currentRequestCheck = currentRequest; try { - let suggestions = await getSuggestions(inputValue, selectionStart, indexPattern); + let suggestions = await getSuggestions( + inputValue, + selectionStart, + indexPattern, + autocomplete + ); suggestions = suggestions .filter((suggestion: AutocompleteSuggestion) => !startsWith(suggestion.text, 'span.')) .slice(0, 15); diff --git a/x-pack/legacy/plugins/uptime/public/lib/adapters/framework/new_platform_adapter.tsx b/x-pack/legacy/plugins/uptime/public/lib/adapters/framework/new_platform_adapter.tsx index 8beebc0caee937..e35d8e93ca4a72 100644 --- a/x-pack/legacy/plugins/uptime/public/lib/adapters/framework/new_platform_adapter.tsx +++ b/x-pack/legacy/plugins/uptime/public/lib/adapters/framework/new_platform_adapter.tsx @@ -8,6 +8,7 @@ import { ChromeBreadcrumb, CoreStart } from 'src/core/public'; import React from 'react'; import ReactDOM from 'react-dom'; import { get } from 'lodash'; +import { AutocompleteProviderRegister } from 'src/plugins/data/public'; import { CreateGraphQLClient } from './framework_adapter_types'; import { UptimeApp, UptimeAppProps } from '../../../uptime_app'; import { getIntegratedAppAvailability } from './capabilities_adapter'; @@ -17,7 +18,10 @@ import { renderUptimeKibanaGlobalHelp } from './kibana_global_help'; import { UMFrameworkAdapter, BootstrapUptimeApp } from '../../lib'; import { createApolloClient } from './apollo_client_adapter'; -export const getKibanaFrameworkAdapter = (core: CoreStart): UMFrameworkAdapter => { +export const getKibanaFrameworkAdapter = ( + core: CoreStart, + autocomplete: Pick +): UMFrameworkAdapter => { const { application: { capabilities }, chrome: { setBadge, setHelpExtension }, @@ -39,6 +43,7 @@ export const getKibanaFrameworkAdapter = (core: CoreStart): UMFrameworkAdapter = canSave, client: createApolloClient(`${basePath.get()}/api/uptime/graphql`, 'true'), darkMode: core.uiSettings.get('theme:darkMode'), + autocomplete, i18n, isApmAvailable: apm, isInfraAvailable: infrastructure, diff --git a/x-pack/legacy/plugins/uptime/public/pages/overview.tsx b/x-pack/legacy/plugins/uptime/public/pages/overview.tsx index 86bd98195ca886..921cb425c75f36 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/overview.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/overview.tsx @@ -9,6 +9,7 @@ import { i18n } from '@kbn/i18n'; import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; import React, { Fragment, useContext, useEffect, useState } from 'react'; import styled from 'styled-components'; +import { AutocompleteProviderRegister } from 'src/plugins/data/public'; import { getOverviewPageBreadcrumbs } from '../breadcrumbs'; import { EmptyState, @@ -29,12 +30,13 @@ import { combineFiltersAndUserSearch, stringifyKueries, toStaticIndexPattern } f interface OverviewPageProps { basePath: string; - logOverviewPageLoad: () => void; + autocomplete: Pick; history: any; location: { pathname: string; search: string; }; + logOverviewPageLoad: () => void; setBreadcrumbs: UMUpdateBreadcrumbs; } @@ -54,7 +56,12 @@ const EuiFlexItemStyled = styled(EuiFlexItem)` } `; -export const OverviewPage = ({ basePath, logOverviewPageLoad, setBreadcrumbs }: Props) => { +export const OverviewPage = ({ + basePath, + autocomplete, + logOverviewPageLoad, + setBreadcrumbs, +}: Props) => { const { colors, setHeadingText } = useContext(UptimeSettingsContext); const [getUrlParams, updateUrl] = useUrlParams(); const { absoluteDateRangeStart, absoluteDateRangeEnd, ...params } = getUrlParams(); @@ -129,7 +136,7 @@ export const OverviewPage = ({ basePath, logOverviewPageLoad, setBreadcrumbs }: - + ; i18n: I18nStart; isApmAvailable: boolean; isInfraAvailable: boolean; @@ -54,6 +56,7 @@ const Application = (props: UptimeAppProps) => { canSave, client, darkMode, + autocomplete, i18n: i18nCore, isApmAvailable, isInfraAvailable, @@ -175,6 +178,7 @@ const Application = (props: UptimeAppProps) => { render={routerProps => (