diff --git a/x-pack/legacy/plugins/lens/public/app_plugin/index.ts b/x-pack/legacy/plugins/lens/public/app_plugin/index.ts index f75dce9b7507f..1460fdfef37e6 100644 --- a/x-pack/legacy/plugins/lens/public/app_plugin/index.ts +++ b/x-pack/legacy/plugins/lens/public/app_plugin/index.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export * from './plugin'; +export * from './app'; diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/_index.scss b/x-pack/legacy/plugins/lens/public/datatable_visualization/_index.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/_index.scss rename to x-pack/legacy/plugins/lens/public/datatable_visualization/_index.scss diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/_visualization.scss b/x-pack/legacy/plugins/lens/public/datatable_visualization/_visualization.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/_visualization.scss rename to x-pack/legacy/plugins/lens/public/datatable_visualization/_visualization.scss diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/expression.tsx b/x-pack/legacy/plugins/lens/public/datatable_visualization/expression.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/expression.tsx rename to x-pack/legacy/plugins/lens/public/datatable_visualization/expression.tsx diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization/index.ts b/x-pack/legacy/plugins/lens/public/datatable_visualization/index.ts new file mode 100644 index 0000000000000..6dee47cc632c2 --- /dev/null +++ b/x-pack/legacy/plugins/lens/public/datatable_visualization/index.ts @@ -0,0 +1,32 @@ +/* + * 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 { CoreSetup } from 'src/core/public'; +import { datatableVisualization } from './visualization'; +import { ExpressionsSetup } from '../../../../../../src/plugins/expressions/public'; +import { datatable, datatableColumns, getDatatableRenderer } from './expression'; +import { FormatFactory } from '../legacy_imports'; +import { EditorFrameSetup } from '../types'; + +export interface DatatableVisualizationPluginSetupPlugins { + expressions: ExpressionsSetup; + formatFactory: FormatFactory; + editorFrame: EditorFrameSetup; +} + +export class DatatableVisualization { + constructor() {} + + setup( + _core: CoreSetup | null, + { expressions, formatFactory, editorFrame }: DatatableVisualizationPluginSetupPlugins + ) { + expressions.registerFunction(() => datatableColumns); + expressions.registerFunction(() => datatable); + expressions.registerRenderer(() => getDatatableRenderer(formatFactory)); + editorFrame.registerVisualization(datatableVisualization); + } +} diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/visualization.test.tsx b/x-pack/legacy/plugins/lens/public/datatable_visualization/visualization.test.tsx similarity index 99% rename from x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/visualization.test.tsx rename to x-pack/legacy/plugins/lens/public/datatable_visualization/visualization.test.tsx index cb9350226575c..0cba22170df1f 100644 --- a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/visualization.test.tsx +++ b/x-pack/legacy/plugins/lens/public/datatable_visualization/visualization.test.tsx @@ -5,7 +5,7 @@ */ import React from 'react'; -import { createMockDatasource } from '../editor_frame_plugin/mocks'; +import { createMockDatasource } from '../editor_frame_service/mocks'; import { DatatableVisualizationState, datatableVisualization, diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/visualization.tsx b/x-pack/legacy/plugins/lens/public/datatable_visualization/visualization.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/visualization.tsx rename to x-pack/legacy/plugins/lens/public/datatable_visualization/visualization.tsx 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 deleted file mode 100644 index ed047f52ecc0f..0000000000000 --- a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/plugin.tsx +++ /dev/null @@ -1,49 +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 { npSetup } from 'ui/new_platform'; -import { CoreSetup } from 'src/core/public'; -import { getFormat, FormatFactory } from 'ui/visualize/loader/pipeline_helpers/utilities'; -import { datatableVisualization } from './visualization'; -import { ExpressionsSetup } from '../../../../../../src/plugins/expressions/public'; -import { datatable, datatableColumns, getDatatableRenderer } from './expression'; - -export interface DatatableVisualizationPluginSetupPlugins { - expressions: ExpressionsSetup; - // TODO this is a simulated NP plugin. - // Once field formatters are actually migrated, the actual shim can be used - fieldFormat: { - formatFactory: FormatFactory; - }; -} - -class DatatableVisualizationPlugin { - constructor() {} - - setup( - _core: CoreSetup | null, - { expressions, fieldFormat }: DatatableVisualizationPluginSetupPlugins - ) { - expressions.registerFunction(() => datatableColumns); - expressions.registerFunction(() => datatable); - expressions.registerRenderer(() => getDatatableRenderer(fieldFormat.formatFactory)); - - return datatableVisualization; - } - - stop() {} -} - -const plugin = new DatatableVisualizationPlugin(); - -export const datatableVisualizationSetup = () => - plugin.setup(npSetup.core, { - expressions: npSetup.plugins.expressions, - fieldFormat: { - formatFactory: getFormat, - }, - }); -export const datatableVisualizationStop = () => plugin.stop(); diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/index.ts b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/index.ts deleted file mode 100644 index f75dce9b7507f..0000000000000 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/index.ts +++ /dev/null @@ -1,7 +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. - */ - -export * from './plugin'; diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/_index.scss b/x-pack/legacy/plugins/lens/public/editor_frame_service/_index.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/_index.scss rename to x-pack/legacy/plugins/lens/public/editor_frame_service/_index.scss diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/__mocks__/suggestion_helpers.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/__mocks__/suggestion_helpers.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/__mocks__/suggestion_helpers.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/__mocks__/suggestion_helpers.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_chart_switch.scss b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_chart_switch.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_chart_switch.scss rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_chart_switch.scss diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_data_panel_wrapper.scss b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_data_panel_wrapper.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_data_panel_wrapper.scss rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_data_panel_wrapper.scss diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_expression_renderer.scss b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_expression_renderer.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_expression_renderer.scss rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_expression_renderer.scss diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_frame_layout.scss b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_frame_layout.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_frame_layout.scss rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_frame_layout.scss diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_suggestion_panel.scss b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_suggestion_panel.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_suggestion_panel.scss rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_suggestion_panel.scss diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_workspace_panel_wrapper.scss b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_workspace_panel_wrapper.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/_workspace_panel_wrapper.scss rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/_workspace_panel_wrapper.scss diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/chart_switch.test.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/chart_switch.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/chart_switch.test.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/chart_switch.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/chart_switch.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/chart_switch.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/chart_switch.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/chart_switch.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/config_panel_wrapper.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/config_panel_wrapper.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/config_panel_wrapper.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/config_panel_wrapper.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/data_panel_wrapper.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/data_panel_wrapper.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/data_panel_wrapper.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/data_panel_wrapper.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/editor_frame.test.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/editor_frame.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/editor_frame.test.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/editor_frame.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/editor_frame.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/editor_frame.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/editor_frame.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/editor_frame.tsx 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_service/editor_frame/expression_helpers.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/expression_helpers.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/expression_helpers.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/frame_layout.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/frame_layout.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/frame_layout.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/frame_layout.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/index.scss b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/index.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/index.scss rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/index.scss diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/index.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/index.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/index.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/index.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/layer_actions.test.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/layer_actions.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/layer_actions.test.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/layer_actions.test.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/layer_actions.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/layer_actions.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/layer_actions.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/layer_actions.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/save.test.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/save.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/save.test.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/save.test.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/save.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/save.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/save.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/save.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/state_management.test.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/state_management.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/state_management.test.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/state_management.test.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/state_management.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/state_management.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/state_management.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/state_management.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/suggestion_helpers.test.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/suggestion_helpers.test.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/suggestion_helpers.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/suggestion_helpers.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/suggestion_panel.test.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/suggestion_panel.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/suggestion_panel.test.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/suggestion_panel.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/suggestion_panel.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/suggestion_panel.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/suggestion_panel.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/suggestion_panel.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/workspace_panel.test.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/workspace_panel.test.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/workspace_panel.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/workspace_panel.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/workspace_panel_wrapper.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel_wrapper.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/editor_frame/workspace_panel_wrapper.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel_wrapper.tsx 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_service/embeddable/embeddable.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.test.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/embeddable/embeddable.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/embeddable/embeddable.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/embeddable/embeddable.tsx 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_service/embeddable/embeddable_factory.ts similarity index 78% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/embeddable/embeddable_factory.ts index 00cde2ee3e04c..e8bb8914fa292 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts +++ b/x-pack/legacy/plugins/lens/public/editor_frame_service/embeddable/embeddable_factory.ts @@ -4,10 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import _ from 'lodash'; -import { Chrome } from 'ui/chrome'; - -import { capabilities } from 'ui/capabilities'; +import { + Capabilities, + HttpSetup, + RecursiveReadonly, + SavedObjectsClientContract, +} from 'kibana/public'; import { i18n } from '@kbn/i18n'; import { IndexPatternsContract, IndexPattern } from '../../../../../../../src/plugins/data/public'; import { ReactExpressionRendererType } from '../../../../../../../src/plugins/expressions/public'; @@ -24,14 +26,12 @@ import { getEditPath } from '../../../../../../plugins/lens/common'; export class EmbeddableFactory extends AbstractEmbeddableFactory { type = DOC_TYPE; - private chrome: Chrome; - private indexPatternService: IndexPatternsContract; - private expressionRenderer: ReactExpressionRendererType; - constructor( - chrome: Chrome, - expressionRenderer: ReactExpressionRendererType, - indexPatternService: IndexPatternsContract + private coreHttp: HttpSetup, + private capabilities: RecursiveReadonly, + private savedObjectsClient: SavedObjectsClientContract, + private expressionRenderer: ReactExpressionRendererType, + private indexPatternService: IndexPatternsContract ) { super({ savedObjectMetaData: { @@ -42,13 +42,10 @@ export class EmbeddableFactory extends AbstractEmbeddableFactory { getIconForSavedObject: () => 'lensApp', }, }); - this.chrome = chrome; - this.expressionRenderer = expressionRenderer; - this.indexPatternService = indexPatternService; } public isEditable() { - return capabilities.get().visualize.save as boolean; + return this.capabilities.visualize.save as boolean; } canCreateNew() { @@ -66,7 +63,7 @@ export class EmbeddableFactory extends AbstractEmbeddableFactory { input: Partial & { id: string }, parent?: IContainer ) { - const store = new SavedObjectIndexStore(this.chrome.getSavedObjectsClient()); + const store = new SavedObjectIndexStore(this.savedObjectsClient); const savedVis = await store.load(savedObjectId); const promises = savedVis.state.datasourceMetaData.filterableIndexPatterns.map( @@ -91,7 +88,7 @@ export class EmbeddableFactory extends AbstractEmbeddableFactory { this.expressionRenderer, { savedVis, - editUrl: this.chrome.addBasePath(getEditPath(savedObjectId)), + editUrl: this.coreHttp.basePath.prepend(getEditPath(savedObjectId)), editable: this.isEditable(), indexPatterns, }, 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_service/embeddable/expression_wrapper.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/expression_wrapper.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/embeddable/expression_wrapper.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/index.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/index.ts similarity index 90% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/index.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/index.ts index f75dce9b7507f..d6e96d74b766c 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/index.ts +++ b/x-pack/legacy/plugins/lens/public/editor_frame_service/index.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export * from './plugin'; +export * from './service'; diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/merge_tables.test.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/merge_tables.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/merge_tables.test.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/merge_tables.test.ts diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/merge_tables.ts b/x-pack/legacy/plugins/lens/public/editor_frame_service/merge_tables.ts similarity index 96% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/merge_tables.ts rename to x-pack/legacy/plugins/lens/public/editor_frame_service/merge_tables.ts index 3c466522e1ebe..c5be5f524755d 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/merge_tables.ts +++ b/x-pack/legacy/plugins/lens/public/editor_frame_service/merge_tables.ts @@ -11,7 +11,7 @@ import { KibanaDatatable, } from 'src/plugins/expressions/public'; import { LensMultiTable } from '../types'; -import { toAbsoluteDates } from '../indexpattern_plugin/auto_date'; +import { toAbsoluteDates } from '../indexpattern_datasource/auto_date'; interface MergeTables { layerIds: string[]; diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/mocks.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/mocks.tsx similarity index 95% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/mocks.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/mocks.tsx index b4fc88cb074c7..cd121a1f96a2b 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/mocks.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_service/mocks.tsx @@ -10,12 +10,10 @@ import { ExpressionsSetup, ExpressionsStart, } from '../../../../../../src/plugins/expressions/public'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { embeddablePluginMock } from '../../../../../../src/plugins/embeddable/public/mocks'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { expressionsPluginMock } from '../../../../../../src/plugins/expressions/public/mocks'; import { DatasourcePublicAPI, FramePublicAPI, Datasource, Visualization } from '../types'; -import { EditorFrameSetupPlugins, EditorFrameStartPlugins } from './plugin'; +import { EditorFrameSetupPlugins, EditorFrameStartPlugins } from './service'; export function createMockVisualization(): jest.Mocked { return { @@ -108,9 +106,6 @@ export function createMockSetupDependencies() { data: {}, embeddable: embeddablePluginMock.createSetupContract(), expressions: expressionsPluginMock.createSetupContract(), - chrome: { - getSavedObjectsClient: () => {}, - }, } as unknown) as MockedSetupDependencies; } diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.test.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_service/service.test.tsx similarity index 66% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.test.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/service.test.tsx index 7a6067dd5f23c..ef4b5f6d7b834 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.test.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_service/service.test.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EditorFramePlugin } from './plugin'; +import { EditorFrameService } from './service'; import { coreMock } from 'src/core/public/mocks'; import { MockedSetupDependencies, @@ -25,14 +25,14 @@ jest.mock('./embeddable/embeddable_factory', () => ({ EmbeddableFactory: class Mock {}, })); -describe('editor_frame plugin', () => { - let pluginInstance: EditorFramePlugin; +describe('editor_frame service', () => { + let pluginInstance: EditorFrameService; let mountpoint: Element; let pluginSetupDependencies: MockedSetupDependencies; let pluginStartDependencies: MockedStartDependencies; beforeEach(() => { - pluginInstance = new EditorFramePlugin(); + pluginInstance = new EditorFrameService(); mountpoint = document.createElement('div'); pluginSetupDependencies = createMockSetupDependencies(); pluginStartDependencies = createMockStartDependencies(); @@ -42,26 +42,28 @@ describe('editor_frame plugin', () => { mountpoint.remove(); }); - it('should create an editor frame instance which mounts and unmounts', () => { - expect(() => { - pluginInstance.setup(coreMock.createSetup(), pluginSetupDependencies); - const publicAPI = pluginInstance.start(coreMock.createStart(), pluginStartDependencies); - const instance = publicAPI.createInstance({}); - instance.mount(mountpoint, { - onError: jest.fn(), - onChange: jest.fn(), - dateRange: { fromDate: '', toDate: '' }, - query: { query: '', language: 'lucene' }, - filters: [], - }); - instance.unmount(); - }).not.toThrowError(); + it('should create an editor frame instance which mounts and unmounts', async () => { + await expect( + (async () => { + pluginInstance.setup(coreMock.createSetup(), pluginSetupDependencies); + const publicAPI = pluginInstance.start(coreMock.createStart(), pluginStartDependencies); + const instance = await publicAPI.createInstance({}); + instance.mount(mountpoint, { + onError: jest.fn(), + onChange: jest.fn(), + dateRange: { fromDate: '', toDate: '' }, + query: { query: '', language: 'lucene' }, + filters: [], + }); + instance.unmount(); + })() + ).resolves.toBeUndefined(); }); - it('should not have child nodes after unmount', () => { + it('should not have child nodes after unmount', async () => { pluginInstance.setup(coreMock.createSetup(), pluginSetupDependencies); const publicAPI = pluginInstance.start(coreMock.createStart(), pluginStartDependencies); - const instance = publicAPI.createInstance({}); + const instance = await publicAPI.createInstance({}); instance.mount(mountpoint, { onError: jest.fn(), onChange: 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_service/service.tsx similarity index 70% rename from x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.tsx rename to x-pack/legacy/plugins/lens/public/editor_frame_service/service.tsx index e914eb7d7784b..9a3d724705a1a 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_service/service.tsx @@ -8,8 +8,6 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; import { CoreSetup, CoreStart } from 'src/core/public'; -import chrome, { Chrome } from 'ui/chrome'; -import { npSetup, npStart } from 'ui/new_platform'; import { ExpressionsSetup, ExpressionsStart, @@ -44,24 +42,35 @@ export interface EditorFrameStartPlugins { data: DataPublicPluginStart; embeddable: IEmbeddableStart; expressions: ExpressionsStart; - chrome: Chrome; } -export class EditorFramePlugin { +async function collectAsyncDefinitions( + definitions: Array> +) { + const resolvedDefinitions = await Promise.all(definitions); + const definitionMap: Record = {}; + resolvedDefinitions.forEach(definition => { + definitionMap[definition.id] = definition; + }); + + return definitionMap; +} + +export class EditorFrameService { constructor() {} - private readonly datasources: Record = {}; - private readonly visualizations: Record = {}; + private readonly datasources: Array> = []; + private readonly visualizations: Array> = []; public setup(core: CoreSetup, plugins: EditorFrameSetupPlugins): EditorFrameSetup { plugins.expressions.registerFunction(() => mergeTables); return { registerDatasource: datasource => { - this.datasources[datasource.id] = datasource as Datasource; + this.datasources.push(datasource as Datasource); }, registerVisualization: visualization => { - this.visualizations[visualization.id] = visualization as Visualization; + this.visualizations.push(visualization as Visualization); }, }; } @@ -70,27 +79,34 @@ export class EditorFramePlugin { plugins.embeddable.registerEmbeddableFactory( 'lens', new EmbeddableFactory( - plugins.chrome, + core.http, + core.application.capabilities, + core.savedObjects.client, plugins.expressions.ReactExpressionRenderer, plugins.data.indexPatterns ) ); - const createInstance = (): EditorFrameInstance => { + const createInstance = async (): Promise => { let domElement: Element; + const [resolvedDatasources, resolvedVisualizations] = await Promise.all([ + collectAsyncDefinitions(this.datasources), + collectAsyncDefinitions(this.visualizations), + ]); + return { mount: (element, { doc, onError, dateRange, query, filters, savedQuery, onChange }) => { domElement = element; - const firstDatasourceId = Object.keys(this.datasources)[0]; - const firstVisualizationId = Object.keys(this.visualizations)[0]; + const firstDatasourceId = Object.keys(resolvedDatasources)[0]; + const firstVisualizationId = Object.keys(resolvedVisualizations)[0]; render( - editorFrame.setup(npSetup.core, { - data: npSetup.plugins.data, - embeddable: npSetup.plugins.embeddable, - expressions: npSetup.plugins.expressions, - }); - -export const editorFrameStart = () => - editorFrame.start(npStart.core, { - data: npStart.plugins.data, - embeddable: npStart.plugins.embeddable, - expressions: npStart.plugins.expressions, - chrome, - }); - -export const editorFrameStop = () => editorFrame.stop(); diff --git a/x-pack/legacy/plugins/lens/public/index.scss b/x-pack/legacy/plugins/lens/public/index.scss index f646b1ed0a9ae..496573f6a1c9a 100644 --- a/x-pack/legacy/plugins/lens/public/index.scss +++ b/x-pack/legacy/plugins/lens/public/index.scss @@ -7,9 +7,9 @@ @import './config_panel'; @import './app_plugin/index'; -@import './datatable_visualization_plugin/index'; +@import 'datatable_visualization/index'; @import './drag_drop/index'; -@import './editor_frame_plugin/index'; -@import './indexpattern_plugin/index'; -@import './xy_visualization_plugin/index'; -@import './metric_visualization_plugin/index'; +@import 'editor_frame_service/index'; +@import 'indexpattern_datasource/index'; +@import 'xy_visualization/index'; +@import 'metric_visualization/index'; diff --git a/x-pack/legacy/plugins/lens/public/index.ts b/x-pack/legacy/plugins/lens/public/index.ts index 9f4141dbcae7d..e49f648906af0 100644 --- a/x-pack/legacy/plugins/lens/public/index.ts +++ b/x-pack/legacy/plugins/lens/public/index.ts @@ -4,4 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +import { LensPlugin } from './plugin'; + export * from './types'; + +export const plugin = () => new LensPlugin(); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/__mocks__/loader.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/__mocks__/loader.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/__mocks__/loader.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/__mocks__/loader.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/__mocks__/state_helpers.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/__mocks__/state_helpers.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/__mocks__/state_helpers.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/__mocks__/state_helpers.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/__snapshots__/lens_field_icon.test.tsx.snap b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/__snapshots__/lens_field_icon.test.tsx.snap similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/__snapshots__/lens_field_icon.test.tsx.snap rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/__snapshots__/lens_field_icon.test.tsx.snap diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/_datapanel.scss b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_datapanel.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/_datapanel.scss rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/_datapanel.scss diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/_field_item.scss b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_field_item.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/_field_item.scss rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/_field_item.scss diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/_index.scss b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_index.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/_index.scss rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/_index.scss diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/auto_date.test.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/auto_date.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/auto_date.test.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/auto_date.test.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/auto_date.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/auto_date.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/auto_date.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/auto_date.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/change_indexpattern.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/change_indexpattern.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/change_indexpattern.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/change_indexpattern.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/datapanel.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/datapanel.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/datapanel.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/datapanel.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/datapanel.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/datapanel.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/_dimension_panel.scss b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/_dimension_panel.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/_dimension_panel.scss rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/_dimension_panel.scss diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/_field_select.scss b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/_field_select.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/_field_select.scss rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/_field_select.scss diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/_index.scss b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/_index.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/_index.scss rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/_index.scss diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/_popover.scss b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/_popover.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/_popover.scss rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/_popover.scss diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/bucket_nesting_editor.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/bucket_nesting_editor.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/bucket_nesting_editor.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/bucket_nesting_editor.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.tsx 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_datasource/dimension_panel/dimension_panel.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/field_select.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/field_select.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/field_select.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/field_select.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/index.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/index.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/index.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/index.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/popover_editor.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/popover_editor.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/popover_editor.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/document_field.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/document_field.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/document_field.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/document_field.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_icon.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_icon.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_icon.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_icon.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_item.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_item.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_item.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_item.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/index.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/index.ts new file mode 100644 index 0000000000000..3ca6e3e1ef56e --- /dev/null +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/index.ts @@ -0,0 +1,49 @@ +/* + * 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 { CoreSetup } from 'src/core/public'; +import { Storage } from '../../../../../../src/plugins/kibana_utils/public'; +import { getIndexPatternDatasource } from './indexpattern'; +import { renameColumns } from './rename_columns'; +import { autoDate } from './auto_date'; +import { ExpressionsSetup } from '../../../../../../src/plugins/expressions/public'; +import { + DataPublicPluginSetup, + DataPublicPluginStart, +} from '../../../../../../src/plugins/data/public'; +import { Datasource, EditorFrameSetup } from '../types'; + +export interface IndexPatternDatasourceSetupPlugins { + expressions: ExpressionsSetup; + data: DataPublicPluginSetup; + editorFrame: EditorFrameSetup; +} + +export interface IndexPatternDatasourceStartPlugins { + data: DataPublicPluginStart; +} + +export class IndexPatternDatasource { + constructor() {} + + setup( + core: CoreSetup, + { expressions, editorFrame }: IndexPatternDatasourceSetupPlugins + ) { + expressions.registerFunction(renameColumns); + expressions.registerFunction(autoDate); + + editorFrame.registerDatasource( + core.getStartServices().then(([coreStart, { data }]) => + getIndexPatternDatasource({ + core: coreStart, + storage: new Storage(localStorage), + data, + }) + ) as Promise + ); + } +} diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.test.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts similarity index 97% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.test.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts index e7def3b9dbf2c..41be22f2c72ed 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.test.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts @@ -4,9 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import chromeMock from 'ui/chrome'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; -import { SavedObjectsClientContract } from 'kibana/public'; import { getIndexPatternDatasource, IndexPatternColumn, uniqueLabels } from './indexpattern'; import { DatasourcePublicAPI, Operation, Datasource } from '../types'; import { coreMock } from 'src/core/public/mocks'; @@ -15,8 +13,6 @@ import { IndexPatternPersistedState, IndexPatternPrivateState } from './types'; jest.mock('./loader'); jest.mock('../id_generator'); -// chrome, notify, storage are used by ./plugin -jest.mock('ui/chrome'); // Contains old and new platform data plugins, used for interpreter and filter ratio jest.mock('ui/new_platform'); @@ -142,10 +138,8 @@ describe('IndexPattern Data Source', () => { beforeEach(() => { indexPatternDatasource = getIndexPatternDatasource({ - chrome: chromeMock, storage: {} as IStorageWrapper, core: coreMock.createStart(), - savedObjectsClient: {} as SavedObjectsClientContract, data: pluginsMock.createStart().data, }); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern.tsx similarity index 94% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern.tsx index 2426d7fc14b5d..afb88d1af7951 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern.tsx @@ -8,7 +8,7 @@ import _ from 'lodash'; import React from 'react'; import { render } from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; -import { CoreStart, SavedObjectsClientContract } from 'src/core/public'; +import { CoreStart } from 'src/core/public'; import { i18n } from '@kbn/i18n'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { @@ -21,7 +21,6 @@ import { import { loadInitialState, changeIndexPattern, changeLayerIndexPattern } from './loader'; import { toExpression } from './to_expression'; import { IndexPatternDimensionPanel } from './dimension_panel'; -import { IndexPatternDatasourceSetupPlugins } from './plugin'; import { IndexPatternDataPanel } from './datapanel'; import { getDatasourceSuggestionsForField, @@ -90,20 +89,16 @@ export function uniqueLabels(layers: Record) { } export function getIndexPatternDatasource({ - chrome, core, storage, - savedObjectsClient, data, -}: Pick & { - // Core start is being required here because it contains the savedObject client - // In the new platform, this plugin wouldn't be initialized until after setup +}: { core: CoreStart; storage: IStorageWrapper; - savedObjectsClient: SavedObjectsClientContract; data: ReturnType; }) { - const uiSettings = chrome.getUiSettingsClient(); + const savedObjectsClient = core.savedObjects.client; + const uiSettings = core.uiSettings; const onIndexPatternLoadError = (err: Error) => core.notifications.toasts.addError(err, { title: i18n.translate('xpack.lens.indexPattern.indexPatternLoadError', { @@ -118,7 +113,7 @@ export function getIndexPatternDatasource({ async initialize(state?: IndexPatternPersistedState) { return loadInitialState({ state, - savedObjectsClient, + savedObjectsClient: await savedObjectsClient, defaultIndexPatternId: core.uiSettings.get('defaultIndex'), }); }, diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern_suggestions.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern_suggestions.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern_suggestions.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/indexpattern_suggestions.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/layerpanel.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/layerpanel.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/layerpanel.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/layerpanel.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/layerpanel.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/layerpanel.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/lens_field_icon.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/lens_field_icon.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/lens_field_icon.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/lens_field_icon.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.test.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/loader.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.test.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/loader.test.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/loader.ts similarity index 99% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/loader.ts index 3ec4b4f4df2ce..ed3d8a91b366d 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/loader.ts @@ -5,7 +5,6 @@ */ import _ from 'lodash'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths import { SavedObjectsClientContract, SavedObjectAttributes, HttpSetup } from 'src/core/public'; import { SimpleSavedObject } from 'src/core/public'; import { StateSetter } from '../types'; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/mocks.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/mocks.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/mocks.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/mocks.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/__mocks__/index.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/__mocks__/index.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/__mocks__/index.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/__mocks__/index.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/cardinality.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/cardinality.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/column_types.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/column_types.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/column_types.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/column_types.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/count.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/count.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx 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_datasource/operations/definitions/date_histogram.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/index.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/index.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/metrics.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/metrics.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/terms.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/terms.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/terms.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.tsx rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/definitions/terms.tsx diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/index.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/index.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/index.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/index.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/operations.test.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/operations.test.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/operations.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/operations.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/operations.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/operations/operations.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/pure_helpers.test.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/pure_helpers.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/pure_helpers.test.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/pure_helpers.test.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/pure_helpers.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/pure_helpers.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/pure_helpers.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/pure_helpers.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/rename_columns.test.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/rename_columns.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/rename_columns.test.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/rename_columns.test.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/rename_columns.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/rename_columns.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/rename_columns.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/rename_columns.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/state_helpers.test.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/state_helpers.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/state_helpers.test.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/state_helpers.test.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/state_helpers.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/state_helpers.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/state_helpers.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/state_helpers.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/to_expression.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/to_expression.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/to_expression.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/to_expression.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/types.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/types.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/types.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/types.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/utils.ts b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/utils.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/indexpattern_plugin/utils.ts rename to x-pack/legacy/plugins/lens/public/indexpattern_datasource/utils.ts diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/plugin.tsx deleted file mode 100644 index 11bc52fc48378..0000000000000 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/plugin.tsx +++ /dev/null @@ -1,53 +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 { CoreSetup } from 'src/core/public'; -// The following dependencies on ui/* and src/legacy/core_plugins must be mocked when testing -import chrome, { Chrome } from 'ui/chrome'; -import { npSetup, npStart } from 'ui/new_platform'; -import { Storage } from '../../../../../../src/plugins/kibana_utils/public'; -import { getIndexPatternDatasource } from './indexpattern'; -import { renameColumns } from './rename_columns'; -import { autoDate } from './auto_date'; -import { ExpressionsSetup } from '../../../../../../src/plugins/expressions/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 - -export interface IndexPatternDatasourceSetupPlugins { - chrome: Chrome; - expressions: ExpressionsSetup; -} - -class IndexPatternDatasourcePlugin { - constructor() {} - - setup(core: CoreSetup, { expressions }: IndexPatternDatasourceSetupPlugins) { - expressions.registerFunction(renameColumns); - expressions.registerFunction(autoDate); - } - - stop() {} -} - -const plugin = new IndexPatternDatasourcePlugin(); - -export const indexPatternDatasourceSetup = () => { - plugin.setup(npSetup.core, { - chrome, - expressions: npSetup.plugins.expressions, - }); - - return getIndexPatternDatasource({ - core: npStart.core, - chrome, - storage: new Storage(localStorage), - savedObjectsClient: chrome.getSavedObjectsClient(), - data: npStart.plugins.data, - }); -}; -export const indexPatternDatasourceStop = () => plugin.stop(); diff --git a/x-pack/legacy/plugins/lens/public/legacy.ts b/x-pack/legacy/plugins/lens/public/legacy.ts index a39d73f187ece..8023bad34de66 100644 --- a/x-pack/legacy/plugins/lens/public/legacy.ts +++ b/x-pack/legacy/plugins/lens/public/legacy.ts @@ -5,15 +5,12 @@ */ import { npSetup, npStart } from 'ui/new_platform'; -import { start as dataShimStart } from '../../../../../src/legacy/core_plugins/data/public/legacy'; +import { getFormat } from './legacy_imports'; export * from './types'; -import { AppPlugin } from './app_plugin'; +import { plugin } from './index'; -const app = new AppPlugin(); -app.setup(npSetup.core, npSetup.plugins); -app.start(npStart.core, { - ...npStart.plugins, - dataShim: dataShimStart, -}); +const pluginInstance = plugin(); +pluginInstance.setup(npSetup.core, { ...npSetup.plugins, __LEGACY: { formatFactory: getFormat } }); +pluginInstance.start(npStart.core, npStart.plugins); diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/index.ts b/x-pack/legacy/plugins/lens/public/legacy_imports.ts similarity index 72% rename from x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/index.ts rename to x-pack/legacy/plugins/lens/public/legacy_imports.ts index f75dce9b7507f..9dcc22ddb1bb7 100644 --- a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/index.ts +++ b/x-pack/legacy/plugins/lens/public/legacy_imports.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export * from './plugin'; +export { getFormat, FormatFactory } from 'ui/visualize/loader/pipeline_helpers/utilities'; diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/auto_scale.test.tsx b/x-pack/legacy/plugins/lens/public/metric_visualization/auto_scale.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/auto_scale.test.tsx rename to x-pack/legacy/plugins/lens/public/metric_visualization/auto_scale.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/auto_scale.tsx b/x-pack/legacy/plugins/lens/public/metric_visualization/auto_scale.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/auto_scale.tsx rename to x-pack/legacy/plugins/lens/public/metric_visualization/auto_scale.tsx diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/index.scss b/x-pack/legacy/plugins/lens/public/metric_visualization/index.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/index.scss rename to x-pack/legacy/plugins/lens/public/metric_visualization/index.scss diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization/index.ts b/x-pack/legacy/plugins/lens/public/metric_visualization/index.ts new file mode 100644 index 0000000000000..217cc6902fc99 --- /dev/null +++ b/x-pack/legacy/plugins/lens/public/metric_visualization/index.ts @@ -0,0 +1,33 @@ +/* + * 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 { CoreSetup } from 'src/core/public'; +import { FormatFactory } from '../legacy_imports'; +import { metricVisualization } from './metric_visualization'; +import { ExpressionsSetup } from '../../../../../../src/plugins/expressions/public'; +import { metricChart, getMetricChartRenderer } from './metric_expression'; +import { EditorFrameSetup } from '../types'; + +export interface MetricVisualizationPluginSetupPlugins { + expressions: ExpressionsSetup; + formatFactory: FormatFactory; + editorFrame: EditorFrameSetup; +} + +export class MetricVisualization { + constructor() {} + + setup( + _core: CoreSetup | null, + { expressions, formatFactory, editorFrame }: MetricVisualizationPluginSetupPlugins + ) { + expressions.registerFunction(() => metricChart); + + expressions.registerRenderer(() => getMetricChartRenderer(formatFactory)); + + editorFrame.registerVisualization(metricVisualization); + } +} diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_config_panel.test.tsx b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_config_panel.test.tsx similarity index 98% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_config_panel.test.tsx rename to x-pack/legacy/plugins/lens/public/metric_visualization/metric_config_panel.test.tsx index a66239e5d30f6..eac35f82a50fa 100644 --- a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_config_panel.test.tsx +++ b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_config_panel.test.tsx @@ -11,7 +11,7 @@ import { MetricConfigPanel } from './metric_config_panel'; import { DatasourceDimensionPanelProps, Operation, DatasourcePublicAPI } from '../types'; import { State } from './types'; import { NativeRendererProps } from '../native_renderer'; -import { createMockFramePublicAPI, createMockDatasource } from '../editor_frame_plugin/mocks'; +import { createMockFramePublicAPI, createMockDatasource } from '../editor_frame_service/mocks'; describe('MetricConfigPanel', () => { const dragDropContext = { dragging: undefined, setDragging: jest.fn() }; diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_config_panel.tsx b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_config_panel.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_config_panel.tsx rename to x-pack/legacy/plugins/lens/public/metric_visualization/metric_config_panel.tsx diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_expression.test.tsx b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_expression.test.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_expression.test.tsx rename to x-pack/legacy/plugins/lens/public/metric_visualization/metric_expression.test.tsx diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_expression.tsx b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_expression.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_expression.tsx rename to x-pack/legacy/plugins/lens/public/metric_visualization/metric_expression.tsx diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_suggestions.test.ts b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_suggestions.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_suggestions.test.ts rename to x-pack/legacy/plugins/lens/public/metric_visualization/metric_suggestions.test.ts diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_suggestions.ts b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_suggestions.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_suggestions.ts rename to x-pack/legacy/plugins/lens/public/metric_visualization/metric_suggestions.ts diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_visualization.test.ts b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_visualization.test.ts similarity index 99% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_visualization.test.ts rename to x-pack/legacy/plugins/lens/public/metric_visualization/metric_visualization.test.ts index c131612399cca..88964b95c2ac7 100644 --- a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_visualization.test.ts +++ b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_visualization.test.ts @@ -6,7 +6,7 @@ import { metricVisualization } from './metric_visualization'; import { State } from './types'; -import { createMockDatasource, createMockFramePublicAPI } from '../editor_frame_plugin/mocks'; +import { createMockDatasource, createMockFramePublicAPI } from '../editor_frame_service/mocks'; import { generateId } from '../id_generator'; import { DatasourcePublicAPI, FramePublicAPI } from '../types'; diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_visualization.tsx b/x-pack/legacy/plugins/lens/public/metric_visualization/metric_visualization.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/metric_visualization.tsx rename to x-pack/legacy/plugins/lens/public/metric_visualization/metric_visualization.tsx diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/types.ts b/x-pack/legacy/plugins/lens/public/metric_visualization/types.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/metric_visualization_plugin/types.ts rename to x-pack/legacy/plugins/lens/public/metric_visualization/types.ts diff --git a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/index.ts b/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/index.ts deleted file mode 100644 index f75dce9b7507f..0000000000000 --- a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/index.ts +++ /dev/null @@ -1,7 +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. - */ - -export * from './plugin'; 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 deleted file mode 100644 index 219ef533a4ba3..0000000000000 --- a/x-pack/legacy/plugins/lens/public/metric_visualization_plugin/plugin.tsx +++ /dev/null @@ -1,50 +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 { npSetup } from 'ui/new_platform'; -import { CoreSetup } from 'src/core/public'; -import { FormatFactory, getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities'; -import { metricVisualization } from './metric_visualization'; -import { ExpressionsSetup } from '../../../../../../src/plugins/expressions/public'; -import { metricChart, getMetricChartRenderer } from './metric_expression'; - -export interface MetricVisualizationPluginSetupPlugins { - expressions: ExpressionsSetup; - // TODO this is a simulated NP plugin. - // Once field formatters are actually migrated, the actual shim can be used - fieldFormat: { - formatFactory: FormatFactory; - }; -} - -class MetricVisualizationPlugin { - constructor() {} - - setup( - _core: CoreSetup | null, - { expressions, fieldFormat }: MetricVisualizationPluginSetupPlugins - ) { - expressions.registerFunction(() => metricChart); - - expressions.registerRenderer(() => getMetricChartRenderer(fieldFormat.formatFactory)); - - return metricVisualization; - } - - stop() {} -} - -const plugin = new MetricVisualizationPlugin(); - -export const metricVisualizationSetup = () => - plugin.setup(null, { - expressions: npSetup.plugins.expressions, - fieldFormat: { - formatFactory: getFormat, - }, - }); - -export const metricVisualizationStop = () => plugin.stop(); diff --git a/x-pack/legacy/plugins/lens/public/multi_column_editor/multi_column_editor.test.tsx b/x-pack/legacy/plugins/lens/public/multi_column_editor/multi_column_editor.test.tsx index 012c27d3ce3ff..38f48c9cdaf72 100644 --- a/x-pack/legacy/plugins/lens/public/multi_column_editor/multi_column_editor.test.tsx +++ b/x-pack/legacy/plugins/lens/public/multi_column_editor/multi_column_editor.test.tsx @@ -5,7 +5,7 @@ */ import React from 'react'; -import { createMockDatasource } from '../editor_frame_plugin/mocks'; +import { createMockDatasource } from '../editor_frame_service/mocks'; import { MultiColumnEditor } from './multi_column_editor'; import { mount } from 'enzyme'; diff --git a/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/plugin.tsx similarity index 55% rename from x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx rename to x-pack/legacy/plugins/lens/public/plugin.tsx index 283f4d2a0689d..634d227559835 100644 --- a/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/plugin.tsx @@ -4,97 +4,112 @@ * you may not use this file except in compliance with the Elastic License. */ -import 'ui/autoload/all'; -// Used to run esaggs queries -import 'uiExports/fieldFormats'; -import 'uiExports/search'; -import 'uiExports/visRequestHandlers'; -import 'uiExports/visResponseHandlers'; -// Used for kibana_context function -import 'uiExports/savedObjectTypes'; - import React from 'react'; import { FormattedMessage, I18nProvider } from '@kbn/i18n/react'; import { HashRouter, Route, RouteComponentProps, Switch } from 'react-router-dom'; import { render, unmountComponentAtNode } from 'react-dom'; -import { CoreSetup, CoreStart, SavedObjectsClientContract } from 'src/core/public'; -import { DataPublicPluginStart } from 'src/plugins/data/public'; +import { AppMountParameters, CoreSetup, CoreStart } from 'src/core/public'; +import { DataPublicPluginSetup, DataPublicPluginStart } from 'src/plugins/data/public'; import rison, { RisonObject, RisonValue } from 'rison-node'; import { isObject } from 'lodash'; -import { DataStart } from '../../../../../../src/legacy/core_plugins/data/public'; -import { Storage } from '../../../../../../src/plugins/kibana_utils/public'; -import { editorFrameSetup, editorFrameStart, editorFrameStop } from '../editor_frame_plugin'; -import { indexPatternDatasourceSetup, indexPatternDatasourceStop } from '../indexpattern_plugin'; -import { addHelpMenuToAppChrome } from '../help_menu_util'; -import { SavedObjectIndexStore } from '../persistence'; -import { xyVisualizationSetup, xyVisualizationStop } from '../xy_visualization_plugin'; -import { metricVisualizationSetup, metricVisualizationStop } from '../metric_visualization_plugin'; -import { - datatableVisualizationSetup, - datatableVisualizationStop, -} from '../datatable_visualization_plugin'; -import { App } from './app'; +import { Storage } from '../../../../../src/plugins/kibana_utils/public'; +import { EditorFrameService } from './editor_frame_service'; +import { IndexPatternDatasource } from './indexpattern_datasource'; +import { addHelpMenuToAppChrome } from './help_menu_util'; +import { SavedObjectIndexStore } from './persistence'; +import { XyVisualization } from './xy_visualization'; +import { MetricVisualization } from './metric_visualization'; +import { ExpressionsSetup, ExpressionsStart } from '../../../../../src/plugins/expressions/public'; +import { DatatableVisualization } from './datatable_visualization'; +import { App } from './app_plugin'; import { LensReportManager, setReportManager, stopReportManager, trackUiEvent, -} from '../lens_ui_telemetry'; -import { NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../../../../../plugins/lens/common'; -import { KibanaLegacySetup } from '../../../../../../src/plugins/kibana_legacy/public'; -import { EditorFrameStart } from '../types'; +} from './lens_ui_telemetry'; +import { KibanaLegacySetup } from '../../../../../src/plugins/kibana_legacy/public'; +import { NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../../../../plugins/lens/common'; import { addEmbeddableToDashboardUrl, getUrlVars, getLensUrlFromDashboardAbsoluteUrl, -} from '../../../../../../src/legacy/core_plugins/kibana/public/dashboard/np_ready/url_helper'; +} from '../../../../../src/legacy/core_plugins/kibana/public/dashboard/np_ready/url_helper'; +import { FormatFactory } from './legacy_imports'; +import { IEmbeddableSetup, IEmbeddableStart } from '../../../../../src/plugins/embeddable/public'; +import { EditorFrameStart } from './types'; export interface LensPluginSetupDependencies { kibanaLegacy: KibanaLegacySetup; + expressions: ExpressionsSetup; + data: DataPublicPluginSetup; + embeddable: IEmbeddableSetup; + __LEGACY: { + formatFactory: FormatFactory; + }; } export interface LensPluginStartDependencies { data: DataPublicPluginStart; - dataShim: DataStart; + embeddable: IEmbeddableStart; + expressions: ExpressionsStart; } export const isRisonObject = (value: RisonValue): value is RisonObject => { return isObject(value); }; -export class AppPlugin { - private startDependencies: { - data: DataPublicPluginStart; - dataShim: DataStart; - savedObjectsClient: SavedObjectsClientContract; - editorFrame: EditorFrameStart; - } | null = null; - - constructor() {} - - setup(core: CoreSetup, { kibanaLegacy }: LensPluginSetupDependencies) { - // TODO: These plugins should not be called from the top level, but since this is the - // entry point to the app we have no choice until the new platform is ready - const indexPattern = indexPatternDatasourceSetup(); - const datatableVisualization = datatableVisualizationSetup(); - const xyVisualization = xyVisualizationSetup(); - const metricVisualization = metricVisualizationSetup(); - const editorFrameSetupInterface = editorFrameSetup(); +export class LensPlugin { + private datatableVisualization: DatatableVisualization; + private editorFrameService: EditorFrameService; + private createEditorFrame: EditorFrameStart['createInstance'] | null = null; + private indexpatternDatasource: IndexPatternDatasource; + private xyVisualization: XyVisualization; + private metricVisualization: MetricVisualization; + + constructor() { + this.datatableVisualization = new DatatableVisualization(); + this.editorFrameService = new EditorFrameService(); + this.indexpatternDatasource = new IndexPatternDatasource(); + this.xyVisualization = new XyVisualization(); + this.metricVisualization = new MetricVisualization(); + } - editorFrameSetupInterface.registerVisualization(xyVisualization); - editorFrameSetupInterface.registerVisualization(datatableVisualization); - editorFrameSetupInterface.registerVisualization(metricVisualization); - editorFrameSetupInterface.registerDatasource(indexPattern); + setup( + core: CoreSetup, + { + kibanaLegacy, + expressions, + data, + embeddable, + __LEGACY: { formatFactory }, + }: LensPluginSetupDependencies + ) { + const editorFrameSetupInterface = this.editorFrameService.setup(core, { + data, + embeddable, + expressions, + }); + const dependencies = { + expressions, + data, + editorFrame: editorFrameSetupInterface, + formatFactory, + }; + this.indexpatternDatasource.setup(core, dependencies); + this.xyVisualization.setup(core, dependencies); + this.datatableVisualization.setup(core, dependencies); + this.metricVisualization.setup(core, dependencies); kibanaLegacy.registerLegacyApp({ id: 'lens', title: NOT_INTERNATIONALIZED_PRODUCT_NAME, - mount: async (context, params) => { - if (this.startDependencies === null) { - throw new Error('mounted before start phase'); - } - const { data, savedObjectsClient, editorFrame } = this.startDependencies; - addHelpMenuToAppChrome(context.core.chrome); - const instance = editorFrame.createInstance({}); + mount: async (params: AppMountParameters) => { + const [coreStart, startDependencies] = await core.getStartServices(); + const dataStart = startDependencies.data; + const savedObjectsClient = coreStart.savedObjects.client; + addHelpMenuToAppChrome(coreStart.chrome); + + const instance = await this.createEditorFrame!({}); setReportManager( new LensReportManager({ @@ -108,7 +123,7 @@ export class AppPlugin { return; } // @ts-ignore - decoded.time = data.query.timefilter.timefilter.getTime(); + decoded.time = dataStart.query.timefilter.timefilter.getTime(); urlVars._g = rison.encode(decoded); }; const redirectTo = ( @@ -122,12 +137,12 @@ export class AppPlugin { routeProps.history.push(`/lens/edit/${id}`); } else if (addToDashboardMode && id) { routeProps.history.push(`/lens/edit/${id}`); - const url = context.core.chrome.navLinks.get('kibana:dashboard'); + const url = coreStart.chrome.navLinks.get('kibana:dashboard'); if (!url) { throw new Error('Cannot get last dashboard url'); } const lastDashboardAbsoluteUrl = url.url; - const basePath = context.core.http.basePath.get(); + const basePath = coreStart.http.basePath.get(); const lensUrl = getLensUrlFromDashboardAbsoluteUrl( lastDashboardAbsoluteUrl, basePath, @@ -158,8 +173,8 @@ export class AppPlugin { !!routeProps.location.search && routeProps.location.search.includes('addToDashboard'); return ( (datasource: Datasource) => void; - registerVisualization: (visualization: Visualization) => void; + registerDatasource: (datasource: Datasource | Promise>) => void; + registerVisualization: ( + visualization: Visualization | Promise> + ) => void; } export interface EditorFrameStart { - createInstance: (options: EditorFrameOptions) => EditorFrameInstance; + createInstance: (options: EditorFrameOptions) => Promise; } // Hints the default nesting to the data source. 0 is the highest priority diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization/__snapshots__/xy_expression.test.tsx.snap b/x-pack/legacy/plugins/lens/public/xy_visualization/__snapshots__/xy_expression.test.tsx.snap new file mode 100644 index 0000000000000..fd0c4b8212fc6 --- /dev/null +++ b/x-pack/legacy/plugins/lens/public/xy_visualization/__snapshots__/xy_expression.test.tsx.snap @@ -0,0 +1,482 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`xy_expression XYChart component it renders area 1`] = ` + + + + + + +`; + +exports[`xy_expression XYChart component it renders bar 1`] = ` + + + + + + +`; + +exports[`xy_expression XYChart component it renders horizontal bar 1`] = ` + + + + + + +`; + +exports[`xy_expression XYChart component it renders line 1`] = ` + + + + + + +`; + +exports[`xy_expression XYChart component it renders stacked area 1`] = ` + + + + + + +`; + +exports[`xy_expression XYChart component it renders stacked bar 1`] = ` + + + + + + +`; + +exports[`xy_expression XYChart component it renders stacked horizontal bar 1`] = ` + + + + + + +`; diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/__snapshots__/xy_visualization.test.ts.snap b/x-pack/legacy/plugins/lens/public/xy_visualization/__snapshots__/xy_visualization.test.ts.snap similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/__snapshots__/xy_visualization.test.ts.snap rename to x-pack/legacy/plugins/lens/public/xy_visualization/__snapshots__/xy_visualization.test.ts.snap diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/_index.scss b/x-pack/legacy/plugins/lens/public/xy_visualization/_index.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/_index.scss rename to x-pack/legacy/plugins/lens/public/xy_visualization/_index.scss diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/_xy_expression.scss b/x-pack/legacy/plugins/lens/public/xy_visualization/_xy_expression.scss similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/_xy_expression.scss rename to x-pack/legacy/plugins/lens/public/xy_visualization/_xy_expression.scss diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/xy_visualization/index.ts similarity index 57% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx rename to x-pack/legacy/plugins/lens/public/xy_visualization/index.ts index 6feece99370ef..86c52e0577616 100644 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/xy_visualization/index.ts @@ -4,24 +4,20 @@ * you may not use this file except in compliance with the Elastic License. */ -import { npSetup } from 'ui/new_platform'; +import { EUI_CHARTS_THEME_DARK, EUI_CHARTS_THEME_LIGHT } from '@elastic/eui/dist/eui_charts_theme'; import { CoreSetup, IUiSettingsClient } 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 { FormatFactory } from '../legacy_imports'; import { ExpressionsSetup } from '../../../../../../src/plugins/expressions/public'; import { xyVisualization } from './xy_visualization'; import { xyChart, getXyChartRenderer } from './xy_expression'; import { legendConfig, xConfig, layerConfig } from './types'; +import { EditorFrameSetup } from '../types'; export interface XyVisualizationPluginSetupPlugins { expressions: ExpressionsSetup; - chrome: Chrome; - // TODO this is a simulated NP plugin. - // Once field formatters are actually migrated, the actual shim can be used - fieldFormat: { - formatFactory: FormatFactory; - }; + formatFactory: FormatFactory; + editorFrame: EditorFrameSetup; } function getTimeZone(uiSettings: IUiSettingsClient) { @@ -33,16 +29,12 @@ function getTimeZone(uiSettings: IUiSettingsClient) { return configuredTimeZone; } -class XyVisualizationPlugin { +export class XyVisualization { constructor() {} setup( - _core: CoreSetup | null, - { - expressions, - fieldFormat: { formatFactory }, - chrome: { getUiSettingsClient }, - }: XyVisualizationPluginSetupPlugins + core: CoreSetup, + { expressions, formatFactory, editorFrame }: XyVisualizationPluginSetupPlugins ) { expressions.registerFunction(() => legendConfig); expressions.registerFunction(() => xConfig); @@ -52,24 +44,13 @@ class XyVisualizationPlugin { expressions.registerRenderer( getXyChartRenderer({ formatFactory, - timeZone: getTimeZone(getUiSettingsClient()), + chartTheme: core.uiSettings.get('theme:darkMode') + ? EUI_CHARTS_THEME_DARK.theme + : EUI_CHARTS_THEME_LIGHT.theme, + timeZone: getTimeZone(core.uiSettings), }) ); - return xyVisualization; + editorFrame.registerVisualization(xyVisualization); } - - stop() {} } - -const plugin = new XyVisualizationPlugin(); - -export const xyVisualizationSetup = () => - plugin.setup(null, { - expressions: npSetup.plugins.expressions, - fieldFormat: { - formatFactory: getFormat, - }, - chrome, - }); -export const xyVisualizationStop = () => plugin.stop(); diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/state_helpers.ts b/x-pack/legacy/plugins/lens/public/xy_visualization/state_helpers.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/state_helpers.ts rename to x-pack/legacy/plugins/lens/public/xy_visualization/state_helpers.ts diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/to_expression.ts b/x-pack/legacy/plugins/lens/public/xy_visualization/to_expression.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/to_expression.ts rename to x-pack/legacy/plugins/lens/public/xy_visualization/to_expression.ts diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/types.ts b/x-pack/legacy/plugins/lens/public/xy_visualization/types.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/types.ts rename to x-pack/legacy/plugins/lens/public/xy_visualization/types.ts diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_config_panel.test.tsx b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_config_panel.test.tsx similarity index 99% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_config_panel.test.tsx rename to x-pack/legacy/plugins/lens/public/xy_visualization/xy_config_panel.test.tsx index 6ed827bc71c68..301c4a58a0ffd 100644 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_config_panel.test.tsx +++ b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_config_panel.test.tsx @@ -14,7 +14,7 @@ import { State } from './types'; import { Position } from '@elastic/charts'; import { NativeRendererProps } from '../native_renderer'; import { generateId } from '../id_generator'; -import { createMockFramePublicAPI, createMockDatasource } from '../editor_frame_plugin/mocks'; +import { createMockFramePublicAPI, createMockDatasource } from '../editor_frame_service/mocks'; jest.mock('../id_generator'); diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_config_panel.tsx b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_config_panel.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_config_panel.tsx rename to x-pack/legacy/plugins/lens/public/xy_visualization/xy_config_panel.tsx diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.test.tsx b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_expression.test.tsx similarity index 93% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.test.tsx rename to x-pack/legacy/plugins/lens/public/xy_visualization/xy_expression.test.tsx index daedb30db3f3e..04e0b80faa200 100644 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.test.tsx +++ b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_expression.test.tsx @@ -132,6 +132,7 @@ describe('xy_expression', () => { args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'line' }] }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component).toMatchSnapshot(); @@ -156,6 +157,7 @@ describe('xy_expression', () => { }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component.find(Settings).prop('xDomain')).toMatchInlineSnapshot(` @@ -184,6 +186,7 @@ describe('xy_expression', () => { }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component.find(Settings).prop('xDomain')).toBeUndefined(); @@ -197,6 +200,7 @@ describe('xy_expression', () => { args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'bar' }] }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component).toMatchSnapshot(); @@ -211,6 +215,7 @@ describe('xy_expression', () => { args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'area' }] }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component).toMatchSnapshot(); @@ -225,6 +230,7 @@ describe('xy_expression', () => { args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'bar_horizontal' }] }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component).toMatchSnapshot(); @@ -240,6 +246,7 @@ describe('xy_expression', () => { args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'bar_stacked' }] }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component).toMatchSnapshot(); @@ -255,6 +262,7 @@ describe('xy_expression', () => { args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'area_stacked' }] }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component).toMatchSnapshot(); @@ -273,6 +281,7 @@ describe('xy_expression', () => { }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component).toMatchSnapshot(); @@ -284,7 +293,13 @@ describe('xy_expression', () => { test('it passes time zone to the series', () => { const { data, args } = sampleArgs(); const component = shallow( - + ); expect(component.find(LineSeries).prop('timeZone')).toEqual('CEST'); }); @@ -299,6 +314,7 @@ describe('xy_expression', () => { args={{ ...args, layers: [firstLayer] }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component.find(BarSeries).prop('enableHistogramMode')).toEqual(true); @@ -321,6 +337,7 @@ describe('xy_expression', () => { }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component.find(BarSeries).prop('enableHistogramMode')).toEqual(true); @@ -337,6 +354,7 @@ describe('xy_expression', () => { }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component.find(BarSeries).prop('enableHistogramMode')).toEqual(false); @@ -346,7 +364,13 @@ describe('xy_expression', () => { const { data, args } = sampleArgs(); const component = shallow( - + ); expect(component.find(LineSeries).prop('data')).toEqual([ { 'Label A': 1, 'Label B': 2, c: 'I', 'Label D': 'Foo', d: 'Foo' }, @@ -358,7 +382,13 @@ describe('xy_expression', () => { const { data, args } = sampleArgs(); const component = shallow( - + ); expect(component.find(LineSeries).prop('yAccessors')).toEqual(['Label A', 'Label B']); }); @@ -372,6 +402,7 @@ describe('xy_expression', () => { args={{ ...args, layers: [{ ...args.layers[0], xScaleType: 'ordinal' }] }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component.find(LineSeries).prop('xScaleType')).toEqual(ScaleType.Ordinal); @@ -386,6 +417,7 @@ describe('xy_expression', () => { args={{ ...args, layers: [{ ...args.layers[0], yScaleType: 'sqrt' }] }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); expect(component.find(LineSeries).prop('yScaleType')).toEqual(ScaleType.Sqrt); @@ -400,6 +432,7 @@ describe('xy_expression', () => { args={{ ...args }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); @@ -415,6 +448,7 @@ describe('xy_expression', () => { args={{ ...args }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); @@ -429,6 +463,7 @@ describe('xy_expression', () => { data={{ ...data }} args={{ ...args, layers: [{ ...args.layers[0], accessors: ['a'] }] }} formatFactory={getFormatSpy} + chartTheme={{}} timeZone="UTC" /> ); @@ -447,6 +482,7 @@ describe('xy_expression', () => { args={{ ...args }} formatFactory={getFormatSpy} timeZone="UTC" + chartTheme={{}} /> ); diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.tsx b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_expression.tsx similarity index 94% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.tsx rename to x-pack/legacy/plugins/lens/public/xy_visualization/xy_expression.tsx index c62a8288d6655..27fd6e7064042 100644 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_expression.tsx +++ b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_expression.tsx @@ -6,7 +6,6 @@ import React, { useState, useEffect } from 'react'; import ReactDOM from 'react-dom'; -import chrome from 'ui/chrome'; import { Chart, Settings, @@ -15,6 +14,7 @@ import { AreaSeries, BarSeries, Position, + PartialTheme, } from '@elastic/charts'; import { I18nProvider } from '@kbn/i18n/react'; import { @@ -27,16 +27,12 @@ import { import { EuiIcon, EuiText, IconType, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { EUI_CHARTS_THEME_DARK, EUI_CHARTS_THEME_LIGHT } from '@elastic/eui/dist/eui_charts_theme'; -import { FormatFactory } from '../../../../../../src/legacy/ui/public/visualize/loader/pipeline_helpers/utilities'; +import { FormatFactory } from '../legacy_imports'; import { LensMultiTable } from '../types'; import { XYArgs, SeriesType, visualizationTypes } from './types'; import { VisualizationContainer } from '../visualization_container'; import { isHorizontalChart } from './state_helpers'; -const IS_DARK_THEME = chrome.getUiSettingsClient().get('theme:darkMode'); -const chartTheme = IS_DARK_THEME ? EUI_CHARTS_THEME_DARK.theme : EUI_CHARTS_THEME_LIGHT.theme; - export interface XYChartProps { data: LensMultiTable; args: XYArgs; @@ -49,6 +45,7 @@ export interface XYRender { } type XYChartRenderProps = XYChartProps & { + chartTheme: PartialTheme; formatFactory: FormatFactory; timeZone: string; }; @@ -101,6 +98,7 @@ export const xyChart: ExpressionFunctionDefinition< export const getXyChartRenderer = (dependencies: { formatFactory: FormatFactory; + chartTheme: PartialTheme; timeZone: string; }): ExpressionRenderDefinition => ({ name: 'lens_xy_chart_renderer', @@ -146,7 +144,7 @@ export function XYChartReportable(props: XYChartRenderProps) { ); } -export function XYChart({ data, args, formatFactory, timeZone }: XYChartRenderProps) { +export function XYChart({ data, args, formatFactory, timeZone, chartTheme }: XYChartRenderProps) { const { legend, layers } = args; if (Object.values(data.tables).every(table => table.rows.length === 0)) { diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_suggestions.test.ts b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_suggestions.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_suggestions.test.ts rename to x-pack/legacy/plugins/lens/public/xy_visualization/xy_suggestions.test.ts diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_suggestions.ts b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_suggestions.ts similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_suggestions.ts rename to x-pack/legacy/plugins/lens/public/xy_visualization/xy_suggestions.ts diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_visualization.test.ts b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_visualization.test.ts similarity index 99% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_visualization.test.ts rename to x-pack/legacy/plugins/lens/public/xy_visualization/xy_visualization.test.ts index 89794ec74eaec..a27a8e7754b86 100644 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_visualization.test.ts +++ b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_visualization.test.ts @@ -8,7 +8,7 @@ import { xyVisualization } from './xy_visualization'; import { Position } from '@elastic/charts'; import { Operation } from '../types'; import { State, SeriesType } from './types'; -import { createMockDatasource, createMockFramePublicAPI } from '../editor_frame_plugin/mocks'; +import { createMockDatasource, createMockFramePublicAPI } from '../editor_frame_service/mocks'; import { generateId } from '../id_generator'; import { Ast } from '@kbn/interpreter/target/common'; diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_visualization.tsx b/x-pack/legacy/plugins/lens/public/xy_visualization/xy_visualization.tsx similarity index 100% rename from x-pack/legacy/plugins/lens/public/xy_visualization_plugin/xy_visualization.tsx rename to x-pack/legacy/plugins/lens/public/xy_visualization/xy_visualization.tsx diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/__snapshots__/xy_expression.test.tsx.snap b/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/__snapshots__/xy_expression.test.tsx.snap deleted file mode 100644 index 495d7a7bcd77e..0000000000000 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/__snapshots__/xy_expression.test.tsx.snap +++ /dev/null @@ -1,1315 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`xy_expression XYChart component it renders area 1`] = ` - - - - - - -`; - -exports[`xy_expression XYChart component it renders bar 1`] = ` - - - - - - -`; - -exports[`xy_expression XYChart component it renders horizontal bar 1`] = ` - - - - - - -`; - -exports[`xy_expression XYChart component it renders line 1`] = ` - - - - - - -`; - -exports[`xy_expression XYChart component it renders stacked area 1`] = ` - - - - - - -`; - -exports[`xy_expression XYChart component it renders stacked bar 1`] = ` - - - - - - -`; - -exports[`xy_expression XYChart component it renders stacked horizontal bar 1`] = ` - - - - - - -`; diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/index.ts b/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/index.ts deleted file mode 100644 index f75dce9b7507f..0000000000000 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/index.ts +++ /dev/null @@ -1,7 +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. - */ - -export * from './plugin';