From 51ed3c06d37dc50e6432c47f3c4f86e468257ab7 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Tue, 18 Feb 2020 16:03:31 +0100 Subject: [PATCH] [ML] Transform: Fix transform wizard query autocomplete. (#57833) Fixes a regression introduced by #56358. We're reusing the KqlFilterBar from the ML plugin in the transform plugin and missed updating the dependency management. Note this PR is only about fixing that regression. Future work on NP migration should take care of cleaning up the dependency management in the transforms plugin in general. --- .../transform/public/app/app_dependencies.tsx | 24 ++++++++++++++++++- .../legacy/plugins/transform/public/plugin.ts | 7 +++--- .../transform/public/shared_imports.ts | 3 +++ .../legacy/plugins/transform/public/shim.ts | 1 + 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/transform/public/app/app_dependencies.tsx b/x-pack/legacy/plugins/transform/public/app/app_dependencies.tsx index 28a54e67bf838..282d1380b396b 100644 --- a/x-pack/legacy/plugins/transform/public/app/app_dependencies.tsx +++ b/x-pack/legacy/plugins/transform/public/app/app_dependencies.tsx @@ -7,13 +7,35 @@ import React, { createContext, useContext, ReactNode } from 'react'; import { HashRouter } from 'react-router-dom'; +import chrome from 'ui/chrome'; +import { metadata } from 'ui/metadata'; + import { API_BASE_PATH } from '../../common/constants'; -import { AuthorizationProvider } from './lib/authorization'; + +import { setDependencyCache } from '../shared_imports'; import { AppDependencies } from '../shim'; +import { AuthorizationProvider } from './lib/authorization'; + +const legacyBasePath = { + prepend: chrome.addBasePath, + get: chrome.getBasePath, + remove: () => {}, +}; +const legacyDocLinks = { + ELASTIC_WEBSITE_URL: 'https://www.elastic.co/', + DOC_LINK_VERSION: metadata.branch, +}; + let DependenciesContext: React.Context; const setAppDependencies = (deps: AppDependencies) => { + setDependencyCache({ + autocomplete: deps.plugins.data.autocomplete, + docLinks: legacyDocLinks as any, + basePath: legacyBasePath as any, + XSRF: chrome.getXsrfToken(), + }); DependenciesContext = createContext(deps); return DependenciesContext.Provider; }; diff --git a/x-pack/legacy/plugins/transform/public/plugin.ts b/x-pack/legacy/plugins/transform/public/plugin.ts index 3b02d07b8c150..2e29ecfc19510 100644 --- a/x-pack/legacy/plugins/transform/public/plugin.ts +++ b/x-pack/legacy/plugins/transform/public/plugin.ts @@ -35,12 +35,13 @@ export class Plugin { savedObjects, overlays, } = core; - const { management, savedSearches: coreSavedSearches, uiMetric } = plugins; + const { data, management, savedSearches: coreSavedSearches, uiMetric } = plugins; // AppCore/AppPlugins to be passed on as React context - const AppDependencies = { + const appDependencies = { core: { chrome, http, i18n: core.i18n, uiSettings, savedObjects, overlays }, plugins: { + data, management: { sections: management.sections }, savedSearches: coreSavedSearches, }, @@ -113,7 +114,7 @@ export class Plugin { unmountReactApp(); const elem = document.getElementById(REACT_ROOT_ID); if (elem) { - renderReact(elem, AppDependencies); + renderReact(elem, appDependencies); } }); }, diff --git a/x-pack/legacy/plugins/transform/public/shared_imports.ts b/x-pack/legacy/plugins/transform/public/shared_imports.ts index fe9fe8b8e695b..74e0c9a3878db 100644 --- a/x-pack/legacy/plugins/transform/public/shared_imports.ts +++ b/x-pack/legacy/plugins/transform/public/shared_imports.ts @@ -32,5 +32,8 @@ export { SORT_DIRECTION, } from '../../ml/public/application/components/ml_in_memory_table'; +// Needs to be imported because we're reusing KqlFilterBar which depends on it. +export { setDependencyCache } from '../../ml/public/application/util/dependency_cache'; + // @ts-ignore: could not find declaration file for module export { KqlFilterBar } from '../../ml/public/application/components/kql_filter_bar'; diff --git a/x-pack/legacy/plugins/transform/public/shim.ts b/x-pack/legacy/plugins/transform/public/shim.ts index 758cc90210579..38bb072ff9eb7 100644 --- a/x-pack/legacy/plugins/transform/public/shim.ts +++ b/x-pack/legacy/plugins/transform/public/shim.ts @@ -26,6 +26,7 @@ export type AppCore = Pick< >; export interface AppPlugins { + data: DataPublicPluginStart; management: { sections: typeof management; };