diff --git a/x-pack/plugins/lens/public/app_plugin/mounter.tsx b/x-pack/plugins/lens/public/app_plugin/mounter.tsx index 1ac8833f0f519..d30af62f3eabd 100644 --- a/x-pack/plugins/lens/public/app_plugin/mounter.tsx +++ b/x-pack/plugins/lens/public/app_plugin/mounter.tsx @@ -45,7 +45,7 @@ import { getPreloadedState } from '../state_management/lens_slice'; export async function getLensServices( coreStart: CoreStart, startDependencies: LensPluginStartDependencies, - attributeService: () => Promise + attributeService: LensAttributeService ): Promise { const { data, @@ -70,7 +70,7 @@ export async function getLensServices( stateTransfer, usageCollection, savedObjectsTagging, - attributeService: await attributeService(), + attributeService, http: coreStart.http, chrome: coreStart.chrome, overlays: coreStart.overlays, @@ -95,8 +95,8 @@ export async function mountApp( params: AppMountParameters, mountProps: { createEditorFrame: EditorFrameStart['createInstance']; - attributeService: () => Promise; - getPresentationUtilContext: () => Promise; + attributeService: LensAttributeService; + getPresentationUtilContext: () => FC; } ) { const { createEditorFrame, attributeService, getPresentationUtilContext } = mountProps; @@ -248,7 +248,7 @@ export async function mountApp( params.element.classList.add('lnsAppWrapper'); - const PresentationUtilContext = await getPresentationUtilContext(); + const PresentationUtilContext = getPresentationUtilContext(); render( diff --git a/x-pack/plugins/lens/public/app_plugin/shared/saved_modal_lazy.tsx b/x-pack/plugins/lens/public/app_plugin/shared/saved_modal_lazy.tsx index f1a537fe65928..34f2c456a9683 100644 --- a/x-pack/plugins/lens/public/app_plugin/shared/saved_modal_lazy.tsx +++ b/x-pack/plugins/lens/public/app_plugin/shared/saved_modal_lazy.tsx @@ -10,7 +10,6 @@ import React, { Suspense, useEffect, useState } from 'react'; import { EuiLoadingSpinner, EuiOverlayMask } from '@elastic/eui'; import { CoreStart } from 'kibana/public'; import type { SaveModalContainerProps } from '../save_modal_container'; -import type { LensAttributeService } from '../../lens_attribute_service'; import type { LensPluginStartDependencies } from '../../plugin'; import type { LensAppServices } from '../types'; const SaveModal = React.lazy(() => import('../save_modal_container')); @@ -33,16 +32,20 @@ const LensSavedModalLazy = (props: SaveModalContainerProps) => { export function getSaveModalComponent( coreStart: CoreStart, - startDependencies: LensPluginStartDependencies, - attributeService: () => Promise + startDependencies: LensPluginStartDependencies ) { return (props: Omit) => { const [lensServices, setLensServices] = useState(); useEffect(() => { async function loadLensService() { - const { getLensServices } = await import('../../async_services'); - const lensServicesT = await getLensServices(coreStart, startDependencies, attributeService); + const { getLensServices, getLensAttributeService } = await import('../../async_services'); + + const lensServicesT = await getLensServices( + coreStart, + startDependencies, + getLensAttributeService(coreStart, startDependencies) + ); setLensServices(lensServicesT); } diff --git a/x-pack/plugins/lens/public/datatable_visualization/expression.test.tsx b/x-pack/plugins/lens/public/datatable_visualization/expression.test.tsx index b2a25cba329df..74c33a2b02a5b 100644 --- a/x-pack/plugins/lens/public/datatable_visualization/expression.test.tsx +++ b/x-pack/plugins/lens/public/datatable_visualization/expression.test.tsx @@ -9,7 +9,7 @@ import type { DatatableProps } from '../../common/expressions'; import type { LensMultiTable } from '../../common'; import { createMockExecutionContext } from '../../../../../src/plugins/expressions/common/mocks'; import type { FormatFactory } from '../../common'; -import { getDatatable } from './expression'; +import { getDatatable } from '../../common/expressions'; function sampleArgs() { const indexPatternId = 'indexPatternId'; diff --git a/x-pack/plugins/lens/public/datatable_visualization/expression.tsx b/x-pack/plugins/lens/public/datatable_visualization/expression.tsx index 4e541bce9a8c2..03691d56ee56a 100644 --- a/x-pack/plugins/lens/public/datatable_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/datatable_visualization/expression.tsx @@ -18,9 +18,7 @@ import { DatatableComponent } from './components/table_basic'; import type { ILensInterpreterRenderHandlers } from '../types'; import type { FormatFactory } from '../../common'; -import { DatatableProps } from '../../common/expressions'; - -export { datatableColumn, getDatatable } from '../../common/expressions'; +import type { DatatableProps } from '../../common/expressions'; export const getDatatableRenderer = (dependencies: { formatFactory: FormatFactory; diff --git a/x-pack/plugins/lens/public/datatable_visualization/index.ts b/x-pack/plugins/lens/public/datatable_visualization/index.ts index 3349f229a6048..51f1f54cc03ce 100644 --- a/x-pack/plugins/lens/public/datatable_visualization/index.ts +++ b/x-pack/plugins/lens/public/datatable_visualization/index.ts @@ -23,23 +23,14 @@ export interface DatatableVisualizationPluginSetupPlugins { } export class DatatableVisualization { - constructor() {} - setup( core: CoreSetup, { expressions, formatFactory, editorFrame, charts }: DatatableVisualizationPluginSetupPlugins ) { editorFrame.registerVisualization(async () => { - const { - getDatatable, - datatableColumn, - getDatatableRenderer, - getDatatableVisualization, - } = await import('../async_services'); + const { getDatatableRenderer, getDatatableVisualization } = await import('../async_services'); const palettes = await charts.palettes.getPalettes(); - expressions.registerFunction(() => datatableColumn); - expressions.registerFunction(() => getDatatable(() => formatFactory)); expressions.registerRenderer(() => getDatatableRenderer({ formatFactory, @@ -50,6 +41,7 @@ export class DatatableVisualization { uiSettings: core.uiSettings, }) ); + return getDatatableVisualization({ paletteService: palettes }); }); } diff --git a/x-pack/plugins/lens/public/editor_frame_service/service.tsx b/x-pack/plugins/lens/public/editor_frame_service/service.tsx index e1b1c637fa24b..d97cfd3cbca23 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/service.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/service.tsx @@ -6,7 +6,7 @@ */ import React from 'react'; -import { CoreSetup, CoreStart } from 'kibana/public'; +import { CoreStart } from 'kibana/public'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/public'; import { ExpressionsSetup, ExpressionsStart } from '../../../../../src/plugins/expressions/public'; import { EmbeddableSetup, EmbeddableStart } from '../../../../../src/plugins/embeddable/public'; @@ -22,7 +22,6 @@ import { EditorFrameStart, } from '../types'; import { Document } from '../persistence/saved_object_store'; -import { mergeTables } from '../../common/expressions'; import { UiActionsStart } from '../../../../../src/plugins/ui_actions/public'; import { ChartsPluginSetup } from '../../../../../src/plugins/charts/public'; import { DashboardStart } from '../../../../../src/plugins/dashboard/public'; @@ -59,8 +58,6 @@ async function collectAsyncDefinitions( } export class EditorFrameService { - constructor() {} - private readonly datasources: Array Promise)> = []; private readonly visualizations: Array Promise)> = []; @@ -81,12 +78,7 @@ export class EditorFrameService { return await persistedStateToExpression(resolvedDatasources, resolvedVisualizations, doc); }; - public setup( - core: CoreSetup, - plugins: EditorFrameSetupPlugins - ): EditorFrameSetup { - plugins.expressions.registerFunction(() => mergeTables); - + public setup(): EditorFrameSetup { return { registerDatasource: (datasource) => { this.datasources.push(datasource as Datasource); diff --git a/x-pack/plugins/lens/public/heatmap_visualization/expression.tsx b/x-pack/plugins/lens/public/heatmap_visualization/expression.tsx index 98ce4b399ae8d..84c8f987f524d 100644 --- a/x-pack/plugins/lens/public/heatmap_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/heatmap_visualization/expression.tsx @@ -17,8 +17,6 @@ import type { ChartsPluginSetup, PaletteRegistry } from '../../../../../src/plug import { HeatmapChartReportable } from './chart_component'; import type { HeatmapExpressionProps } from './types'; -export { heatmapGridConfig, heatmapLegendConfig, heatmap } from '../../common/expressions'; - export const getHeatmapRenderer = (dependencies: { formatFactory: FormatFactory; chartsThemeService: ChartsPluginSetup['theme']; diff --git a/x-pack/plugins/lens/public/heatmap_visualization/index.ts b/x-pack/plugins/lens/public/heatmap_visualization/index.ts index 5fb4524939f11..3ac3f769e4b5f 100644 --- a/x-pack/plugins/lens/public/heatmap_visualization/index.ts +++ b/x-pack/plugins/lens/public/heatmap_visualization/index.ts @@ -20,28 +20,15 @@ export interface HeatmapVisualizationPluginSetupPlugins { } export class HeatmapVisualization { - constructor() {} - setup( core: CoreSetup, { expressions, formatFactory, editorFrame, charts }: HeatmapVisualizationPluginSetupPlugins ) { editorFrame.registerVisualization(async () => { const timeZone = getTimeZone(core.uiSettings); - - const { - getHeatmapVisualization, - heatmap, - heatmapLegendConfig, - heatmapGridConfig, - getHeatmapRenderer, - } = await import('../async_services'); + const { getHeatmapVisualization, getHeatmapRenderer } = await import('../async_services'); const palettes = await charts.palettes.getPalettes(); - expressions.registerFunction(() => heatmap); - expressions.registerFunction(() => heatmapLegendConfig); - expressions.registerFunction(() => heatmapGridConfig); - expressions.registerRenderer( getHeatmapRenderer({ formatFactory, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/time_scaling.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/time_scaling.tsx index 7c611230683d3..8a670e7562573 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/time_scaling.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/time_scaling.tsx @@ -5,9 +5,16 @@ * 2.0. */ -import { EuiToolTip } from '@elastic/eui'; -import { EuiIcon } from '@elastic/eui'; -import { EuiFormRow, EuiSelect, EuiFlexItem, EuiFlexGroup, EuiButtonIcon } from '@elastic/eui'; +import { + EuiToolTip, + EuiIcon, + EuiFormRow, + EuiSelect, + EuiFlexItem, + EuiFlexGroup, + EuiButtonIcon, +} from '@elastic/eui'; + import { i18n } from '@kbn/i18n'; import React from 'react'; import { @@ -17,7 +24,7 @@ import { } from '../operations'; import type { TimeScaleUnit } from '../../../common/expressions'; import { unitSuffixesLong } from '../../../common/suffix_formatter'; -import { IndexPatternLayer } from '../types'; +import type { IndexPatternLayer } from '../types'; export function setTimeScaling( columnId: string, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/index.ts b/x-pack/plugins/lens/public/indexpattern_datasource/index.ts index 9ff80f51bea97..5f4afc9df6179 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/index.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/index.ts @@ -20,7 +20,6 @@ import type { FieldFormatsStart, FieldFormatsSetup, } from '../../../../../src/plugins/field_formats/public'; -import { getTimeZone } from '../utils'; export interface IndexPatternDatasourceSetupPlugins { expressions: ExpressionsSetup; @@ -38,8 +37,6 @@ export interface IndexPatternDatasourceStartPlugins { } export class IndexPatternDatasource { - constructor() {} - setup( core: CoreSetup, { @@ -50,15 +47,9 @@ export class IndexPatternDatasource { }: IndexPatternDatasourceSetupPlugins ) { editorFrame.registerDatasource(async () => { - const { - getIndexPatternDatasource, - renameColumns, - formatColumn, - counterRate, - getTimeScale, - getSuffixFormatter, - suffixFormatterId, - } = await import('../async_services'); + const { getIndexPatternDatasource, getSuffixFormatter, suffixFormatterId } = await import( + '../async_services' + ); if (!fieldFormatsSetup.has(suffixFormatterId)) { const startServices = createStartServicesGetter(core.getStartServices); @@ -69,11 +60,6 @@ export class IndexPatternDatasource { fieldFormatsSetup.register([suffixFormatter]); } - expressions.registerFunction(getTimeScale(() => getTimeZone(core.uiSettings))); - expressions.registerFunction(counterRate); - expressions.registerFunction(renameColumns); - expressions.registerFunction(formatColumn); - const [ coreStart, { indexPatternFieldEditor, uiActions, data, fieldFormats }, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx index 8f66bcf7fe49c..c54fa733e7499 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx @@ -70,19 +70,18 @@ export function columnToOperation(column: IndexPatternColumn, uniqueLabel?: stri }; } -export { +export type { + FormatColumnArgs, + TimeScaleArgs, CounterRateArgs, ExpressionFunctionCounterRate, - counterRate, } from '../../common/expressions'; -export { FormatColumnArgs, supportedFormats, formatColumn } from '../../common/expressions'; + export { getSuffixFormatter, unitSuffixesLong, suffixFormatterId, } from '../../common/suffix_formatter'; -export { getTimeScale, TimeScaleArgs } from '../../common/expressions'; -export { renameColumns } from '../../common/expressions'; export function getIndexPatternDatasource({ core, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts index cff036db4813b..b0793bf912bb2 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts @@ -8,7 +8,7 @@ import { flatten, minBy, pick, mapValues, partition } from 'lodash'; import { i18n } from '@kbn/i18n'; import { generateId } from '../id_generator'; -import { DatasourceSuggestion, TableChangeType } from '../types'; +import type { DatasourceSuggestion, TableChangeType } from '../types'; import { columnToOperation } from './indexpattern'; import { insertNewColumn, @@ -23,7 +23,7 @@ import { getReferencedColumnIds, } from './operations'; import { hasField } from './utils'; -import { +import type { IndexPattern, IndexPatternPrivateState, IndexPatternLayer, diff --git a/x-pack/plugins/lens/public/lens_attribute_service.ts b/x-pack/plugins/lens/public/lens_attribute_service.ts index 39a1903c6d0c4..3b8c47022af6e 100644 --- a/x-pack/plugins/lens/public/lens_attribute_service.ts +++ b/x-pack/plugins/lens/public/lens_attribute_service.ts @@ -5,14 +5,15 @@ * 2.0. */ -import { CoreStart } from '../../../../src/core/public'; -import { LensPluginStartDependencies } from './plugin'; -import { AttributeService } from '../../../../src/plugins/embeddable/public'; -import { +import type { CoreStart } from '../../../../src/core/public'; +import type { LensPluginStartDependencies } from './plugin'; +import type { AttributeService } from '../../../../src/plugins/embeddable/public'; +import type { LensSavedObjectAttributes, LensByValueInput, LensByReferenceInput, } from './embeddable/embeddable'; + import { SavedObjectIndexStore, Document } from './persistence'; import { checkForDuplicateTitle, OnSaveProps } from '../../../../src/plugins/saved_objects/public'; import { DOC_TYPE } from '../common'; diff --git a/x-pack/plugins/lens/public/metric_visualization/expression.tsx b/x-pack/plugins/lens/public/metric_visualization/expression.tsx index 41b487e790a08..8838e6df777c9 100644 --- a/x-pack/plugins/lens/public/metric_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/metric_visualization/expression.tsx @@ -19,9 +19,7 @@ import { EmptyPlaceholder } from '../shared_components'; import { LensIconChartMetric } from '../assets/chart_metric'; import type { FormatFactory } from '../../common'; import type { MetricChartProps } from '../../common/expressions'; - -export { metricChart } from '../../common/expressions'; -export type { MetricState, MetricConfig } from '../../common/expressions'; +export type { MetricChartProps, MetricState, MetricConfig } from '../../common/expressions'; export const getMetricChartRenderer = ( formatFactory: FormatFactory diff --git a/x-pack/plugins/lens/public/metric_visualization/index.ts b/x-pack/plugins/lens/public/metric_visualization/index.ts index 29138979ab858..20c25b285bd5b 100644 --- a/x-pack/plugins/lens/public/metric_visualization/index.ts +++ b/x-pack/plugins/lens/public/metric_visualization/index.ts @@ -17,18 +17,12 @@ export interface MetricVisualizationPluginSetupPlugins { } export class MetricVisualization { - constructor() {} - setup( _core: CoreSetup | null, { expressions, formatFactory, editorFrame }: MetricVisualizationPluginSetupPlugins ) { editorFrame.registerVisualization(async () => { - const { metricVisualization, metricChart, getMetricChartRenderer } = await import( - '../async_services' - ); - - expressions.registerFunction(() => metricChart); + const { metricVisualization, getMetricChartRenderer } = await import('../async_services'); expressions.registerRenderer(() => getMetricChartRenderer(formatFactory)); return metricVisualization; diff --git a/x-pack/plugins/lens/public/metric_visualization/metric_suggestions.ts b/x-pack/plugins/lens/public/metric_visualization/metric_suggestions.ts index de79f5f0a4cbc..3d6b2683b4ad2 100644 --- a/x-pack/plugins/lens/public/metric_visualization/metric_suggestions.ts +++ b/x-pack/plugins/lens/public/metric_visualization/metric_suggestions.ts @@ -6,7 +6,7 @@ */ import { SuggestionRequest, VisualizationSuggestion, TableSuggestion } from '../types'; -import { MetricState } from '../../common/expressions'; +import type { MetricState } from '../../common/expressions'; import { layerTypes } from '../../common'; import { LensIconChartMetric } from '../assets/chart_metric'; diff --git a/x-pack/plugins/lens/public/pie_visualization/expression.tsx b/x-pack/plugins/lens/public/pie_visualization/expression.tsx index c1b9f4c799e64..50dc0e2a296be 100644 --- a/x-pack/plugins/lens/public/pie_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/pie_visualization/expression.tsx @@ -19,8 +19,6 @@ import type { FormatFactory } from '../../common'; import type { PieExpressionProps } from '../../common/expressions'; import type { ChartsPluginSetup, PaletteRegistry } from '../../../../../src/plugins/charts/public'; -export { pie } from '../../common/expressions'; - export const getPieRenderer = (dependencies: { formatFactory: FormatFactory; chartsThemeService: ChartsPluginSetup['theme']; diff --git a/x-pack/plugins/lens/public/pie_visualization/index.ts b/x-pack/plugins/lens/public/pie_visualization/index.ts index 6d34de85f1801..b4670b3b9c9dd 100644 --- a/x-pack/plugins/lens/public/pie_visualization/index.ts +++ b/x-pack/plugins/lens/public/pie_visualization/index.ts @@ -24,18 +24,14 @@ export interface PieVisualizationPluginStartPlugins { } export class PieVisualization { - constructor() {} - setup( core: CoreSetup, { expressions, formatFactory, editorFrame, charts }: PieVisualizationPluginSetupPlugins ) { editorFrame.registerVisualization(async () => { - const { getPieVisualization, pie, getPieRenderer } = await import('../async_services'); + const { getPieVisualization, getPieRenderer } = await import('../async_services'); const palettes = await charts.palettes.getPalettes(); - expressions.registerFunction(() => pie); - expressions.registerRenderer( getPieRenderer({ formatFactory, diff --git a/x-pack/plugins/lens/public/plugin.ts b/x-pack/plugins/lens/public/plugin.ts index 95f2e13cbc464..db63b990b9013 100644 --- a/x-pack/plugins/lens/public/plugin.ts +++ b/x-pack/plugins/lens/public/plugin.ts @@ -5,27 +5,33 @@ * 2.0. */ -import { AppMountParameters, CoreSetup, CoreStart } from 'kibana/public'; +import type { AppMountParameters, CoreSetup, CoreStart } from 'kibana/public'; import type { Start as InspectorStartContract } from 'src/plugins/inspector/public'; import type { FieldFormatsSetup, FieldFormatsStart } from 'src/plugins/field_formats/public'; -import { UsageCollectionSetup, UsageCollectionStart } from 'src/plugins/usage_collection/public'; -import { DataPublicPluginSetup, DataPublicPluginStart } from '../../../../src/plugins/data/public'; -import { EmbeddableSetup, EmbeddableStart } from '../../../../src/plugins/embeddable/public'; -import { DashboardStart } from '../../../../src/plugins/dashboard/public'; -import { +import type { + UsageCollectionSetup, + UsageCollectionStart, +} from 'src/plugins/usage_collection/public'; +import type { + DataPublicPluginSetup, + DataPublicPluginStart, +} from '../../../../src/plugins/data/public'; +import type { EmbeddableSetup, EmbeddableStart } from '../../../../src/plugins/embeddable/public'; +import type { DashboardStart } from '../../../../src/plugins/dashboard/public'; +import type { ExpressionsServiceSetup, ExpressionsSetup, ExpressionsStart, } from '../../../../src/plugins/expressions/public'; -import { +import type { VisualizationsSetup, VisualizationsStart, } from '../../../../src/plugins/visualizations/public'; -import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public'; -import { UrlForwardingSetup } from '../../../../src/plugins/url_forwarding/public'; -import { GlobalSearchPluginSetup } from '../../global_search/public'; -import { ChartsPluginSetup, ChartsPluginStart } from '../../../../src/plugins/charts/public'; -import { PresentationUtilPluginStart } from '../../../../src/plugins/presentation_util/public'; +import type { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public'; +import type { UrlForwardingSetup } from '../../../../src/plugins/url_forwarding/public'; +import type { GlobalSearchPluginSetup } from '../../global_search/public'; +import type { ChartsPluginSetup, ChartsPluginStart } from '../../../../src/plugins/charts/public'; +import type { PresentationUtilPluginStart } from '../../../../src/plugins/presentation_util/public'; import { EmbeddableStateTransfer } from '../../../../src/plugins/embeddable/public'; import type { EditorFrameService as EditorFrameServiceType } from './editor_frame_service'; import { IndexPatternFieldEditorStart } from '../../../../src/plugins/index_pattern_field_editor/public'; @@ -59,20 +65,45 @@ import { VISUALIZE_FIELD_TRIGGER, } from '../../../../src/plugins/ui_actions/public'; import { APP_ID, FormatFactory, getEditPath, NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../common'; -import type { EditorFrameStart, VisualizationType } from './types'; +import type { VisualizationType } from './types'; import { getLensAliasConfig } from './vis_type_alias'; import { visualizeFieldAction } from './trigger_actions/visualize_field_actions'; import { getSearchProvider } from './search_provider'; -import { LensAttributeService } from './lens_attribute_service'; -import { LensEmbeddableInput } from './embeddable'; +import type { LensEmbeddableInput } from './embeddable'; import { EmbeddableFactory, LensEmbeddableStartServices } from './embeddable/embeddable_factory'; import { EmbeddableComponentProps, getEmbeddableComponent, } from './embeddable/embeddable_component'; import { getSaveModalComponent } from './app_plugin/shared/saved_modal_lazy'; -import { SaveModalContainerProps } from './app_plugin/save_modal_container'; +import type { SaveModalContainerProps } from './app_plugin/save_modal_container'; + +import { + axisTitlesVisibilityConfig, + counterRate, + datatableColumn, + formatColumn, + gridlinesConfig, + layerConfig, + legendConfig, + metricChart, + pie, + renameColumns, + tickLabelsConfig, + xyChart, + yAxisConfig, + mergeTables, + heatmap, + heatmapLegendConfig, + heatmapGridConfig, + axisExtentConfig, + getDatatable, + getTimeScale, + labelsOrientationConfig, +} from '../common/expressions'; +import { createStartServicesGetter } from '../../../../src/plugins/kibana_utils/public'; +import { getTimeZone } from './utils'; export interface LensPluginSetupDependencies { urlForwarding: UrlForwardingSetup; @@ -152,8 +183,6 @@ export interface LensPublicStart { export class LensPlugin { private datatableVisualization: DatatableVisualizationType | undefined; private editorFrameService: EditorFrameServiceType | undefined; - private createEditorFrame: EditorFrameStart['createInstance'] | null = null; - private attributeService: (() => Promise) | null = null; private indexpatternDatasource: IndexPatternDatasourceType | undefined; private xyVisualization: XyVisualizationType | undefined; private metricVisualization: MetricVisualizationType | undefined; @@ -176,37 +205,32 @@ export class LensPlugin { usageCollection, }: LensPluginSetupDependencies ) { - this.attributeService = async () => { - const { getLensAttributeService } = await import('./async_services'); - const [coreStart, startDependencies] = await core.getStartServices(); - return getLensAttributeService(coreStart, startDependencies); - }; + const startServices = createStartServicesGetter(core.getStartServices); const getStartServices = async (): Promise => { - const [coreStart, deps] = await core.getStartServices(); + const { getLensAttributeService } = await import('./async_services'); + const { core: coreStart, plugins } = startServices(); - this.initParts( + await this.initParts( core, data, - embeddable, charts, expressions, - usageCollection, fieldFormats, - deps.fieldFormats.deserialize + plugins.fieldFormats.deserialize ); return { - attributeService: await this.attributeService!(), + attributeService: getLensAttributeService(coreStart, plugins), capabilities: coreStart.application.capabilities, coreHttp: coreStart.http, - timefilter: deps.data.query.timefilter.timefilter, - expressionRenderer: deps.expressions.ReactExpressionRenderer, + timefilter: plugins.data.query.timefilter.timefilter, + expressionRenderer: plugins.expressions.ReactExpressionRenderer, documentToExpression: this.editorFrameService!.documentToExpression, - indexPatternService: deps.data.indexPatterns, - uiActions: deps.uiActions, + indexPatternService: plugins.data.indexPatterns, + uiActions: plugins.uiActions, usageCollection, - inspector: deps.inspector, + inspector: plugins.inspector, }; }; @@ -216,17 +240,37 @@ export class LensPlugin { visualizations.registerAlias(getLensAliasConfig()); - const getPresentationUtilContext = async () => { - const [, deps] = await core.getStartServices(); - const { ContextProvider } = deps.presentationUtil; - return ContextProvider; - }; + [ + pie, + xyChart, + mergeTables, + counterRate, + metricChart, + yAxisConfig, + layerConfig, + formatColumn, + legendConfig, + renameColumns, + gridlinesConfig, + datatableColumn, + tickLabelsConfig, + axisTitlesVisibilityConfig, + heatmap, + heatmapLegendConfig, + heatmapGridConfig, + axisExtentConfig, + labelsOrientationConfig, + getDatatable(() => startServices().plugins.fieldFormats.deserialize), + getTimeScale(() => getTimeZone(core.uiSettings)), + ].forEach((expressionFn) => expressions.registerFunction(expressionFn)); + + const getPresentationUtilContext = () => + startServices().plugins.presentationUtil.ContextProvider; const ensureDefaultIndexPattern = async () => { - const [, deps] = await core.getStartServices(); // make sure a default index pattern exists // if not, the page will be redirected to management and visualize won't be rendered - await deps.data.indexPatterns.ensureDefaultIndexPattern(); + await startServices().plugins.data.indexPatterns.ensureDefaultIndexPattern(); }; core.application.register({ @@ -234,25 +278,27 @@ export class LensPlugin { title: NOT_INTERNATIONALIZED_PRODUCT_NAME, navLinkStatus: AppNavLinkStatus.hidden, mount: async (params: AppMountParameters) => { - const [, deps] = await core.getStartServices(); + const { core: coreStart, plugins: deps } = startServices(); await this.initParts( core, data, - embeddable, charts, expressions, - usageCollection, fieldFormats, deps.fieldFormats.deserialize ); - const { mountApp, stopReportManager } = await import('./async_services'); + const { mountApp, stopReportManager, getLensAttributeService } = await import( + './async_services' + ); + const frameStart = this.editorFrameService!.start(coreStart, deps); + this.stopReportManager = stopReportManager; await ensureDefaultIndexPattern(); return mountApp(core, params, { - createEditorFrame: this.createEditorFrame!, - attributeService: this.attributeService!, + createEditorFrame: frameStart.createInstance, + attributeService: getLensAttributeService(coreStart, deps), getPresentationUtilContext, }); }, @@ -278,10 +324,8 @@ export class LensPlugin { private async initParts( core: CoreSetup, data: DataPublicPluginSetup, - embeddable: EmbeddableSetup | undefined, charts: ChartsPluginSetup, expressions: ExpressionsServiceSetup, - usageCollection: UsageCollectionSetup | undefined, fieldFormats: FieldFormatsSetup, formatFactory: FormatFactory ) { @@ -301,13 +345,9 @@ export class LensPlugin { this.metricVisualization = new MetricVisualization(); this.pieVisualization = new PieVisualization(); this.heatmapVisualization = new HeatmapVisualization(); - const editorFrameSetupInterface = this.editorFrameService.setup(core, { - data, - embeddable, - charts, - expressions, - usageCollection, - }); + + const editorFrameSetupInterface = this.editorFrameService.setup(); + const dependencies: IndexPatternDatasourceSetupPlugins & XyVisualizationPluginSetupPlugins & DatatableVisualizationPluginSetupPlugins & @@ -326,9 +366,6 @@ export class LensPlugin { this.metricVisualization.setup(core, dependencies); this.pieVisualization.setup(core, dependencies); this.heatmapVisualization.setup(core, dependencies); - const [coreStart, startDependencies] = await core.getStartServices(); - const frameStart = this.editorFrameService.start(coreStart, startDependencies); - this.createEditorFrame = frameStart.createInstance; } start(core: CoreStart, startDependencies: LensPluginStartDependencies): LensPublicStart { @@ -343,7 +380,7 @@ export class LensPlugin { return { EmbeddableComponent: getEmbeddableComponent(core, startDependencies), - SaveModalComponent: getSaveModalComponent(core, startDependencies, this.attributeService!), + SaveModalComponent: getSaveModalComponent(core, startDependencies), navigateToPrefilledEditor: ( input, { openInNewTab = false, originatingApp = '', originatingPath } = {} diff --git a/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx b/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx index a41ad59ebee93..aa2a0b42864e6 100644 --- a/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/expression.test.tsx @@ -22,9 +22,10 @@ import { LayoutDirection, } from '@elastic/charts'; import { PaletteOutput } from 'src/plugins/charts/public'; -import { calculateMinInterval, XYChart, XYChartRenderProps, xyChart } from './expression'; +import { calculateMinInterval, XYChart, XYChartRenderProps } from './expression'; import type { LensMultiTable } from '../../common'; import { layerTypes } from '../../common'; +import { xyChart } from '../../common/expressions'; import { layerConfig, legendConfig, diff --git a/x-pack/plugins/lens/public/xy_visualization/expression.tsx b/x-pack/plugins/lens/public/xy_visualization/expression.tsx index f8dff65969d57..4eaebeb98a5a1 100644 --- a/x-pack/plugins/lens/public/xy_visualization/expression.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/expression.tsx @@ -74,18 +74,6 @@ type SeriesSpec = InferPropType & InferPropType & InferPropType; -export { - legendConfig, - yAxisConfig, - tickLabelsConfig, - gridlinesConfig, - axisTitlesVisibilityConfig, - axisExtentConfig, - layerConfig, - xyChart, - labelsOrientationConfig, -} from '../../common/expressions'; - export type XYChartRenderProps = XYChartProps & { chartsThemeService: ChartsPluginSetup['theme']; chartsActiveCursorService: ChartsPluginStart['activeCursor']; diff --git a/x-pack/plugins/lens/public/xy_visualization/index.ts b/x-pack/plugins/lens/public/xy_visualization/index.ts index 6823ffedc9d90..f9d48ffaaae37 100644 --- a/x-pack/plugins/lens/public/xy_visualization/index.ts +++ b/x-pack/plugins/lens/public/xy_visualization/index.ts @@ -21,37 +21,14 @@ export interface XyVisualizationPluginSetupPlugins { } export class XyVisualization { - constructor() {} - setup( core: CoreSetup, { expressions, formatFactory, editorFrame }: XyVisualizationPluginSetupPlugins ) { editorFrame.registerVisualization(async () => { - const { - legendConfig, - yAxisConfig, - tickLabelsConfig, - gridlinesConfig, - axisTitlesVisibilityConfig, - axisExtentConfig, - labelsOrientationConfig, - layerConfig, - xyChart, - getXyChartRenderer, - getXyVisualization, - } = await import('../async_services'); + const { getXyChartRenderer, getXyVisualization } = await import('../async_services'); const [, { charts, fieldFormats }] = await core.getStartServices(); const palettes = await charts.palettes.getPalettes(); - expressions.registerFunction(() => legendConfig); - expressions.registerFunction(() => yAxisConfig); - expressions.registerFunction(() => tickLabelsConfig); - expressions.registerFunction(() => axisExtentConfig); - expressions.registerFunction(() => labelsOrientationConfig); - expressions.registerFunction(() => gridlinesConfig); - expressions.registerFunction(() => axisTitlesVisibilityConfig); - expressions.registerFunction(() => layerConfig); - expressions.registerFunction(() => xyChart); expressions.registerRenderer( getXyChartRenderer({ diff --git a/x-pack/plugins/lens/public/xy_visualization/types.ts b/x-pack/plugins/lens/public/xy_visualization/types.ts index 9d32c2f71c530..4729cfb96f324 100644 --- a/x-pack/plugins/lens/public/xy_visualization/types.ts +++ b/x-pack/plugins/lens/public/xy_visualization/types.ts @@ -17,8 +17,8 @@ import { LensIconChartBarHorizontalStacked } from '../assets/chart_bar_horizonta import { LensIconChartBarHorizontalPercentage } from '../assets/chart_bar_horizontal_percentage'; import { LensIconChartLine } from '../assets/chart_line'; -import { VisualizationType } from '../types'; -import { +import type { VisualizationType } from '../types'; +import type { SeriesType, ValueLabelConfig, LegendConfig,