diff --git a/packages/kbn-interpreter/src/common/index.d.ts b/packages/kbn-interpreter/src/common/index.d.ts index 7201ccbb35635..bf03795d0a15c 100644 --- a/packages/kbn-interpreter/src/common/index.d.ts +++ b/packages/kbn-interpreter/src/common/index.d.ts @@ -19,4 +19,4 @@ export { Registry } from './lib/registry'; -export { fromExpression, toExpression, Ast } from './lib/ast'; +export { fromExpression, toExpression, Ast, ExpressionFunctionAST } from './lib/ast'; diff --git a/src/legacy/core_plugins/data/public/expressions/expression_renderer.tsx b/src/legacy/core_plugins/data/public/expressions/expression_renderer.tsx index e5358acc1c05c..11921ca9cf269 100644 --- a/src/legacy/core_plugins/data/public/expressions/expression_renderer.tsx +++ b/src/legacy/core_plugins/data/public/expressions/expression_renderer.tsx @@ -26,7 +26,7 @@ import { IExpressionLoader, ExpressionLoader } from './lib/loader'; // Accept all options of the runner as props except for the // dom element which is provided by the component itself export interface ExpressionRendererProps extends IExpressionLoaderParams { - className: 'string'; + className: string; expression: string | ExpressionAST; /** * If an element is specified, but the response of the expression run can't be rendered diff --git a/src/legacy/core_plugins/data/public/expressions/expression_runner.ts b/src/legacy/core_plugins/data/public/expressions/expression_runner.ts deleted file mode 100644 index ac087e2f530f0..0000000000000 --- a/src/legacy/core_plugins/data/public/expressions/expression_runner.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 { Ast, fromExpression } from '@kbn/interpreter/common'; - -import { RequestAdapter, DataAdapter } from 'ui/inspector/adapters'; -import { RenderFunctionsRegistry, Interpreter, Result } from './expressions_service'; - -export interface ExpressionRunnerOptions { - // TODO use the real types here once they are ready - context?: object; - getInitialContext?: () => object; - element?: Element; - /** - * If an element is specified, but the response of the expression run can't be rendered - * because it isn't a valid response or the specified renderer isn't available, - * this callback is called with the given result. - */ - onRenderFailure?: (result: Result) => void; -} - -export type ExpressionRunner = ( - expression: string | Ast, - options: ExpressionRunnerOptions -) => Promise; - -export const createRunFn = ( - renderersRegistry: RenderFunctionsRegistry, - interpreterPromise: Promise -): ExpressionRunner => async ( - expressionOrAst, - { element, context, getInitialContext, onRenderFailure } -) => { - // TODO: make interpreter initialization synchronous to avoid this - const interpreter = await interpreterPromise; - const ast = - typeof expressionOrAst === 'string' ? fromExpression(expressionOrAst) : expressionOrAst; - - const response = await interpreter.interpretAst(ast, context || { type: 'null' }, { - getInitialContext: getInitialContext || (() => ({})), - inspectorAdapters: { - // TODO connect real adapters - requests: new RequestAdapter(), - data: new DataAdapter(), - }, - }); - - if (response.type === 'error') { - throw response; - } - - if (element) { - if (response.type === 'render' && response.as && renderersRegistry.get(response.as) !== null) { - renderersRegistry.get(response.as).render(element, response.value, { - onDestroy: fn => { - // TODO implement - }, - done: () => { - // TODO implement - }, - }); - } else { - throw response; - } - } - - return response; -}; diff --git a/src/legacy/core_plugins/data/public/expressions/expressions_service.ts b/src/legacy/core_plugins/data/public/expressions/expressions_service.ts index a00512f04c1ac..2aff9cab67e82 100644 --- a/src/legacy/core_plugins/data/public/expressions/expressions_service.ts +++ b/src/legacy/core_plugins/data/public/expressions/expressions_service.ts @@ -24,6 +24,7 @@ import { setInspector, setInterpreter } from './services'; import { execute } from './lib/execute'; import { loader } from './lib/loader'; import { render } from './lib/render'; +import { IInterpreter } from './lib/_types'; import { createRenderer } from './expression_renderer'; import { Start as IInspector } from '../../../../../plugins/inspector/public'; @@ -40,7 +41,9 @@ export class ExpressionsService { // eslint-disable-next-line const { getInterpreter } = require('../../../interpreter/public/interpreter'); getInterpreter() - .then(setInterpreter) + .then(({ interpreter }: { interpreter: IInterpreter }) => { + setInterpreter(interpreter); + }) .catch((e: Error) => { throw new Error('interpreter is not initialized'); }); diff --git a/src/legacy/core_plugins/data/public/expressions/lib/_types.ts b/src/legacy/core_plugins/data/public/expressions/lib/_types.ts index b3185fda2c178..e458260432eaa 100644 --- a/src/legacy/core_plugins/data/public/expressions/lib/_types.ts +++ b/src/legacy/core_plugins/data/public/expressions/lib/_types.ts @@ -68,13 +68,13 @@ export interface IInterpreterRenderHandlers { event: (event: event) => void; } -export interface IInterpreterRenderFunction { +export interface IInterpreterRenderFunction { name: string; displayName: string; help: string; validate: () => void; reuseDomNode: boolean; - render: (domNode: Element, data: unknown, handlers: IInterpreterRenderHandlers) => void; + render: (domNode: Element, data: T, handlers: IInterpreterRenderHandlers) => void | Promise; } export interface IInterpreter { diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index b62c8106bc168..ddbc663525f3b 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -79,6 +79,8 @@ export class DataPlugin implements Plugin ({ QueryBar: jest.fn(() => null), @@ -22,6 +23,7 @@ jest.mock('ui/new_platform'); jest.mock('ui/notify'); jest.mock('ui/chrome'); jest.mock('../persistence'); +jest.mock('src/core/public'); const waitForPromises = () => new Promise(resolve => setTimeout(resolve)); @@ -39,6 +41,7 @@ function makeDefaultArgs(): jest.Mocked<{ docId?: string; docStorage: SavedObjectStore; redirectTo: (id?: string) => void; + savedObjectsClient: SavedObjectsClientContract; }> { return ({ editorFrame: createMockFrame(), @@ -68,6 +71,7 @@ function makeDefaultArgs(): jest.Mocked<{ }, QueryBar: jest.fn(() =>
), redirectTo: jest.fn(id => {}), + savedObjectsClient: jest.fn(), } as unknown) as jest.Mocked<{ editorFrame: EditorFrameInstance; chrome: Chrome; @@ -75,6 +79,7 @@ function makeDefaultArgs(): jest.Mocked<{ docId?: string; docStorage: SavedObjectStore; redirectTo: (id?: string) => void; + savedObjectsClient: SavedObjectsClientContract; }>; } diff --git a/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx b/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx index 243ee3df97980..82353f6550151 100644 --- a/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx +++ b/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx @@ -12,6 +12,7 @@ import { EuiLink, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { Storage } from 'ui/storage'; import { toastNotifications } from 'ui/notify'; import { Chrome } from 'ui/chrome'; +import { SavedObjectsClientContract } from 'src/core/public'; import { Query, QueryBar } from '../../../../../../src/legacy/core_plugins/data/public/query'; import { Document, SavedObjectStore } from '../persistence'; import { EditorFrameInstance } from '../types'; @@ -55,6 +56,7 @@ export function App({ docId, docStorage, redirectTo, + savedObjectsClient, }: { editorFrame: EditorFrameInstance; chrome: Chrome; @@ -62,6 +64,7 @@ export function App({ docId?: string; docStorage: SavedObjectStore; redirectTo: (id?: string) => void; + savedObjectsClient: SavedObjectsClientContract; }) { const uiSettings = chrome.getUiSettingsClient(); const timeDefaults = uiSettings.get('timepicker:timeDefaults'); @@ -228,6 +231,7 @@ export function App({ state.localQueryBarState.dateRange && state.localQueryBarState.dateRange.to } uiSettings={uiSettings} + savedObjectsClient={savedObjectsClient} />
diff --git a/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx index 07bd55cbd4e93..f3580a59ae89d 100644 --- a/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx @@ -9,7 +9,7 @@ import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; import { HashRouter, Switch, Route, RouteComponentProps } from 'react-router-dom'; import chrome from 'ui/chrome'; import { Storage } from 'ui/storage'; -import { editorFrameSetup, editorFrameStop } from '../editor_frame_plugin'; +import { editorFrameSetup, editorFrameStart, editorFrameStop } from '../editor_frame_plugin'; import { indexPatternDatasourceSetup, indexPatternDatasourceStop } from '../indexpattern_plugin'; import { SavedObjectIndexStore } from '../persistence'; import { xyVisualizationSetup, xyVisualizationStop } from '../xy_visualization_plugin'; @@ -23,6 +23,7 @@ import { EditorFrameInstance } from '../types'; export class AppPlugin { private instance: EditorFrameInstance | null = null; + private store: SavedObjectIndexStore | null = null; constructor() {} @@ -33,15 +34,25 @@ export class AppPlugin { const datatableVisualization = datatableVisualizationSetup(); const xyVisualization = xyVisualizationSetup(); const metricVisualization = metricVisualizationSetup(); - const editorFrame = editorFrameSetup(); - const store = new SavedObjectIndexStore(chrome!.getSavedObjectsClient()); + const editorFrameSetupInterface = editorFrameSetup(); + this.store = new SavedObjectIndexStore(chrome!.getSavedObjectsClient()); - editorFrame.registerDatasource('indexpattern', indexPattern); - editorFrame.registerVisualization(xyVisualization); - editorFrame.registerVisualization(datatableVisualization); - editorFrame.registerVisualization(metricVisualization); + editorFrameSetupInterface.registerDatasource('indexpattern', indexPattern); + editorFrameSetupInterface.registerVisualization(xyVisualization); + editorFrameSetupInterface.registerVisualization(datatableVisualization); + editorFrameSetupInterface.registerVisualization(metricVisualization); + } + + start() { + if (this.store === null) { + throw new Error('Start lifecycle called before setup lifecycle'); + } + + const store = this.store; + + const editorFrameStartInterface = editorFrameStart(); - this.instance = editorFrame.createInstance({}); + this.instance = editorFrameStartInterface.createInstance({}); const renderEditor = (routeProps: RouteComponentProps<{ id?: string }>) => { return ( @@ -49,6 +60,7 @@ export class AppPlugin { editorFrame={this.instance!} chrome={chrome} store={new Storage(localStorage)} + savedObjectsClient={chrome.getSavedObjectsClient()} docId={routeProps.match.params.id} docStorage={store} redirectTo={id => { @@ -96,4 +108,5 @@ export class AppPlugin { const app = new AppPlugin(); export const appSetup = () => app.setup(); +export const appStart = () => app.start(); export const appStop = () => app.stop(); diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/expression.tsx b/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/expression.tsx index 0e53ee59761f5..353bb85dd32e1 100644 --- a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/expression.tsx +++ b/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/expression.tsx @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n'; import { EuiBasicTable } from '@elastic/eui'; import { ExpressionFunction, KibanaDatatable } from 'src/legacy/core_plugins/interpreter/types'; import { LensMultiTable } from '../types'; -import { RenderFunction } from '../interpreter_types'; +import { IInterpreterRenderFunction } from '../../../../../../src/legacy/core_plugins/data/public/expressions/lib/_types'; import { FormatFactory } from '../../../../../../src/legacy/ui/public/visualize/loader/pipeline_helpers/utilities'; export interface DatatableColumns { @@ -109,7 +109,7 @@ export const datatableColumns: ExpressionFunction< export const getDatatableRenderer = ( formatFactory: FormatFactory -): RenderFunction => ({ +): IInterpreterRenderFunction => ({ name: 'lens_datatable_renderer', displayName: i18n.translate('xpack.lens.datatable.visualizationName', { defaultMessage: 'Datatable', diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/plugin.tsx index 52f4f99513e7a..9716b6b708b60 100644 --- a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/plugin.tsx @@ -8,16 +8,12 @@ import { CoreSetup } from 'src/core/public'; import { getFormat, FormatFactory } from 'ui/visualize/loader/pipeline_helpers/utilities'; import { datatableVisualization } from './visualization'; - -import { - renderersRegistry, - functionsRegistry, -} from '../../../../../../src/legacy/core_plugins/interpreter/public/registries'; -import { InterpreterSetup, RenderFunction } from '../interpreter_types'; +import { ExpressionsSetup } from '../../../../../../src/legacy/core_plugins/data/public/expressions'; +import { setup as dataSetup } from '../../../../../../src/legacy/core_plugins/data/public/legacy'; import { datatable, datatableColumns, getDatatableRenderer } from './expression'; export interface DatatableVisualizationPluginSetupPlugins { - interpreter: InterpreterSetup; + expressions: ExpressionsSetup; // TODO this is a simulated NP plugin. // Once field formatters are actually migrated, the actual shim can be used fieldFormat: { @@ -30,13 +26,11 @@ class DatatableVisualizationPlugin { setup( _core: CoreSetup | null, - { interpreter, fieldFormat }: DatatableVisualizationPluginSetupPlugins + { expressions, fieldFormat }: DatatableVisualizationPluginSetupPlugins ) { - interpreter.functionsRegistry.register(() => datatableColumns); - interpreter.functionsRegistry.register(() => datatable); - interpreter.renderersRegistry.register( - () => getDatatableRenderer(fieldFormat.formatFactory) as RenderFunction - ); + expressions.registerFunction(() => datatableColumns); + expressions.registerFunction(() => datatable); + expressions.registerRenderer(() => getDatatableRenderer(fieldFormat.formatFactory)); return datatableVisualization; } @@ -48,10 +42,7 @@ const plugin = new DatatableVisualizationPlugin(); export const datatableVisualizationSetup = () => plugin.setup(null, { - interpreter: { - renderersRegistry, - functionsRegistry, - }, + expressions: dataSetup.expressions, fieldFormat: { formatFactory: getFormat, }, diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/expression_helpers.ts b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/expression_helpers.ts index 1b71f28260088..da7ddee67453e 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/expression_helpers.ts +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/expression_helpers.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { TimeRange } from 'ui/timefilter/time_history'; +import { TimeRange } from 'src/plugins/data/public'; import { Query } from 'src/legacy/core_plugins/data/public'; import { Filter } from '@kbn/es-query'; import { Ast, fromExpression, ExpressionFunctionAST } from '@kbn/interpreter/common'; diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.test.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.test.tsx index 2009eb232562b..375b29bd10d34 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.test.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.test.tsx @@ -5,7 +5,7 @@ */ import { Embeddable } from './embeddable'; -import { TimeRange } from 'ui/timefilter/time_history'; +import { TimeRange } from 'src/plugins/data/public'; import { Query, ExpressionRendererProps } from 'src/legacy/core_plugins/data/public'; import { Filter } from '@kbn/es-query'; import { Document } from '../../persistence'; @@ -104,7 +104,7 @@ describe('embeddable', () => { expect(expressionRenderer).toHaveBeenCalledTimes(2); }); - it('should pass context in getInitialContext handler', () => { + it('should pass context to embeddable', () => { const timeRange: TimeRange = { from: 'now-15d', to: 'now' }; const query: Query = { language: 'kquery', query: '' }; const filters: Filter[] = [{ meta: { alias: 'test', negate: false, disabled: false } }]; @@ -120,7 +120,8 @@ describe('embeddable', () => { ); embeddable.render(mountpoint); - expect(expressionRenderer.mock.calls[0][0].getInitialContext!()).toEqual({ + expect(expressionRenderer.mock.calls[0][0].searchContext).toEqual({ + type: 'kibana_context', timeRange, query, filters, diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx index f50ee70731642..8827e5a6397c4 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx @@ -8,7 +8,7 @@ import _ from 'lodash'; import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; -import { TimeRange } from 'ui/timefilter/time_history'; +import { TimeRange } from 'src/plugins/data/public'; import { Query, StaticIndexPattern, ExpressionRenderer } from 'src/legacy/core_plugins/data/public'; import { Filter } from '@kbn/es-query'; import { Subscription } from 'rxjs'; diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts index edd219b64701b..98f831b7050e0 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts @@ -46,8 +46,8 @@ export class EmbeddableFactory extends AbstractEmbeddableFactory { }, }); this.chrome = chrome; - this.indexPatternService = indexPatternService; this.expressionRenderer = expressionRenderer; + this.indexPatternService = indexPatternService; } public isEditable() { diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/expression_wrapper.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/expression_wrapper.tsx index d5ba7bcd39118..e5aabf159de63 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/expression_wrapper.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/expression_wrapper.tsx @@ -10,7 +10,7 @@ import React, { useState, useEffect } from 'react'; import { I18nProvider } from '@kbn/i18n/react'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiFlexGroup, EuiFlexItem, EuiText, EuiIcon } from '@elastic/eui'; -import { TimeRange } from 'ui/timefilter/time_history'; +import { TimeRange } from 'src/plugins/data/public'; import { Query } from 'src/legacy/core_plugins/data/public'; import { Filter } from '@kbn/es-query'; import { ExpressionRenderer } from '../../../../../../../src/legacy/core_plugins/data/public'; @@ -61,7 +61,7 @@ export function ExpressionWrapper({ onRenderFailure={(e: unknown) => { setExpressionError(e); }} - getInitialContext={() => context} + searchContext={{ ...context, type: 'kibana_context' }} /> )} diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/mocks.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/mocks.tsx index a1bcc921104bc..582aa42051aca 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/mocks.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/mocks.tsx @@ -6,11 +6,15 @@ import React from 'react'; import { ExpressionRendererProps } from 'src/legacy/core_plugins/data/public'; -import { setup as data } from '../../../../../../src/legacy/core_plugins/data/public/legacy'; +import { + setup as dataSetup, + start as dataStart, +} from '../../../../../../src/legacy/core_plugins/data/public/legacy'; import { DatasourcePublicAPI, FramePublicAPI, Visualization, Datasource } from '../types'; -import { EditorFrameSetupPlugins } from './plugin'; +import { EditorFrameSetupPlugins, EditorFrameStartPlugins } from './plugin'; -type DataSetup = typeof data; +type DataSetup = typeof dataSetup; +type DataStart = typeof dataStart; export function createMockVisualization(): jest.Mocked { return { @@ -80,10 +84,14 @@ export function createMockFramePublicAPI(): FrameMock { type Omit = Pick>; -export type MockedDependencies = Omit & { +export type MockedSetupDependencies = Omit & { data: Omit & { expressions: jest.Mocked }; }; +export type MockedStartDependencies = Omit & { + data: Omit & { expressions: jest.Mocked }; +}; + export function createExpressionRendererMock(): jest.Mock< React.ReactElement, [ExpressionRendererProps] @@ -91,12 +99,25 @@ export function createExpressionRendererMock(): jest.Mock< return jest.fn(_ => ); } -export function createMockDependencies() { +export function createMockSetupDependencies() { return ({ data: { expressions: { - ExpressionRenderer: createExpressionRendererMock(), - run: jest.fn(_ => Promise.resolve({ type: 'render', as: 'test', value: undefined })), + registerFunction: jest.fn(), + registerRenderer: jest.fn(), + }, + }, + chrome: { + getSavedObjectsClient: () => {}, + }, + } as unknown) as MockedSetupDependencies; +} + +export function createMockStartDependencies() { + return ({ + data: { + expressions: { + ExpressionRenderer: jest.fn(() => null), }, indexPatterns: { indexPatterns: {}, @@ -105,13 +126,5 @@ export function createMockDependencies() { embeddables: { registerEmbeddableFactory: jest.fn(), }, - chrome: { - getSavedObjectsClient: () => {}, - }, - interpreter: { - functionsRegistry: { - register: jest.fn(), - }, - }, - } as unknown) as MockedDependencies; + } as unknown) as MockedStartDependencies; } diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.test.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.test.tsx index 09a22c61d0ccf..aa37b654f4511 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.test.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.test.tsx @@ -5,7 +5,12 @@ */ import { EditorFramePlugin } from './plugin'; -import { createMockDependencies, MockedDependencies } from './mocks'; +import { + MockedSetupDependencies, + MockedStartDependencies, + createMockSetupDependencies, + createMockStartDependencies, +} from './mocks'; jest.mock('ui/chrome', () => ({ getSavedObjectsClient: jest.fn(), @@ -13,18 +18,25 @@ jest.mock('ui/chrome', () => ({ // mock away actual dependencies to prevent all of it being loaded jest.mock('../../../../../../src/legacy/core_plugins/interpreter/public/registries', () => {}); -jest.mock('../../../../../../src/legacy/core_plugins/data/public/legacy', () => {}); -jest.mock('./embeddable/embeddable_factory', () => ({ EmbeddableFactory: class Mock {} })); +jest.mock('../../../../../../src/legacy/core_plugins/data/public/legacy', () => ({ + start: {}, + setup: {}, +})); +jest.mock('./embeddable/embeddable_factory', () => ({ + EmbeddableFactory: class Mock {}, +})); describe('editor_frame plugin', () => { let pluginInstance: EditorFramePlugin; let mountpoint: Element; - let pluginDependencies: MockedDependencies; + let pluginSetupDependencies: MockedSetupDependencies; + let pluginStartDependencies: MockedStartDependencies; beforeEach(() => { pluginInstance = new EditorFramePlugin(); mountpoint = document.createElement('div'); - pluginDependencies = createMockDependencies(); + pluginSetupDependencies = createMockSetupDependencies(); + pluginStartDependencies = createMockStartDependencies(); }); afterEach(() => { @@ -33,7 +45,8 @@ describe('editor_frame plugin', () => { it('should create an editor frame instance which mounts and unmounts', () => { expect(() => { - const publicAPI = pluginInstance.setup(null, pluginDependencies); + pluginInstance.setup(null, pluginSetupDependencies); + const publicAPI = pluginInstance.start(null, pluginStartDependencies); const instance = publicAPI.createInstance({}); instance.mount(mountpoint, { onError: jest.fn(), @@ -46,7 +59,8 @@ describe('editor_frame plugin', () => { }); it('should not have child nodes after unmount', () => { - const publicAPI = pluginInstance.setup(null, pluginDependencies); + pluginInstance.setup(null, pluginSetupDependencies); + const publicAPI = pluginInstance.start(null, pluginStartDependencies); const instance = publicAPI.createInstance({}); instance.mount(mountpoint, { onError: jest.fn(), diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.tsx index 62339a4cc3afc..2b83f50924e8a 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.tsx @@ -7,32 +7,34 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; -import { Registry } from '@kbn/interpreter/target/common'; -import { CoreSetup } from 'src/core/public'; +import { CoreSetup, CoreStart } from 'src/core/public'; import chrome, { Chrome } from 'ui/chrome'; import { Plugin as EmbeddablePlugin } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; -import { setup as embeddablePlugin } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; -import { setup as data } from '../../../../../../src/legacy/core_plugins/data/public/legacy'; -import { ExpressionFunction } from '../../../../../../src/legacy/core_plugins/interpreter/public'; -import { functionsRegistry } from '../../../../../../src/legacy/core_plugins/interpreter/public/registries'; -import { Datasource, Visualization, EditorFrameSetup, EditorFrameInstance } from '../types'; +import { start as embeddablePlugin } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; +import { + setup as dataSetup, + start as dataStart, +} from '../../../../../../src/legacy/core_plugins/data/public/legacy'; +import { + Datasource, + Visualization, + EditorFrameSetup, + EditorFrameInstance, + EditorFrameStart, +} from '../types'; import { EditorFrame } from './editor_frame'; import { mergeTables } from './merge_tables'; import { EmbeddableFactory } from './embeddable/embeddable_factory'; import { getActiveDatasourceIdFromDoc } from './editor_frame/state_management'; export interface EditorFrameSetupPlugins { - data: typeof data; - chrome: Chrome; - embeddables: ReturnType; - interpreter: InterpreterSetup; + data: typeof dataSetup; } -export interface InterpreterSetup { - functionsRegistry: Registry< - ExpressionFunction, - ExpressionFunction - >; +export interface EditorFrameStartPlugins { + data: typeof dataStart; + embeddables: ReturnType; + chrome: Chrome; } export class EditorFramePlugin { @@ -42,8 +44,19 @@ export class EditorFramePlugin { private readonly visualizations: Record = {}; public setup(_core: CoreSetup | null, plugins: EditorFrameSetupPlugins): EditorFrameSetup { - plugins.interpreter.functionsRegistry.register(() => mergeTables); + plugins.data.expressions.registerFunction(() => mergeTables); + + return { + registerDatasource: (name, datasource) => { + this.datasources[name] = datasource as Datasource; + }, + registerVisualization: visualization => { + this.visualizations[visualization.id] = visualization as Visualization; + }, + }; + } + public start(_core: CoreStart | null, plugins: EditorFrameStartPlugins): EditorFrameStart { plugins.embeddables.registerEmbeddableFactory( 'lens', new EmbeddableFactory( @@ -92,12 +105,6 @@ export class EditorFramePlugin { return { createInstance, - registerDatasource: (name, datasource) => { - this.datasources[name] = datasource as Datasource; - }, - registerVisualization: visualization => { - this.visualizations[visualization.id] = visualization as Visualization; - }, }; } @@ -110,12 +117,14 @@ const editorFrame = new EditorFramePlugin(); export const editorFrameSetup = () => editorFrame.setup(null, { - data, + data: dataSetup, + }); + +export const editorFrameStart = () => + editorFrame.start(null, { + data: dataStart, chrome, embeddables: embeddablePlugin, - interpreter: { - functionsRegistry, - }, }); export const editorFrameStop = () => editorFrame.stop(); diff --git a/x-pack/legacy/plugins/lens/public/index.ts b/x-pack/legacy/plugins/lens/public/index.ts index 8e232e878e91a..48a37fd5d8656 100644 --- a/x-pack/legacy/plugins/lens/public/index.ts +++ b/x-pack/legacy/plugins/lens/public/index.ts @@ -20,7 +20,7 @@ import 'uiExports/savedObjectTypes'; import { render, unmountComponentAtNode } from 'react-dom'; import { IScope } from 'angular'; import chrome from 'ui/chrome'; -import { appSetup, appStop } from './app_plugin'; +import { appStart, appSetup, appStop } from './app_plugin'; import { PLUGIN_ID } from '../common'; // TODO: Convert this to the "new platform" way of doing UI @@ -31,7 +31,8 @@ function Root($scope: IScope, $element: JQLite) { appStop(); }); - return render(appSetup(), el); + appSetup(); + return render(appStart(), el); } chrome.setRootController(PLUGIN_ID, Root); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx index 1e801467f3f94..2351bd7952a3d 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx @@ -14,7 +14,7 @@ import { IndexPatternDimensionPanel, IndexPatternDimensionPanelProps } from './d import { DropHandler, DragContextState } from '../../drag_drop'; import { createMockedDragDropContext } from '../mocks'; import { mountWithIntl as mount, shallowWithIntl as shallow } from 'test_utils/enzyme_helpers'; -import { UiSettingsClientContract } from 'src/core/public'; +import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; import { Storage } from 'ui/storage'; jest.mock('ui/new_platform'); @@ -121,6 +121,7 @@ describe('IndexPatternDimensionPanel', () => { filterOperations: () => true, storage: {} as Storage, uiSettings: {} as UiSettingsClientContract, + savedObjectsClient: {} as SavedObjectsClientContract, }; jest.clearAllMocks(); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx index 0076a9f599bb9..9158806138c2e 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx @@ -9,7 +9,7 @@ import React, { memo, useMemo } from 'react'; import { EuiButtonIcon } from '@elastic/eui'; import { Storage } from 'ui/storage'; import { i18n } from '@kbn/i18n'; -import { UiSettingsClientContract } from 'src/core/public'; +import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; import { DatasourceDimensionPanelProps, StateSetter } from '../../types'; import { IndexPatternColumn, @@ -30,6 +30,7 @@ export type IndexPatternDimensionPanelProps = DatasourceDimensionPanelProps & { dragDropContext: DragContextState; uiSettings: UiSettingsClientContract; storage: Storage; + savedObjectsClient: SavedObjectsClientContract; layerId: string; }; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx index 7eb03152b341f..eaec3ea8b6c5b 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx @@ -355,6 +355,7 @@ export function PopoverEditor(props: PopoverEditorProps) { currentColumn={state.layers[layerId].columns[columnId]} storage={props.storage} uiSettings={props.uiSettings} + savedObjectsClient={props.savedObjectsClient} layerId={layerId} /> )} diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.test.ts b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.test.ts index d69a3827a43c9..0aa21e867fc30 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.test.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.test.ts @@ -9,6 +9,7 @@ import { data as dataMock } from '../../../../../../src/legacy/core_plugins/data import { Storage } from 'ui/storage'; import { functionsRegistry } from '../../../../../../src/legacy/core_plugins/interpreter/public/registries'; import { toastNotifications as notificationsMock } from 'ui/notify'; +import { SavedObjectsClientContract } from 'src/core/public'; import { getIndexPatternDatasource, IndexPatternPersistedState, @@ -140,6 +141,7 @@ describe('IndexPattern Data Source', () => { interpreter: { functionsRegistry }, toastNotifications: notificationsMock, data: dataMock, + savedObjectsClient: {} as SavedObjectsClientContract, }); persistedState = { diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.tsx index c21f6a68c0416..78174e8d96f63 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.tsx @@ -8,6 +8,7 @@ import _ from 'lodash'; import React from 'react'; import { render } from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; +import { SavedObjectsClientContract } from 'src/core/public'; import { Storage } from 'ui/storage'; import { DatasourceDimensionPanelProps, @@ -152,7 +153,11 @@ export function getIndexPatternDatasource({ chrome, toastNotifications, storage, -}: IndexPatternDatasourcePluginPlugins & { storage: Storage }) { + savedObjectsClient, +}: IndexPatternDatasourcePluginPlugins & { + storage: Storage; + savedObjectsClient: SavedObjectsClientContract; +}) { const uiSettings = chrome.getUiSettingsClient(); // Not stateful. State is persisted to the frame const indexPatternDatasource: Datasource = { @@ -267,6 +272,7 @@ export function getIndexPatternDatasource({ setState={setState} uiSettings={uiSettings} storage={storage} + savedObjectsClient={savedObjectsClient} layerId={props.layerId} {...props} /> diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern_suggestions.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern_suggestions.test.tsx index 7201cd12fce2a..aa07a95a76091 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern_suggestions.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern_suggestions.test.tsx @@ -8,6 +8,7 @@ import chromeMock from 'ui/chrome'; import { data as dataMock } from '../../../../../../src/legacy/core_plugins/data/public/setup'; import { functionsRegistry } from '../../../../../../src/legacy/core_plugins/interpreter/public/registries'; import { toastNotifications as notificationsMock } from 'ui/notify'; +import { SavedObjectsClientContract } from 'src/core/public'; import { getIndexPatternDatasource, IndexPatternPersistedState, @@ -140,6 +141,7 @@ describe('IndexPattern Data Source suggestions', () => { interpreter: { functionsRegistry }, toastNotifications: notificationsMock, data: dataMock, + savedObjectsClient: {} as SavedObjectsClientContract, }); persistedState = { diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx index 4b8b556927052..76f67bcecbf47 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx @@ -10,7 +10,7 @@ import { dateHistogramOperation } from '.'; import { shallow } from 'enzyme'; import { IndexPatternPrivateState } from '../../indexpattern'; import { EuiRange, EuiSwitch } from '@elastic/eui'; -import { UiSettingsClientContract } from 'src/core/public'; +import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; import { Storage } from 'ui/storage'; import { createMockedIndexPattern } from '../../mocks'; @@ -323,6 +323,7 @@ describe('date_histogram', () => { currentColumn={state.layers.first.columns.col1 as DateHistogramIndexPatternColumn} storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -340,6 +341,7 @@ describe('date_histogram', () => { layerId="second" storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -356,6 +358,7 @@ describe('date_histogram', () => { layerId="third" storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); expect(instance.find(EuiRange).exists()).toBe(false); @@ -373,6 +376,7 @@ describe('date_histogram', () => { currentColumn={state.layers.third.columns.col1 as DateHistogramIndexPatternColumn} storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); instance.find(EuiSwitch).prop('onChange')!({ @@ -394,6 +398,7 @@ describe('date_histogram', () => { currentColumn={state.layers.first.columns.col1 as DateHistogramIndexPatternColumn} storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -452,6 +457,7 @@ describe('date_histogram', () => { currentColumn={state.layers.first.columns.col1 as DateHistogramIndexPatternColumn} storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx index a90e4e7a3068d..9558a141ad7a0 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx @@ -228,14 +228,16 @@ export const dateHistogramOperation: OperationDefinition) => + onChange={( + e: React.ChangeEvent | React.MouseEvent + ) => setState( updateColumnParam({ state, layerId, currentColumn, paramName: 'interval', - value: numericToInterval(Number(e.target.value)), + value: numericToInterval(Number((e.target as HTMLInputElement).value)), }) ) } diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/filter_ratio.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/filter_ratio.test.tsx index 8864e959977a8..e9da64c44fcbd 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/filter_ratio.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/filter_ratio.test.tsx @@ -11,7 +11,7 @@ import { FilterRatioIndexPatternColumn } from './filter_ratio'; import { filterRatioOperation } from '.'; import { IndexPatternPrivateState } from '../../indexpattern'; import { Storage } from 'ui/storage'; -import { UiSettingsClientContract } from 'src/core/public'; +import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; import { QueryBarInput } from '../../../../../../../../src/legacy/core_plugins/data/public/query'; import { createMockedIndexPattern } from '../../mocks'; @@ -108,6 +108,7 @@ describe('filter_ratio', () => { currentColumn={state.layers.first.columns.col1 as FilterRatioIndexPatternColumn} storage={storageMock} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); }).not.toThrow(); @@ -123,6 +124,7 @@ describe('filter_ratio', () => { currentColumn={state.layers.first.columns.col1 as FilterRatioIndexPatternColumn} storage={storageMock} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -141,6 +143,7 @@ describe('filter_ratio', () => { currentColumn={state.layers.first.columns.col1 as FilterRatioIndexPatternColumn} storage={storageMock} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -180,6 +183,7 @@ describe('filter_ratio', () => { currentColumn={state.layers.first.columns.col1 as FilterRatioIndexPatternColumn} storage={storageMock} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/filter_ratio.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/filter_ratio.tsx index 0d50801708b3e..de6e34ec3d941 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/filter_ratio.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/filter_ratio.tsx @@ -77,7 +77,15 @@ export const filterRatioOperation: OperationDefinition { + paramEditor: ({ + state, + setState, + currentColumn, + uiSettings, + storage, + layerId, + savedObjectsClient, + }) => { const [hasDenominator, setDenominator] = useState(false); return ( @@ -94,6 +102,7 @@ export const filterRatioOperation: OperationDefinition { setState( updateColumnParam({ @@ -121,6 +130,7 @@ export const filterRatioOperation: OperationDefinition { setState( updateColumnParam({ diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts index 13020605d3606..9f82d0f2a1763 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts @@ -5,7 +5,7 @@ */ import { Storage } from 'ui/storage'; -import { UiSettingsClientContract } from 'src/core/public'; +import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; import { termsOperation } from './terms'; import { minOperation, averageOperation, sumOperation, maxOperation } from './metrics'; import { dateHistogramOperation } from './date_histogram'; @@ -46,6 +46,7 @@ export interface ParamEditorProps { layerId: string; uiSettings: UiSettingsClientContract; storage: Storage; + savedObjectsClient: SavedObjectsClientContract; } interface BaseOperationDefinitionProps { diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx index 56b15eaaa47db..30b8bfb0ec5bd 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { IndexPatternPrivateState } from '../../indexpattern'; import { EuiRange, EuiSelect } from '@elastic/eui'; -import { UiSettingsClientContract } from 'src/core/public'; +import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; import { Storage } from 'ui/storage'; import { createMockedIndexPattern } from '../../mocks'; import { TermsIndexPatternColumn } from './terms'; @@ -312,6 +312,7 @@ describe('terms', () => { layerId="first" storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -358,6 +359,7 @@ describe('terms', () => { currentColumn={state.layers.first.columns.col1 as TermsIndexPatternColumn} storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -377,6 +379,7 @@ describe('terms', () => { layerId="first" storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -423,6 +426,7 @@ describe('terms', () => { currentColumn={state.layers.first.columns.col1 as TermsIndexPatternColumn} storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -445,6 +449,7 @@ describe('terms', () => { currentColumn={state.layers.first.columns.col1 as TermsIndexPatternColumn} storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -488,6 +493,7 @@ describe('terms', () => { currentColumn={state.layers.first.columns.col1 as TermsIndexPatternColumn} storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); @@ -505,6 +511,7 @@ describe('terms', () => { currentColumn={state.layers.first.columns.col1 as TermsIndexPatternColumn} storage={{} as Storage} uiSettings={{} as UiSettingsClientContract} + savedObjectsClient={{} as SavedObjectsClientContract} /> ); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.tsx index 6f1a1a3b5471c..52b27f85fb495 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.tsx @@ -181,14 +181,16 @@ export const termsOperation: OperationDefinition = { step={1} value={currentColumn.params.size} showInput - onChange={(e: React.ChangeEvent) => + onChange={( + e: React.ChangeEvent | React.MouseEvent + ) => setState( updateColumnParam({ state, layerId, currentColumn, paramName: 'size', - value: Number(e.target.value), + value: Number((e.target as HTMLInputElement).value), }) ) } diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/plugin.tsx index 2f1c23b1bf9dc..63e9642636063 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/plugin.tsx @@ -50,6 +50,7 @@ class IndexPatternDatasourcePlugin { toastNotifications: toast, data, storage: new Storage(localStorage), + savedObjectsClient: chrome.getSavedObjectsClient(), }); } diff --git a/x-pack/legacy/plugins/lens/public/interpreter_types.ts b/x-pack/legacy/plugins/lens/public/interpreter_types.ts deleted file mode 100644 index fe02ab11757cc..0000000000000 --- a/x-pack/legacy/plugins/lens/public/interpreter_types.ts +++ /dev/null @@ -1,32 +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 { Registry } from '@kbn/interpreter/target/common'; -import { ExpressionFunction } from '../../../../../src/legacy/core_plugins/interpreter/public'; - -// TODO these are intermediary types because interpreter is not typed yet -// They can get replaced by references to the real interfaces as soon as they -// are available -interface RenderHandlers { - done: () => void; - onDestroy: (fn: () => void) => void; -} -export interface RenderFunction { - name: string; - displayName: string; - help: string; - validate: () => void; - reuseDomNode: boolean; - render: (domNode: Element, data: T, handlers: RenderHandlers) => void; -} - -export interface InterpreterSetup { - renderersRegistry: Registry; - functionsRegistry: Registry< - ExpressionFunction, - ExpressionFunction - >; -} diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_expression.tsx b/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_expression.tsx index d6c29abf70c4d..0b7f6aeda05a9 100644 --- a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_expression.tsx +++ b/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_expression.tsx @@ -8,9 +8,9 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/types'; import { FormatFactory } from 'ui/visualize/loader/pipeline_helpers/utilities'; +import { IInterpreterRenderFunction } from '../../../../../../src/legacy/core_plugins/data/public/expressions/lib/_types'; import { MetricConfig } from './types'; import { LensMultiTable } from '../types'; -import { RenderFunction } from './plugin'; import { AutoScale } from './auto_scale'; export interface MetricChartProps { @@ -73,7 +73,7 @@ export const metricChart: ExpressionFunction< export const getMetricChartRenderer = ( formatFactory: FormatFactory -): RenderFunction => ({ +): IInterpreterRenderFunction => ({ name: 'lens_metric_chart_renderer', displayName: 'Metric Chart', help: 'Metric Chart Renderer', diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/plugin.tsx index f8bfd15b49892..fc3fc9462a498 100644 --- a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/plugin.tsx @@ -4,44 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Registry } from '@kbn/interpreter/target/common'; import { CoreSetup } from 'src/core/public'; import { FormatFactory, getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities'; import { metricVisualization } from './metric_visualization'; -import { - renderersRegistry, - functionsRegistry, -} from '../../../../../../src/legacy/core_plugins/interpreter/public/registries'; -import { ExpressionFunction } from '../../../../../../src/legacy/core_plugins/interpreter/public'; +import { ExpressionsSetup } from '../../../../../../src/legacy/core_plugins/data/public/expressions'; +import { setup as dataSetup } from '../../../../../../src/legacy/core_plugins/data/public/legacy'; import { metricChart, getMetricChartRenderer } from './metric_expression'; -// TODO these are intermediary types because interpreter is not typed yet -// They can get replaced by references to the real interfaces as soon as they -// are available -interface RenderHandlers { - done: () => void; - onDestroy: (fn: () => void) => void; -} - -export interface RenderFunction { - name: string; - displayName: string; - help: string; - validate: () => void; - reuseDomNode: boolean; - render: (domNode: Element, data: T, handlers: RenderHandlers) => void; -} - -export interface InterpreterSetup { - renderersRegistry: Registry; - functionsRegistry: Registry< - ExpressionFunction, - ExpressionFunction - >; -} - export interface MetricVisualizationPluginSetupPlugins { - interpreter: InterpreterSetup; + expressions: ExpressionsSetup; // TODO this is a simulated NP plugin. // Once field formatters are actually migrated, the actual shim can be used fieldFormat: { @@ -54,13 +25,11 @@ class MetricVisualizationPlugin { setup( _core: CoreSetup | null, - { interpreter, fieldFormat }: MetricVisualizationPluginSetupPlugins + { expressions, fieldFormat }: MetricVisualizationPluginSetupPlugins ) { - interpreter.functionsRegistry.register(() => metricChart); + expressions.registerFunction(() => metricChart); - interpreter.renderersRegistry.register( - () => getMetricChartRenderer(fieldFormat.formatFactory) as RenderFunction - ); + expressions.registerRenderer(() => getMetricChartRenderer(fieldFormat.formatFactory)); return metricVisualization; } @@ -72,10 +41,7 @@ const plugin = new MetricVisualizationPlugin(); export const metricVisualizationSetup = () => plugin.setup(null, { - interpreter: { - renderersRegistry, - functionsRegistry, - }, + expressions: dataSetup.expressions, fieldFormat: { formatFactory: getFormat, }, diff --git a/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts b/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts index 8f49f6f12ee16..19f313f2d56d6 100644 --- a/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts +++ b/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts @@ -5,12 +5,12 @@ */ import { i18n } from '@kbn/i18n'; -import { visualizations } from '../../../../../src/legacy/core_plugins/visualizations/public'; +import { setup } from '../../../../../src/legacy/core_plugins/visualizations/public/np_ready/public/legacy'; import { BASE_APP_URL, getEditPath } from '../common'; const NOT_INTERNATIONALIZED_PRODUCT_NAME = 'Lens Visualizations'; -visualizations.types.visTypeAliasRegistry.add({ +setup.types.visTypeAliasRegistry.add({ aliasUrl: BASE_APP_URL, name: NOT_INTERNATIONALIZED_PRODUCT_NAME, title: i18n.translate('xpack.lens.visTypeAlias.title', { diff --git a/x-pack/legacy/plugins/lens/public/types.ts b/x-pack/legacy/plugins/lens/public/types.ts index 14fa018fa6e5d..c047ad4fbfe7c 100644 --- a/x-pack/legacy/plugins/lens/public/types.ts +++ b/x-pack/legacy/plugins/lens/public/types.ts @@ -33,12 +33,15 @@ export interface EditorFrameInstance { } export interface EditorFrameSetup { - createInstance: (options: EditorFrameOptions) => EditorFrameInstance; // generic type on the API functions to pull the "unknown vs. specific type" error into the implementation registerDatasource: (name: string, datasource: Datasource) => void; registerVisualization: (visualization: Visualization) => void; } +export interface EditorFrameStart { + createInstance: (options: EditorFrameOptions) => EditorFrameInstance; +} + // Hints the default nesting to the data source. 0 is the highest priority export type DimensionPriority = 0 | 1 | 2; diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx index 6692fc17f05ac..0f0e1e8534cc0 100644 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx @@ -8,19 +8,14 @@ import { CoreSetup, UiSettingsClientContract } from 'src/core/public'; import chrome, { Chrome } from 'ui/chrome'; import moment from 'moment-timezone'; import { getFormat, FormatFactory } from 'ui/visualize/loader/pipeline_helpers/utilities'; - -import { - renderersRegistry, - functionsRegistry, -} from '../../../../../../src/legacy/core_plugins/interpreter/public/registries'; - +import { ExpressionsSetup } from '../../../../../../src/legacy/core_plugins/data/public/expressions'; +import { setup as dataSetup } from '../../../../../../src/legacy/core_plugins/data/public/legacy'; import { xyVisualization } from './xy_visualization'; -import { InterpreterSetup, RenderFunction } from '../interpreter_types'; import { xyChart, getXyChartRenderer } from './xy_expression'; import { legendConfig, xConfig, layerConfig } from './types'; export interface XyVisualizationPluginSetupPlugins { - interpreter: InterpreterSetup; + expressions: ExpressionsSetup; chrome: Chrome; // TODO this is a simulated NP plugin. // Once field formatters are actually migrated, the actual shim can be used @@ -44,22 +39,21 @@ class XyVisualizationPlugin { setup( _core: CoreSetup | null, { - interpreter, + expressions, fieldFormat: { formatFactory }, chrome: { getUiSettingsClient }, }: XyVisualizationPluginSetupPlugins ) { - interpreter.functionsRegistry.register(() => legendConfig); - interpreter.functionsRegistry.register(() => xConfig); - interpreter.functionsRegistry.register(() => layerConfig); - interpreter.functionsRegistry.register(() => xyChart); + expressions.registerFunction(() => legendConfig); + expressions.registerFunction(() => xConfig); + expressions.registerFunction(() => layerConfig); + expressions.registerFunction(() => xyChart); - interpreter.renderersRegistry.register( - () => - getXyChartRenderer({ - formatFactory, - timeZone: getTimeZone(getUiSettingsClient()), - }) as RenderFunction + expressions.registerRenderer(() => + getXyChartRenderer({ + formatFactory, + timeZone: getTimeZone(getUiSettingsClient()), + }) ); return xyVisualization; @@ -72,10 +66,7 @@ const plugin = new XyVisualizationPlugin(); export const xyVisualizationSetup = () => plugin.setup(null, { - interpreter: { - renderersRegistry, - functionsRegistry, - }, + expressions: dataSetup.expressions, fieldFormat: { formatFactory: getFormat, }, diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.tsx b/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.tsx index df69f510a8d21..3eeeee618fb88 100644 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.tsx +++ b/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.tsx @@ -23,9 +23,9 @@ import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiText, IconType } from '@elastic/ import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; import { FormatFactory } from '../../../../../../src/legacy/ui/public/visualize/loader/pipeline_helpers/utilities'; +import { IInterpreterRenderFunction } from '../../../../../../src/legacy/core_plugins/data/public/expressions/lib/_types'; import { LensMultiTable } from '../types'; import { XYArgs, SeriesType, visualizationTypes } from './types'; -import { RenderFunction } from '../interpreter_types'; export interface XYChartProps { data: LensMultiTable; @@ -93,7 +93,7 @@ export interface XYChartProps { export const getXyChartRenderer = (dependencies: { formatFactory: FormatFactory; timeZone: string; -}): RenderFunction => ({ +}): IInterpreterRenderFunction => ({ name: 'lens_xy_chart_renderer', displayName: 'XY Chart', help: i18n.translate('xpack.lens.xyChart.renderer.help', {