Skip to content

Commit

Permalink
[ML] Transform: Fix transform wizard query autocomplete. (elastic#57833)
Browse files Browse the repository at this point in the history
Fixes a regression introduced by elastic#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.
  • Loading branch information
walterra committed Feb 18, 2020
1 parent c99308c commit 51ed3c0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
24 changes: 23 additions & 1 deletion x-pack/legacy/plugins/transform/public/app/app_dependencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppDependencies>;

const setAppDependencies = (deps: AppDependencies) => {
setDependencyCache({
autocomplete: deps.plugins.data.autocomplete,
docLinks: legacyDocLinks as any,
basePath: legacyBasePath as any,
XSRF: chrome.getXsrfToken(),
});
DependenciesContext = createContext<AppDependencies>(deps);
return DependenciesContext.Provider;
};
Expand Down
7 changes: 4 additions & 3 deletions x-pack/legacy/plugins/transform/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -113,7 +114,7 @@ export class Plugin {
unmountReactApp();
const elem = document.getElementById(REACT_ROOT_ID);
if (elem) {
renderReact(elem, AppDependencies);
renderReact(elem, appDependencies);
}
});
},
Expand Down
3 changes: 3 additions & 0 deletions x-pack/legacy/plugins/transform/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/transform/public/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type AppCore = Pick<
>;

export interface AppPlugins {
data: DataPublicPluginStart;
management: {
sections: typeof management;
};
Expand Down

0 comments on commit 51ed3c0

Please sign in to comment.