From 8b5b9c0a12f4e8d3caac5121dc591ac228c5982c Mon Sep 17 00:00:00 2001 From: "Walter M. Rafelsberger" Date: Fri, 30 Jan 2026 11:00:52 +0100 Subject: [PATCH 1/5] extract es|ql conversion types --- .../convert_to_esql_modal.test.tsx | 2 +- .../edit_on_the_fly/convert_to_esql_modal.tsx | 24 +------ .../convert_to_text_based_layer.test.ts | 2 +- .../convert_to_text_based_layer.ts | 30 ++------ .../edit_on_the_fly/esql_conversion_types.ts | 72 +++++++++++++++++++ .../use_esql_conversion_check.tsx | 2 +- 6 files changed, 82 insertions(+), 50 deletions(-) create mode 100644 x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/esql_conversion_types.ts diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_esql_modal.test.tsx b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_esql_modal.test.tsx index 5a3be7caac451..680a06a7f5233 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_esql_modal.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_esql_modal.test.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; -import type { ConvertibleLayer } from './convert_to_esql_modal'; +import type { ConvertibleLayer } from './esql_conversion_types'; import { ConvertToEsqlModal } from './convert_to_esql_modal'; import userEvent from '@testing-library/user-event'; import { IconChartBarAnnotations, IconChartBarReferenceLine } from '@kbn/chart-icons'; diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_esql_modal.tsx b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_esql_modal.tsx index ee5057a92c8b3..2a9d7df9e283e 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_esql_modal.tsx +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_esql_modal.tsx @@ -11,7 +11,6 @@ import type { EuiBasicTableColumn, EuiConfirmModalProps, EuiTableSelectionType, - IconType, } from '@elastic/eui'; import { EuiBasicTable, @@ -29,29 +28,8 @@ import { useEuiTheme, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import type { LensLayerType } from '@kbn/lens-common'; -import type { OriginalColumn } from '../../../../common/types'; import { layerTypes } from '../../..'; - -type LayerType = Exclude; - -/** - * Conversion data from generateEsqlQuery. - */ -export interface EsqlConversionData { - esAggsIdMap: Record; - partialRows: boolean; -} - -export interface ConvertibleLayer { - id: string; - icon: IconType; - name: string; - type: LayerType; - query: string; - isConvertibleToEsql: boolean; - conversionData: EsqlConversionData; -} +import type { ConvertibleLayer, LayerType } from './esql_conversion_types'; const typeLabels: Record string> = { data: (count: number) => diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_text_based_layer.test.ts b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_text_based_layer.test.ts index f7b8d30547479..a55a67b63dcc7 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_text_based_layer.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_text_based_layer.test.ts @@ -13,7 +13,7 @@ import type { } from '@kbn/lens-common'; import { createMockFramePublicAPI } from '../../../mocks'; import { convertFormBasedToTextBasedLayer } from './convert_to_text_based_layer'; -import type { ConvertibleLayer, EsqlConversionData } from './convert_to_esql_modal'; +import type { ConvertibleLayer, EsqlConversionData } from './esql_conversion_types'; describe('convertFormBasedToTextBasedLayer', () => { const layerId = 'layer1'; diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_text_based_layer.ts b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_text_based_layer.ts index 6b6d5d1eff821..e43bdaa1021b0 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_text_based_layer.ts +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/convert_to_text_based_layer.ts @@ -15,11 +15,15 @@ import type { TextBasedLayerColumn, TextBasedPrivateState, TypedLensSerializedState, - DatasourceStates, ValueFormatConfig, } from '@kbn/lens-common'; -import type { ConvertibleLayer, EsqlConversionData } from './convert_to_esql_modal'; +import type { + ConvertibleLayer, + ConvertToEsqlParams, + EsqlConversionData, + LayerConversionData, +} from './esql_conversion_types'; // Map Lens DataType to DatatableColumnType // Some Lens types (counter, gauge, document) aren't valid DatatableColumnTypes @@ -33,16 +37,6 @@ const getMetaTypeFromDataType = (dataType: DataType): DatatableColumnType => { return dataType; }; -interface LayerConversionData { - layerId: string; - layer: FormBasedLayer; - conversionResult: { - esql: string; - partialRows: boolean; - esAggsIdMap: EsqlConversionData['esAggsIdMap']; - }; -} - /** * Retrieves conversion data for a form-based layer. */ @@ -158,18 +152,6 @@ function buildTextBasedState( }; } -interface ConvertToEsqlParams { - /** - * The ConvertibleLayer objects selected for conversion. - * Contains the ES|QL query and column mappings from useEsqlConversionCheck. - */ - layersToConvert: ConvertibleLayer[]; - attributes: TypedLensSerializedState['attributes']; - visualizationState: unknown; - datasourceStates: DatasourceStates; - framePublicAPI: FramePublicAPI; -} - /** * Converts form-based layers to text-based (ES|QL) and returns new attributes. * Returns undefined if conversion fails or no layers to convert. diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/esql_conversion_types.ts b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/esql_conversion_types.ts new file mode 100644 index 0000000000000..71d4fe5939cc1 --- /dev/null +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/esql_conversion_types.ts @@ -0,0 +1,72 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { IconType } from '@elastic/eui'; + +import type { + DatasourceStates, + FormBasedLayer, + FramePublicAPI, + LensLayerType, + TypedLensSerializedState, +} from '@kbn/lens-common'; + +import type { OriginalColumn } from '../../../../common/types'; + +/** + * Output from ES|QL query generation containing column mappings and partial row info. + */ +export interface EsqlConversionData { + esAggsIdMap: Record; + partialRows: boolean; +} + +/** + * Lens layer types that can appear in the ES|QL conversion UI. + * Excludes internal metricTrendline sub-layer. + */ +export type LayerType = Exclude; + +/** + * Represents a Lens layer eligible for ES|QL conversion with its + * generated query and metadata. + */ +export interface ConvertibleLayer { + id: string; + icon: IconType; + name: string; + type: LayerType; + query: string; + isConvertibleToEsql: boolean; + conversionData: EsqlConversionData; +} + +/** Type alias for ES|QL query strings. */ +export type EsqlConversionString = string; + +/** + * Intermediate structure holding a layer's conversion result during + * the ES|QL transformation process. + */ +export interface LayerConversionData { + layerId: string; + layer: FormBasedLayer; + conversionResult: { + esql: string; + partialRows: boolean; + esAggsIdMap: EsqlConversionData['esAggsIdMap']; + }; +} + +/** Parameters for converting form-based Lens layers to ES|QL datasource layers. */ +export interface ConvertToEsqlParams { + layersToConvert: ConvertibleLayer[]; + attributes: TypedLensSerializedState['attributes']; + visualizationState: unknown; + datasourceStates: DatasourceStates; + framePublicAPI: FramePublicAPI; +} diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/use_esql_conversion_check.tsx b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/use_esql_conversion_check.tsx index 400524dc3c4b5..f0ecf6ce43254 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/use_esql_conversion_check.tsx +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/use_esql_conversion_check.tsx @@ -27,7 +27,7 @@ import { esqlConversionFailureReasonMessages, getFailureTooltip, } from '../../../datasources/form_based/to_esql_failure_reasons'; -import type { ConvertibleLayer } from './convert_to_esql_modal'; +import type { ConvertibleLayer } from './esql_conversion_types'; import { operationDefinitionMap } from '../../../datasources/form_based/operations'; import type { LensPluginStartDependencies } from '../../../plugin'; import { layerTypes } from '../../..'; From ef1e2dca51fc65c983a710ccf9714271abfd9704 Mon Sep 17 00:00:00 2001 From: "Walter M. Rafelsberger" Date: Fri, 30 Jan 2026 12:47:54 +0100 Subject: [PATCH 2/5] improve types/return value for getActiveDatasourceIdFromDoc --- .../lens/public/app_plugin/app.test.tsx | 22 +- .../get_edit_lens_configuration.test.tsx | 8 +- .../get_edit_lens_configuration.tsx | 259 ++++++++++-------- .../edit_on_the_fly/layer_tabs.test.tsx | 26 +- .../lens_configuration_flyout.test.tsx | 16 +- .../app_plugin/show_underlying_data.test.ts | 82 +++--- .../shared/lens/public/chart_info_api.test.ts | 4 +- .../chart_switch/chart_switch.test.tsx | 58 ++-- .../config_panel/config_panel.test.tsx | 20 +- .../config_panel/layer_header.test.tsx | 6 +- .../config_panel/layer_panel.test.tsx | 6 +- .../editor_frame/editor_frame.test.tsx | 16 +- .../editor_frame/suggestion_helpers.test.ts | 6 +- .../editor_frame/suggestion_panel.test.tsx | 12 +- .../workspace_panel/workspace_panel.test.tsx | 44 +-- .../editor_frame_service_context.test.tsx | 2 +- .../lens/public/mocks/datasource_mock.tsx | 10 +- .../shared/lens/public/mocks/store_mocks.tsx | 4 +- .../react_embeddable/data_loader.test.ts | 8 +- .../lens/public/react_embeddable/esql.test.ts | 4 +- .../public/react_embeddable/helper.test.ts | 2 +- .../__snapshots__/load_initial.test.tsx.snap | 12 +- .../context_middleware/index.test.ts | 14 +- .../state_management/lens_slice.test.ts | 116 ++++---- .../state_management/load_initial.test.tsx | 36 +-- .../in_app_embeddable_edit_action.test.tsx | 2 +- .../plugins/shared/lens/public/utils.ts | 9 +- .../visualizations/xy/visualization.test.tsx | 4 +- 28 files changed, 420 insertions(+), 388 deletions(-) diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/app.test.tsx b/x-pack/platform/plugins/shared/lens/public/app_plugin/app.test.tsx index 924da29758465..3794ceeaa0a94 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/app.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/app.test.tsx @@ -186,9 +186,9 @@ describe('Lens App', () => { }, selectedLayerId: null, }, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: { datasourceState: true }, }, @@ -225,9 +225,9 @@ describe('Lens App', () => { query: preloadedState.query, filters: preloadedState.filters, datasourceStates: { - testDatasource: { + formBased: { isLoading: false, - state: preloadedState.datasourceStates.testDatasource.state, + state: preloadedState.datasourceStates.formBased.state, }, }, }) @@ -352,8 +352,8 @@ describe('Lens App', () => { await renderApp({ datasourceMapOverride: { ...datasourceMap, - testDatasource: { - ...datasourceMap.testDatasource, + formBased: { + ...datasourceMap.formBased, isTimeBased: jest.fn((_state, _indexPatterns) => true), }, }, @@ -373,8 +373,8 @@ describe('Lens App', () => { await renderApp({ datasourceMapOverride: { ...datasourceMap, - testDatasource: { - ...datasourceMap.testDatasource, + formBased: { + ...datasourceMap.formBased, isTimeBased: jest.fn((_state, _indexPatterns) => false), }, }, @@ -1403,7 +1403,7 @@ describe('Lens App', () => { state: { ...localDoc.state, datasourceStates: { - testDatasource: 'datasource', + formBased: 'datasource', }, visualization: {}, }, @@ -1421,8 +1421,8 @@ describe('Lens App', () => { preloadedState, datasourceMapOverride: { ...datasourceMap, - testDatasource: { - ...datasourceMap.testDatasource, + formBased: { + ...datasourceMap.formBased, isEqual: jest.fn().mockReturnValue(true), // if this returns false, the documents won't be accounted equal }, }, diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration.test.tsx b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration.test.tsx index 6055bc6616df0..a4900e79bb377 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration.test.tsx @@ -35,7 +35,7 @@ describe('Lens flyout', () => { test('updater is run if modifies visualization or datasource state', () => { store.dispatch( updateDatasourceState({ - datasourceId: 'testDatasource2', + datasourceId: 'textBased', newDatasourceState: 'newDatasourceState', }) ); @@ -51,8 +51,8 @@ describe('Lens flyout', () => { store.dispatch( setState({ datasourceStates: { - testDatasource: { state: {}, isLoading: true }, - testDatasource2: { state: {}, isLoading: true }, + formBased: { state: {}, isLoading: true }, + textBased: { state: {}, isLoading: true }, }, visualization: { state: {}, activeId: 'testVis', selectedLayerId: null }, }) @@ -62,7 +62,7 @@ describe('Lens flyout', () => { // testing store.dispatch( updateDatasourceState({ - datasourceId: 'testDatasource2', + datasourceId: 'textBased', newDatasourceState: {}, }) ); diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration.tsx b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration.tsx index 1d4c823656c7a..f5d09a6dcfa2f 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration.tsx +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/get_edit_lens_configuration.tsx @@ -5,6 +5,7 @@ * 2.0. */ +import type { FC } from 'react'; import React, { useCallback, useState } from 'react'; import { EuiFlyout, EuiLoadingSpinner, EuiOverlayMask } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; @@ -20,9 +21,9 @@ import type { TypedLensSerializedState, DatasourceMap, VisualizationMap, + LensAppServices, LensStoreDeps, LensDocument, - SupportedDatasourceId, } from '@kbn/lens-common'; import type { LensPluginStartDependencies } from '../../../plugin'; import { getActiveDatasourceIdFromDoc } from '../../../utils'; @@ -141,141 +142,171 @@ const MaybeWrapper = ({ ); }; -export async function getEditLensConfiguration( - coreStart: CoreStart, - startDependencies: LensPluginStartDependencies, - visualizationMap?: VisualizationMap, - datasourceMap?: DatasourceMap -) { - const { getLensServices, getLensAttributeService } = await import('../../../async_services'); - const lensServices = await getLensServices( - coreStart, - startDependencies, - getLensAttributeService(coreStart.http) +const EditLensConfiguration: FC< + EditLensConfigurationProps & { + coreStart: CoreStart; + startDependencies: LensPluginStartDependencies; + visualizationMap: VisualizationMap; + datasourceMap: DatasourceMap; + lensServices: LensAppServices; + } +> = ({ + coreStart, + startDependencies, + visualizationMap, + datasourceMap, + lensServices, + attributes, + updatePanelState, + updateSuggestion, + closeFlyout, + wrapInFlyout, + panelId, + savedObjectId, + dataLoading$, + lensAdapters, + updateByRefInput, + navigateToLensEditor, + displayFlyoutHeader, + isNewPanel, + hidesSuggestions, + onApply, + onCancel, + isReadOnly, + parentApi, + applyButtonLabel, + hideTextBasedEditor, +}) => { + const [currentAttributes, setCurrentAttributes] = + useState(attributes); + + /** + * During inline editing of a by reference panel, the panel is converted to a by value one. + * When the user applies the changes we save them to the Lens SO + */ + const saveByRef = useCallback( + async (attrs: LensDocument) => { + const lensDocumentService = new LensDocumentService(lensServices.http); + await lensDocumentService.save({ + ...attrs, + savedObjectId, + type: DOC_TYPE, + }); + }, + [lensServices.http, savedObjectId] ); - return ({ - attributes, + // Derive datasourceId from currentAttributes so it updates when attributes change + // (e.g., after converting from formBased to textBased) + const currentDatasourceId = getActiveDatasourceIdFromDoc(currentAttributes); + + if (currentDatasourceId === null) { + return ; + } + + const datasourceState = currentAttributes.state.datasourceStates[currentDatasourceId]; + + const storeDeps: LensStoreDeps = { + lensServices, + datasourceMap, + visualizationMap, + initialContext: + datasourceState && 'initialContext' in datasourceState + ? datasourceState.initialContext + : undefined, + visualizationType: attributes.visualizationType, + }; + const lensStore: LensRootStore = makeConfigureStore( + storeDeps, + undefined, + updatingMiddleware(updatePanelState) + ); + lensStore.dispatch( + loadInitial({ + initialInput: { + attributes: currentAttributes, + id: panelId ?? generateId(), + }, + inlineEditing: true, + hideTextBasedEditor, + }) + ); + + const configPanelProps: EditConfigPanelProps = { + attributes: currentAttributes, updatePanelState, updateSuggestion, closeFlyout, - wrapInFlyout, - panelId, - savedObjectId, + coreStart, + startDependencies, dataLoading$, lensAdapters, + saveByRef, + savedObjectId, updateByRefInput, navigateToLensEditor, displayFlyoutHeader, - isNewPanel, hidesSuggestions, + setCurrentAttributes, + isNewPanel, onApply, onCancel, isReadOnly, parentApi, + panelId, applyButtonLabel, hideTextBasedEditor, - }: EditLensConfigurationProps) => { - if (!lensServices || !datasourceMap || !visualizationMap) { - return ; - } - - const [currentAttributes, setCurrentAttributes] = - useState(attributes); + }; - // Derive datasourceId from currentAttributes so it updates when attributes change - // (e.g., after converting from formBased to textBased) - const currentDatasourceId = getActiveDatasourceIdFromDoc( - currentAttributes - ) as SupportedDatasourceId; + return ( + + + + + + + {coreStart.rendering.addContext( + + )} + + + + + + + ); +}; - /** - * During inline editing of a by reference panel, the panel is converted to a by value one. - * When the user applies the changes we save them to the Lens SO - */ - const saveByRef = useCallback( - async (attrs: LensDocument) => { - const lensDocumentService = new LensDocumentService(lensServices.http); - await lensDocumentService.save({ - ...attrs, - savedObjectId, - type: DOC_TYPE, - }); - }, - [savedObjectId] - ); - const datasourceState = currentAttributes.state.datasourceStates[currentDatasourceId]; - const storeDeps: LensStoreDeps = { - lensServices, - datasourceMap, - visualizationMap, - initialContext: - datasourceState && 'initialContext' in datasourceState - ? datasourceState.initialContext - : undefined, - visualizationType: attributes.visualizationType, - }; - const lensStore: LensRootStore = makeConfigureStore( - storeDeps, - undefined, - updatingMiddleware(updatePanelState) - ); - lensStore.dispatch( - loadInitial({ - initialInput: { - attributes: currentAttributes, - id: panelId ?? generateId(), - }, - inlineEditing: true, - hideTextBasedEditor, - }) - ); +export async function getEditLensConfiguration( + coreStart: CoreStart, + startDependencies: LensPluginStartDependencies, + visualizationMap?: VisualizationMap, + datasourceMap?: DatasourceMap +) { + const { getLensServices, getLensAttributeService } = await import('../../../async_services'); + const lensServices = await getLensServices( + coreStart, + startDependencies, + getLensAttributeService(coreStart.http) + ); - const configPanelProps: EditConfigPanelProps = { - attributes: currentAttributes, - updatePanelState, - updateSuggestion, - closeFlyout, - coreStart, - startDependencies, - dataLoading$, - lensAdapters, - saveByRef, - savedObjectId, - updateByRefInput, - navigateToLensEditor, - displayFlyoutHeader, - hidesSuggestions, - setCurrentAttributes, - isNewPanel, - onApply, - onCancel, - isReadOnly, - parentApi, - panelId, - applyButtonLabel, - hideTextBasedEditor, - }; + return (props: EditLensConfigurationProps) => { + if (!lensServices || !datasourceMap || !visualizationMap) { + return ; + } return ( - - - - - - - {coreStart.rendering.addContext( - - )} - - - - - - + ); }; } diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/layer_tabs.test.tsx b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/layer_tabs.test.tsx index 6f4685567eaca..b68a4e188de87 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/layer_tabs.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/layer_tabs.test.tsx @@ -120,12 +120,12 @@ describe('LayerTabs', () => { { preloadedState: { datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: 'state', }, }, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', visualization: { activeId: 'testVis', state: 'state', @@ -155,7 +155,7 @@ describe('LayerTabs', () => { datasourceMap: ReturnType; } { frame.datasourceLayers = { - first: datasourceMap.testDatasource.publicAPIMock, + first: datasourceMap.formBased.publicAPIMock, }; // Override getAddLayerButtonComponent to return simple buttons for testing @@ -222,7 +222,7 @@ describe('LayerTabs', () => { }, ]); - datasourceMap.testDatasource.initializeDimension = jest.fn(); + datasourceMap.formBased.initializeDimension = jest.fn(); const props = getDefaultProps({ visualizationMap, datasourceMap }); const { instance, lensStore } = await prepareAndMountComponent(props); @@ -256,7 +256,7 @@ describe('LayerTabs', () => { layerId: 'newId', prevState: undefined, }); - expect(datasourceMap.testDatasource.initializeDimension).not.toHaveBeenCalled(); + expect(datasourceMap.formBased.initializeDimension).not.toHaveBeenCalled(); }); it('should not add an initial dimension when not specified', async () => { @@ -270,7 +270,7 @@ describe('LayerTabs', () => { label: 'Reference layer', }, ]); - datasourceMap.testDatasource.initializeDimension = jest.fn(); + datasourceMap.formBased.initializeDimension = jest.fn(); const props = getDefaultProps({ datasourceMap, visualizationMap }); const { instance, lensStore } = await prepareAndMountComponent(props); @@ -278,13 +278,13 @@ describe('LayerTabs', () => { // One call for adding the layer, one call for setting it as the current selected layer expect(lensStore.dispatch).toHaveBeenCalledTimes(2); - expect(datasourceMap.testDatasource.initializeDimension).not.toHaveBeenCalled(); + expect(datasourceMap.formBased.initializeDimension).not.toHaveBeenCalled(); }); it('should not add an initial dimension when initialDimensions are not available for the given layer type', async () => { const datasourceMap = mockDatasourceMap(); const visualizationMap = mockVisualizationMap(); - datasourceMap.testDatasource.initializeDimension = jest.fn(); + datasourceMap.formBased.initializeDimension = jest.fn(); visualizationMap.testVis.getSupportedLayers = jest.fn(() => [ { @@ -309,7 +309,7 @@ describe('LayerTabs', () => { addNewLayer(instance); // One call for adding the layer, one call for setting it as the current selected layer expect(lensStore.dispatch).toHaveBeenCalledTimes(2); - expect(datasourceMap.testDatasource.initializeDimension).not.toHaveBeenCalled(); + expect(datasourceMap.formBased.initializeDimension).not.toHaveBeenCalled(); }); it('should use group initial dimension value when adding a new layer if available', async () => { @@ -346,7 +346,7 @@ describe('LayerTabs', () => { ], }, ]); - datasourceMap.testDatasource.initializeDimension = jest.fn(); + datasourceMap.formBased.initializeDimension = jest.fn(); const props = getDefaultProps({ datasourceMap, visualizationMap }); const { instance, lensStore } = await prepareAndMountComponent(props); @@ -354,7 +354,7 @@ describe('LayerTabs', () => { // One call for adding the layer, one call for setting it as the current selected layer expect(lensStore.dispatch).toHaveBeenCalledTimes(2); - expect(datasourceMap.testDatasource.initializeDimension).toHaveBeenCalledWith( + expect(datasourceMap.formBased.initializeDimension).toHaveBeenCalledWith( {}, 'newId', frame.dataViews.indexPatterns, @@ -434,12 +434,12 @@ describe('LayerTabs', () => { const { instance } = await prepareAndMountComponent(props, { preloadedState: { datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: 'state', }, }, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', visualization: { activeId: 'testVis', state: 'state', diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.test.tsx b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.test.tsx index 9e94dbbaae482..86cb5fc74338f 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.test.tsx @@ -98,7 +98,7 @@ const lensAttributes = { visualizationType: 'testVis', state: { datasourceStates: { - testDatasource: {}, + formBased: {}, }, visualization: {}, filters: [], @@ -171,12 +171,12 @@ describe('LensEditConfigurationFlyout', () => { { preloadedState: { datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: 'state', }, }, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', query: query as Query, visualization: { state: {}, @@ -273,7 +273,7 @@ describe('LensEditConfigurationFlyout', () => { title: 'test', visualizationType: 'testVis', state: { - datasourceStates: { testDatasource: 'state' }, + datasourceStates: { formBased: 'state' }, visualization: {}, filters: [], query: { esql: 'from index1 | limit 10' }, @@ -350,9 +350,7 @@ describe('LensEditConfigurationFlyout', () => { saveByRef: saveByRefSpy, attributes: lensAttributes, }; - // todo: replace testDatasource with formBased or textBased as it's the only ones accepted - // @ts-ignore - newProps.attributes.state.datasourceStates.testDatasource = 'state'; + newProps.attributes.state.datasourceStates.formBased = 'state'; await renderConfigFlyout(newProps); expect(screen.getByRole('button', { name: /apply and close/i })).toBeDisabled(); }); @@ -367,8 +365,8 @@ describe('LensEditConfigurationFlyout', () => { saveByRef: saveByRefSpy, datasourceMap: { ...datasourceMap, - testDatasource: { - ...datasourceMap.testDatasource, + formBased: { + ...datasourceMap.formBased, toExpression: jest.fn(() => null), }, }, diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/show_underlying_data.test.ts b/x-pack/platform/plugins/shared/lens/public/app_plugin/show_underlying_data.test.ts index 879dabc37242c..e568956c07355 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/show_underlying_data.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/show_underlying_data.test.ts @@ -22,7 +22,7 @@ describe('getLayerMetaInfo', () => { it('should return error in case of no data', () => { expect( getLayerMetaInfo( - createMockDatasource('testDatasource'), + createMockDatasource('formBased'), {}, createMockVisualization('testVisualization'), {}, @@ -71,7 +71,7 @@ describe('getLayerMetaInfo', () => { it('should return error in case of missing datasource configuration/state', () => { expect( getLayerMetaInfo( - createMockDatasource('testDatasource'), + createMockDatasource('formBased'), undefined, createMockVisualization('testVisualization'), {}, @@ -86,7 +86,7 @@ describe('getLayerMetaInfo', () => { it('should return error in case of missing activeVisualization', () => { expect( getLayerMetaInfo( - createMockDatasource('testDatasource'), + createMockDatasource('formBased'), {}, undefined, {}, @@ -101,7 +101,7 @@ describe('getLayerMetaInfo', () => { it('should return error in case of missing visualization configuration/state', () => { expect( getLayerMetaInfo( - createMockDatasource('testDatasource'), + createMockDatasource('formBased'), {}, createMockVisualization('testVisualization'), undefined, @@ -116,7 +116,7 @@ describe('getLayerMetaInfo', () => { it('should ignore the number of datatables passed, rather check the datasource and visualization configuration', () => { expect( getLayerMetaInfo( - createMockDatasource('testDatasource', { + createMockDatasource('formBased', { getFilters: jest.fn(() => ({ enabled: { kuery: [], lucene: [] }, disabled: { kuery: [], lucene: [] }, @@ -137,7 +137,7 @@ describe('getLayerMetaInfo', () => { }); it('should return no multiple layers error when non-data layers are used together with a single data layer', () => { - const mockDatasource = createMockDatasource('testDatasource', { + const mockDatasource = createMockDatasource('formBased', { getFilters: jest.fn(() => ({ enabled: { kuery: [], lucene: [] }, disabled: { kuery: [], lucene: [] }, @@ -165,7 +165,7 @@ describe('getLayerMetaInfo', () => { }); it('should return error in case of a timeshift declared in a column', () => { - const mockDatasource = createMockDatasource('testDatasource', { + const mockDatasource = createMockDatasource('formBased', { getOperationForColumnId: jest.fn(() => ({ dataType: 'number', isBucketed: false, @@ -192,7 +192,7 @@ describe('getLayerMetaInfo', () => { }); it('should return error in case of getFilters returning errors', () => { - const mockDatasource = createMockDatasource('testDatasource', { + const mockDatasource = createMockDatasource('formBased', { datasourceId: 'formBased', getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]), getFilters: jest.fn(() => ({ error: 'filters error' })), @@ -214,7 +214,7 @@ describe('getLayerMetaInfo', () => { }); it('should not be visible if discover is not available', () => { - const mockDatasource = createMockDatasource('testDatasource', { + const mockDatasource = createMockDatasource('formBased', { datasourceId: 'indexpattern', getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]), getFilters: jest.fn(() => ({ error: 'filters error' })), @@ -257,7 +257,7 @@ describe('getLayerMetaInfo', () => { }); it('should basically work collecting fields and filters in the visualization', () => { - const mockDatasource = createMockDatasource('testDatasource', { + const mockDatasource = createMockDatasource('formBased', { datasourceId: 'formBased', getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]), getSourceId: jest.fn(() => '1'), @@ -303,7 +303,7 @@ describe('getLayerMetaInfo', () => { }); it('should order date fields first', () => { - const mockDatasource = createMockDatasource('testDatasource', { + const mockDatasource = createMockDatasource('formBased', { datasourceId: 'formBased', getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes', 'timestamp'] }]), getSourceId: jest.fn(() => '1'), @@ -340,7 +340,7 @@ describe('combineQueryAndFilters', () => { { language: 'kuery', query: 'myfield: *' }, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { kuery: [], lucene: [] }, disabled: { kuery: [], lucene: [] } }, }, @@ -356,7 +356,7 @@ describe('combineQueryAndFilters', () => { { language: 'kuery', query: 'myfield: *' }, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { kuery: [[{ language: 'kuery', query: 'otherField: *' }]], lucene: [] }, @@ -378,7 +378,7 @@ describe('combineQueryAndFilters', () => { undefined, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { kuery: [[{ language: 'kuery', query: 'otherField: *' }]], lucene: [] }, @@ -398,7 +398,7 @@ describe('combineQueryAndFilters', () => { undefined, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { @@ -436,7 +436,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: 'myField' }, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { @@ -478,7 +478,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (kuery)', disabled: false, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -518,14 +518,14 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Existing kuery filters', disabled: false, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, } as Filter, ], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { @@ -566,7 +566,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Existing kuery filters', disabled: false, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -590,7 +590,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (lucene)', disabled: false, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -609,7 +609,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: 'myField' }, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { @@ -650,7 +650,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (kuery)', disabled: false, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -672,7 +672,7 @@ describe('combineQueryAndFilters', () => { ], [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { @@ -736,7 +736,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (kuery)', disabled: false, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -758,7 +758,7 @@ describe('combineQueryAndFilters', () => { [{ language: 'lucene', query: '' }], [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { @@ -778,7 +778,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: '' }, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { @@ -798,7 +798,7 @@ describe('combineQueryAndFilters', () => { undefined, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { @@ -850,14 +850,14 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Existing kuery filters', disabled: false, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, } as Filter, ], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { enabled: { @@ -912,7 +912,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Existing kuery filters', disabled: false, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -937,7 +937,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (lucene)', disabled: false, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -957,7 +957,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: 'myField' }, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { disabled: { @@ -991,7 +991,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'anotherField (lucene)', disabled: true, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -1022,7 +1022,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'myfield: *', disabled: true, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -1041,7 +1041,7 @@ describe('combineQueryAndFilters', () => { undefined, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { disabled: { @@ -1085,7 +1085,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'myfield: *abc*', disabled: true, - index: 'testDatasource', + index: 'formBased', negate: false, type: 'custom', }, @@ -1104,7 +1104,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: 'myField' }, [], { - id: 'testDatasource', + id: 'formBased', columns: [], filters: { disabled: { @@ -1143,7 +1143,7 @@ describe('combineQueryAndFilters', () => { must_not: [], }, meta: { - index: 'testDatasource', + index: 'formBased', type: 'custom', disabled: false, negate: false, @@ -1167,7 +1167,7 @@ describe('combineQueryAndFilters', () => { must_not: [], }, meta: { - index: 'testDatasource', + index: 'formBased', type: 'custom', disabled: true, negate: false, @@ -1198,7 +1198,7 @@ describe('combineQueryAndFilters', () => { must_not: [], }, meta: { - index: 'testDatasource', + index: 'formBased', type: 'custom', disabled: true, negate: false, diff --git a/x-pack/platform/plugins/shared/lens/public/chart_info_api.test.ts b/x-pack/platform/plugins/shared/lens/public/chart_info_api.test.ts index 7c331a54a248c..8179618ceaa1d 100644 --- a/x-pack/platform/plugins/shared/lens/public/chart_info_api.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/chart_info_api.test.ts @@ -46,7 +46,7 @@ describe('createChartInfoApi', () => { }, } as unknown as VisualizationMap, { - from_based: { + formBased: { getDatasourceInfo: mockGetDatasourceInfo, }, } as unknown as DatasourceMap @@ -56,7 +56,7 @@ describe('createChartInfoApi', () => { visualizationType: 'lnsXY', state: { datasourceStates: { - from_based: {}, + formBased: {}, }, visualization: {}, filters: [], diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/chart_switch/chart_switch.test.tsx b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/chart_switch/chart_switch.test.tsx index dbe8111773316..00e0056cf792f 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/chart_switch/chart_switch.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/chart_switch/chart_switch.test.tsx @@ -46,7 +46,7 @@ const mockFrame = (layers: string[]) => ({ const datasourceSuggestions: Record = { unchanged: [ { - state: 'testDatasource suggestion', + state: 'formBased suggestion', table: { columns: [ { @@ -75,7 +75,7 @@ const datasourceSuggestions: Record = { ], layers: [ { - state: 'testDatasource suggestion layer a', + state: 'formBased suggestion layer a', table: { columns: [ { @@ -102,7 +102,7 @@ const datasourceSuggestions: Record = { keptLayerIds: ['a'], }, { - state: 'testDatasource suggestion layer b', + state: 'formBased suggestion layer b', table: { columns: [ { @@ -252,7 +252,7 @@ describe('chart_switch', () => { selectedLayerId: null, }, datasourceStates, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', ...preloadedStateOverrides, }, } @@ -292,10 +292,10 @@ describe('chart_switch', () => { describe('data loss indicators', () => { it('should indicate data loss if not all columns will be used', async () => { - datasourceMap.testDatasource.getDatasourceSuggestionsFromCurrentState.mockReturnValue( + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue( datasourceSuggestions.unchanged ); - datasourceMap.testDatasource.publicAPIMock.getTableSpec.mockReturnValue([ + datasourceMap.formBased.publicAPIMock.getTableSpec.mockReturnValue([ { columnId: 'col1', fields: [] }, { columnId: 'col2', fields: [] }, { columnId: 'col3', fields: [] }, @@ -321,7 +321,7 @@ describe('chart_switch', () => { it('should support multi-layer suggestions without data loss', async () => { frame = mockFrame(['a', 'b']); - datasourceMap.testDatasource.getDatasourceSuggestionsFromCurrentState.mockReturnValue( + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue( datasourceSuggestions.unchanged ); (frame.datasourceLayers.a?.getTableSpec as jest.Mock).mockReturnValue([ @@ -420,7 +420,7 @@ describe('chart_switch', () => { suggestion: { visualizationState: 'testVis2 initial state', newVisualizationId: 'testVis2', - datasourceId: 'testDatasource', + datasourceId: 'formBased', datasourceState: {}, }, clearStagedPreview: true, @@ -475,7 +475,7 @@ describe('chart_switch', () => { await openChartSwitch(); switchToVis('testVis2'); - expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'a'); // from preloaded state + expect(datasourceMap.formBased.removeLayer).toHaveBeenCalledWith({}, 'a'); // from preloaded state expect(store.dispatch).toHaveBeenCalledWith({ type: 'lens/switchVisualization', payload: { @@ -500,7 +500,7 @@ describe('chart_switch', () => { visualizationMap.testVis.getMainPalette = jest.fn(() => legacyPalette); visualizationMap.testVis2.getSuggestions.mockReturnValueOnce([]); frame = mockFrame(['a', 'b', 'c']); - datasourceMap.testDatasource.getLayers.mockReturnValue(['a', 'b', 'c']); + datasourceMap.formBased.getLayers.mockReturnValue(['a', 'b', 'c']); const { openChartSwitch, switchToVis } = renderChartSwitch(); await openChartSwitch(); @@ -530,7 +530,7 @@ describe('chart_switch', () => { suggestion: { visualizationState: 'testVis2 initial state testVis2', newVisualizationId: 'testVis2', - datasourceId: 'testDatasource', + datasourceId: 'formBased', datasourceState: {}, }, clearStagedPreview: true, @@ -563,8 +563,8 @@ describe('chart_switch', () => { describe('multi-layer suggestions', () => { it('should use suggestion for chart switch for selected layer', async () => { frame = mockFrame(['a', 'b']); - datasourceMap.testDatasource.getLayers.mockReturnValue(['a', 'b']); - datasourceMap.testDatasource.getDatasourceSuggestionsFromCurrentState.mockReturnValue( + datasourceMap.formBased.getLayers.mockReturnValue(['a', 'b']); + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue( datasourceSuggestions.layers ); (frame.datasourceLayers.a?.getTableSpec as jest.Mock).mockReturnValue([ @@ -586,8 +586,8 @@ describe('chart_switch', () => { suggestion: { visualizationState: 'testVis2 initial state', newVisualizationId: 'testVis2', - datasourceId: 'testDatasource', - datasourceState: 'testDatasource suggestion layer b', + datasourceId: 'formBased', + datasourceState: 'formBased suggestion layer b', }, clearStagedPreview: true, }, @@ -623,7 +623,7 @@ describe('chart_switch', () => { type: 'lens/switchVisualization', payload: { suggestion: { - datasourceId: 'testDatasource', + datasourceId: 'formBased', datasourceState: {}, visualizationState: 'switched', newVisualizationId: 'testVis3', @@ -631,7 +631,7 @@ describe('chart_switch', () => { clearStagedPreview: true, }, }); - expect(datasourceMap.testDatasource.removeLayer).not.toHaveBeenCalled(); + expect(datasourceMap.formBased.removeLayer).not.toHaveBeenCalled(); }); it('should not remove layers and initialize with existing state when switching between subtypes without data', async () => { @@ -660,13 +660,13 @@ describe('chart_switch', () => { }, 'a' ); - expect(datasourceMap.testDatasource.removeLayer).not.toHaveBeenCalled(); + expect(datasourceMap.formBased.removeLayer).not.toHaveBeenCalled(); }); it('should switch to the updated datasource state', async () => { frame = mockFrame(['a', 'b']); - datasourceMap.testDatasource.getDatasourceSuggestionsFromCurrentState.mockReturnValue( + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue( datasourceSuggestions.unchanged ); @@ -679,8 +679,8 @@ describe('chart_switch', () => { payload: { suggestion: { newVisualizationId: 'testVis2', - datasourceId: 'testDatasource', - datasourceState: 'testDatasource suggestion', + datasourceId: 'formBased', + datasourceState: 'formBased suggestion', visualizationState: 'testVis2 initial state', }, clearStagedPreview: true, @@ -691,16 +691,16 @@ describe('chart_switch', () => { // it('should get suggestions when switching subvisualization based on the current layer', async () => { // visualizationMap.testVis3.getSuggestions.mockReturnValueOnce([]); // frame = mockFrame(['a', 'b', 'c']); - // datasourceMap.testDatasource.getLayers.mockReturnValue(['a', 'b', 'c']); + // datasourceMap.formBased.getLayers.mockReturnValue(['a', 'b', 'c']); // const { openChartSwitch, switchToVis } = renderChartSwitch({ layerId: 'c' }); // openChartSwitch(); // screen.debug(); // switchToVis('testVis3'); - // expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'a'); - // expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'b'); - // expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'c'); + // expect(datasourceMap.formBased.removeLayer).toHaveBeenCalledWith({}, 'a'); + // expect(datasourceMap.formBased.removeLayer).toHaveBeenCalledWith({}, 'b'); + // expect(datasourceMap.formBased.removeLayer).toHaveBeenCalledWith({}, 'c'); // expect(visualizationMap.testVis2.getSuggestions).toHaveBeenCalledWith( // expect.objectContaining({ // keptLayerIds: ['a'], @@ -724,15 +724,15 @@ describe('chart_switch', () => { it('should get suggestions when switching subvisualization', async () => { visualizationMap.testVis2.getSuggestions.mockReturnValueOnce([]); frame = mockFrame(['a', 'b', 'c']); - datasourceMap.testDatasource.getLayers.mockReturnValue(['a', 'b', 'c']); + datasourceMap.formBased.getLayers.mockReturnValue(['a', 'b', 'c']); const { openChartSwitch, switchToVis, store } = renderChartSwitch(); await openChartSwitch(); switchToVis('testVis2'); - expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'a'); - expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'b'); - expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'c'); + expect(datasourceMap.formBased.removeLayer).toHaveBeenCalledWith({}, 'a'); + expect(datasourceMap.formBased.removeLayer).toHaveBeenCalledWith({}, 'b'); + expect(datasourceMap.formBased.removeLayer).toHaveBeenCalledWith({}, 'c'); expect(visualizationMap.testVis2.getSuggestions).toHaveBeenCalledWith( expect.objectContaining({ keptLayerIds: ['a'], diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx index 678da47729769..daaae3a24125e 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx @@ -86,12 +86,12 @@ describe('ConfigPanel', () => { { preloadedState: { datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: 'state', }, }, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', query: query as Query, visualization: { activeId: 'testVis', @@ -117,12 +117,12 @@ describe('ConfigPanel', () => { } ) { frame.datasourceLayers = { - first: datasourceMap.testDatasource.publicAPIMock, + first: datasourceMap.formBased.publicAPIMock, }; return { activeVisualizationId: 'testVis', visualizationMap, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', datasourceMap, activeVisualization: { ...visualizationMap.testVis, @@ -143,7 +143,7 @@ describe('ConfigPanel', () => { }, } as Visualization, datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: 'state', }, @@ -179,14 +179,14 @@ describe('ConfigPanel', () => { const { updateDatasource, updateAll } = instance.find(LayerPanel).props(); const newDatasourceState = 'updated'; - updateDatasource('testDatasource', newDatasourceState); + updateDatasource('formBased', newDatasourceState); await waitMs(0); expect(lensStore.dispatch).toHaveBeenCalledTimes(1); expect((lensStore.dispatch as jest.Mock).mock.calls[0][0].payload.newDatasourceState).toEqual( 'updated' ); - updateAll('testDatasource', newDatasourceState, props.visualizationState); + updateAll('formBased', newDatasourceState, props.visualizationState); // wait for one tick so async updater has a chance to trigger await waitMs(0); expect(lensStore.dispatch).toHaveBeenCalledTimes(3); @@ -220,14 +220,14 @@ describe('ConfigPanel', () => { ], }, ]); - datasourceMap.testDatasource.initializeDimension = jest.fn(); + datasourceMap.formBased.initializeDimension = jest.fn(); const props = getDefaultProps({ visualizationMap, datasourceMap }); const { instance, lensStore } = await prepareAndMountComponent(props); await clickToAddDimension(instance); expect(lensStore.dispatch).toHaveBeenCalledTimes(1); - expect(datasourceMap.testDatasource.initializeDimension).toHaveBeenCalledWith( + expect(datasourceMap.formBased.initializeDimension).toHaveBeenCalledWith( 'state', 'first', frame.dataViews.indexPatterns, @@ -262,7 +262,7 @@ describe('ConfigPanel', () => { label: 'Reference layer', }, ]); - datasourceMap.testDatasource.initializeDimension = jest.fn(); + datasourceMap.formBased.initializeDimension = jest.fn(); const props = getDefaultProps({ datasourceMap, visualizationMap }); const { instance } = await prepareAndMountComponent(props, {}, { esql: 'from "foo"' }); diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_header.test.tsx b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_header.test.tsx index a221ded676a2e..4c56ee0eaa803 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_header.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_header.test.tsx @@ -36,8 +36,8 @@ describe('LayerHeader', () => { visualizationMapOverrides, }: RenderLayerSettingsOptions = {}) => { const datasourceMap = datasourceMapOverrides ?? { - testDatasource: createMockDatasource(), - testDatasource2: createMockDatasource('testDatasource2'), + formBased: createMockDatasource(), + textBased: createMockDatasource('textBased'), }; const visualizationMap = visualizationMapOverrides ?? { testVis: createMockVisualization(), @@ -81,7 +81,7 @@ describe('LayerHeader', () => { selectedLayerId: null, }, datasourceStates: mockDatasourceStates(), - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', ...preloadedStateOverrides, }, } diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx index 56d67e8aba713..285f59ae6a512 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx @@ -88,7 +88,7 @@ interface RenderLayerPanelOptions { describe('LayerPanel', () => { let mockVisualization: jest.Mocked; - let mockDatasource = createMockDatasource('testDatasource'); + let mockDatasource = createMockDatasource('formBased'); function getDefaultProps(): LayerPanelProps { return { @@ -143,7 +143,7 @@ describe('LayerPanel', () => { testVis: mockVisualization, }} datasourceMap={{ - testDatasource: mockDatasource, + formBased: mockDatasource, }} > {children} @@ -597,7 +597,7 @@ describe('LayerPanel', () => { await userEvent.click(screen.getByTestId('lns-indexPattern-dimensionContainerBack')); expect(mockDatasource.updateStateOnCloseDimension).toHaveBeenCalled(); - expect(updateDatasource).toHaveBeenCalledWith('testDatasource', { newState: {} }); + expect(updateDatasource).toHaveBeenCalledWith('formBased', { newState: {} }); }); it('should display the fake final accessor if present in the group config', async () => { diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/editor_frame.test.tsx b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/editor_frame.test.tsx index bcafcd505cc6d..33f1ec6896db6 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/editor_frame.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/editor_frame.test.tsx @@ -100,7 +100,7 @@ describe('editor_frame', () => { mockVisualization2 = createMockVisualization('testVis2', ['second']); mockDatasource = createMockDatasource(); - mockDatasource2 = createMockDatasource('testDatasource2'); + mockDatasource2 = createMockDatasource('textBased'); mockDatasource.getLayers.mockReturnValue(['first']); mockDatasource.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ { @@ -121,8 +121,8 @@ describe('editor_frame', () => { }; datasourceMap = { - testDatasource: mockDatasource, - testDatasource2: mockDatasource2, + formBased: mockDatasource, + textBased: mockDatasource2, }; }); @@ -140,14 +140,14 @@ describe('editor_frame', () => { {}, { preloadedState: { - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', visualization: { activeId: mockVisualization.id, state: 'initialState', selectedLayerId: 'layer1', }, datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: { internalState: 'datasourceState', @@ -177,7 +177,7 @@ describe('editor_frame', () => { store.dispatch( setState({ datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: { internalState: 'datasourceState', @@ -200,7 +200,7 @@ describe('editor_frame', () => { } = renderEditorFrame(undefined, { preloadedStateOverrides: { datasourceStates: { - testDatasource: { + formBased: { isLoading: true, state: { internalState: 'datasourceState', @@ -292,7 +292,7 @@ describe('editor_frame', () => { renderEditorFrame(); const updatedPublicAPI: DatasourcePublicAPI = { - datasourceId: 'testDatasource', + datasourceId: 'formBased', getOperationForColumnId: jest.fn(), getTableSpec: jest.fn(), getVisualDefaults: jest.fn(), diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts index c33bd1a1a11e5..44a0014e93e86 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts @@ -153,6 +153,8 @@ describe('suggestion helpers', () => { ); }); + // Tests iteration over multiple datasources. Production only supports 2 (formBased, textBased), + // but the algorithm handles N datasources generically. it('should call getDatasourceSuggestionsForField from all datasources with a state', () => { const multiDatasourceStates = { mock: { @@ -226,6 +228,8 @@ describe('suggestion helpers', () => { ); }); + // Tests iteration over multiple datasources. Production only supports 2 (formBased, textBased), + // but the algorithm handles N datasources generically. it('should call getDatasourceSuggestionsForVisualizeField from all datasources with a state', () => { const multiDatasourceStates = { mock: { @@ -592,7 +596,7 @@ describe('suggestion helpers', () => { }, }, { activeId: 'testVis', state: {}, selectedLayerId: null }, - { testDatasource: { state: mockDatasourceState, isLoading: false } }, + { a: { state: mockDatasourceState, isLoading: false } }, { testVis: mockVisualization1 }, datasourceMap.mock, { id: 'myfield', humanData: { label: 'myfieldLabel' } }, diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_panel.test.tsx b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_panel.test.tsx index ab0d93e58104c..033c7051ff9cf 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_panel.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_panel.test.tsx @@ -92,7 +92,7 @@ describe('suggestion_panel', () => { preloadedState = { datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: '', }, @@ -102,7 +102,7 @@ describe('suggestion_panel', () => { state: {}, selectedLayerId: null, }, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', }; defaultProps = { @@ -119,7 +119,7 @@ describe('suggestion_panel', () => { }; defaultDatasourceMap = { - testDatasource: mockDatasource, + formBased: mockDatasource, }; }); @@ -210,7 +210,7 @@ describe('suggestion_panel', () => { beforeEach(() => { suggestionState = { datasourceStates: { - testDatasource: { + formBased: { isLoading: false, state: '', }, @@ -410,8 +410,8 @@ describe('suggestion_panel', () => { const newPreloadedState = { ...preloadedState, datasourceStates: { - testDatasource: { - ...preloadedState.datasourceStates!.testDatasource, + formBased: { + ...preloadedState.datasourceStates!.formBased, state: missingIndexPatternsState, }, }, diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.test.tsx b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.test.tsx index e7dda7381759f..2268cc568c8e5 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.test.tsx @@ -185,7 +185,7 @@ describe('workspace_panel', () => { renderWithReduxStore( { const { rerender, store } = renderWithReduxStore( { rerender( { rerender( { const { store } = renderWithReduxStore( { const mounted = mountWithReduxStore( null }, @@ -475,7 +475,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( 'testVis' }, @@ -514,7 +514,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( 'testVis' }, @@ -555,7 +555,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( 'testVis' }, @@ -593,7 +593,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( 'testVis' }, @@ -641,7 +641,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( 'testVis' }, @@ -688,7 +688,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( 'testVis' }, @@ -749,7 +749,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( @@ -780,7 +780,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( { act(() => { lensStore.dispatch( updateDatasourceState({ - datasourceId: 'testDatasource', + datasourceId: 'formBased', newDatasourceState: 'newState', }) ); @@ -849,7 +849,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( 'testVis' }, @@ -880,7 +880,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( 'testVis' }, @@ -913,7 +913,7 @@ describe('workspace_panel', () => { const mounted = mountWithReduxStore( 'testVis' }, @@ -960,7 +960,7 @@ describe('workspace_panel', () => { function renderWithDndAndRedux(propsOverrides = {}, draggingContext = draggedField) { return renderWithReduxStore( { getSuggestionForField: jest.fn().mockReturnValue({ visualizationId: 'testVis', visualizationState: {}, - datasourceId: 'testDatasource', + datasourceId: 'formBased', datasourceState: {}, }), }); @@ -994,7 +994,7 @@ describe('workspace_panel', () => { suggestion: { newVisualizationId: 'testVis', visualizationState: {}, - datasourceId: 'testDatasource', + datasourceId: 'formBased', datasourceState: {}, }, clearStagedPreview: true, @@ -1007,7 +1007,7 @@ describe('workspace_panel', () => { getSuggestionForField: jest.fn().mockReturnValue({ visualizationId: 'testVis', visualizationState: {}, - datasourceId: 'testDatasource', + datasourceId: 'formBased', datasourceState: {}, }), }); diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame_service_context.test.tsx b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame_service_context.test.tsx index b5ac28add7cde..d510143d5c519 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame_service_context.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame_service_context.test.tsx @@ -16,7 +16,7 @@ describe('EditorFrameServiceContext', () => { }; const mockDatasourceMap: DatasourceMap = { - testDatasource: {} as Datasource, + formBased: {} as Datasource, }; function TestComponent() { diff --git a/x-pack/platform/plugins/shared/lens/public/mocks/datasource_mock.tsx b/x-pack/platform/plugins/shared/lens/public/mocks/datasource_mock.tsx index 2c45c78924892..39dce4bf1552d 100644 --- a/x-pack/platform/plugins/shared/lens/public/mocks/datasource_mock.tsx +++ b/x-pack/platform/plugins/shared/lens/public/mocks/datasource_mock.tsx @@ -12,7 +12,7 @@ export type DatasourceMock = jest.Mocked & { }; export function createMockDatasource( - id = 'testDatasource', + id = 'formBased', customPublicApi: Partial = {} ): DatasourceMock { const publicAPIMock = { @@ -29,7 +29,7 @@ export function createMockDatasource( } as jest.Mocked; return { - id: 'testDatasource', + id, clearLayer: jest.fn((state, _layerId) => ({ newState: state, removedLayerIds: [] })), getDatasourceSuggestionsForField: jest.fn((_state, _item, filterFn, _indexPatterns) => []), getDatasourceSuggestionsForVisualizeField: jest.fn( @@ -78,7 +78,7 @@ export function createMockDatasource( } export function mockDatasourceMap() { - const datasource = createMockDatasource(); + const datasource = createMockDatasource('formBased'); datasource.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ { state: {}, @@ -94,8 +94,8 @@ export function mockDatasourceMap() { datasource.getLayers.mockReturnValue(['a']); return { - testDatasource2: createMockDatasource('testDatasource2'), - testDatasource: datasource, + textBased: createMockDatasource('textBased'), + formBased: datasource, }; } diff --git a/x-pack/platform/plugins/shared/lens/public/mocks/store_mocks.tsx b/x-pack/platform/plugins/shared/lens/public/mocks/store_mocks.tsx index 6fc81321530fd..125ec16bb3353 100644 --- a/x-pack/platform/plugins/shared/lens/public/mocks/store_mocks.tsx +++ b/x-pack/platform/plugins/shared/lens/public/mocks/store_mocks.tsx @@ -42,7 +42,7 @@ export const mockStoreDeps = ({ export function mockDatasourceStates() { return { - testDatasource: { + formBased: { state: {}, isLoading: false, }, @@ -58,7 +58,7 @@ export const defaultState = { isSaveable: false, isLoading: false, isLinkedToOriginatingApp: false, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', visualization: { state: {}, activeId: 'testVis', diff --git a/x-pack/platform/plugins/shared/lens/public/react_embeddable/data_loader.test.ts b/x-pack/platform/plugins/shared/lens/public/react_embeddable/data_loader.test.ts index c9bf39777aca9..97b72a20379da 100644 --- a/x-pack/platform/plugins/shared/lens/public/react_embeddable/data_loader.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/react_embeddable/data_loader.test.ts @@ -102,7 +102,7 @@ async function expectRerenderOnDataLoader( const services = { ...makeEmbeddableServices(new BehaviorSubject(''), undefined, { visOverrides: { id: 'lnsXY' }, - dataOverrides: { id: 'form_based' }, + dataOverrides: { id: 'formBased' }, }), documentToExpression: jest.fn().mockResolvedValue({ ast: 'expression_string' }), ...servicesOverrides, @@ -516,8 +516,8 @@ describe('Data Loader', () => { // Mock the testing datasource to return an error when asked for checkIntegrity servicesOverrides: { datasourceMap: { - form_based: { - ...createMockDatasource('form_based'), + formBased: { + ...createMockDatasource('formBased'), checkIntegrity: jest.fn().mockReturnValue(['90943e30-9a47-11e8-b64d-95841ca0b247']), }, }, @@ -528,7 +528,7 @@ describe('Data Loader', () => { activeAttributes: { ...defaultDoc, visualizationType: 'lnsXY', - state: { ...defaultDoc.state, datasourceStates: { form_based: {} } }, + state: { ...defaultDoc.state, datasourceStates: { formBased: {} } }, }, mergedSearchContext: { now: Date.now(), diff --git a/x-pack/platform/plugins/shared/lens/public/react_embeddable/esql.test.ts b/x-pack/platform/plugins/shared/lens/public/react_embeddable/esql.test.ts index e8994ce66dc3d..9be92ee362d24 100644 --- a/x-pack/platform/plugins/shared/lens/public/react_embeddable/esql.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/react_embeddable/esql.test.ts @@ -29,7 +29,7 @@ describe('ES|QL attributes creation', () => { return { ...makeEmbeddableServices(new BehaviorSubject(''), undefined, { visOverrides: { id: 'lnsXY' }, - dataOverrides: { id: 'form_based' }, + dataOverrides: { id: 'formBased' }, }), uiSettings: { ...getUiSettingsOverrides(), get: jest.fn().mockReturnValue(true) }, ...servicesOverrides, @@ -60,7 +60,7 @@ describe('ES|QL attributes creation', () => { { title: 'MyTitle', visualizationId: 'lnsXY', - datasourceId: 'form_based', + datasourceId: 'formBased', datasourceState: {}, visualizationState: {}, columns: 1, diff --git a/x-pack/platform/plugins/shared/lens/public/react_embeddable/helper.test.ts b/x-pack/platform/plugins/shared/lens/public/react_embeddable/helper.test.ts index aada057986201..0da6c6fff55ab 100644 --- a/x-pack/platform/plugins/shared/lens/public/react_embeddable/helper.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/react_embeddable/helper.test.ts @@ -21,7 +21,7 @@ describe('Embeddable helpers', () => { function getServices() { return makeEmbeddableServices(new BehaviorSubject(''), undefined, { visOverrides: { id: 'lnsXY' }, - dataOverrides: { id: 'form_based' }, + dataOverrides: { id: 'formBased' }, }); } it('should forward a by value state', async () => { diff --git a/x-pack/platform/plugins/shared/lens/public/state_management/__snapshots__/load_initial.test.tsx.snap b/x-pack/platform/plugins/shared/lens/public/state_management/__snapshots__/load_initial.test.tsx.snap index 2f5c01231871e..2a41b8ae7111f 100644 --- a/x-pack/platform/plugins/shared/lens/public/state_management/__snapshots__/load_initial.test.tsx.snap +++ b/x-pack/platform/plugins/shared/lens/public/state_management/__snapshots__/load_initial.test.tsx.snap @@ -3,18 +3,18 @@ exports[`Initializing the store should initialize all datasources with state from doc 1`] = ` Object { "lens": Object { - "activeDatasourceId": "testDatasource", + "activeDatasourceId": "formBased", "annotationGroups": Object {}, "dataViews": Object { "indexPatternRefs": Array [], "indexPatterns": Object {}, }, "datasourceStates": Object { - "testDatasource": Object { + "formBased": Object { "isLoading": false, "state": undefined, }, - "testDatasource2": Object { + "textBased": Object { "isLoading": false, "state": undefined, }, @@ -39,7 +39,7 @@ Object { "savedObjectId": "1234", "state": Object { "datasourceStates": Object { - "testDatasource": Object { + "formBased": Object { "isLoading": false, "state": Object {}, }, @@ -74,10 +74,10 @@ Object { "savedObjectId": "1234", "state": Object { "datasourceStates": Object { - "testDatasource": Object { + "formBased": Object { "datasource1": "", }, - "testDatasource2": Object { + "textBased": Object { "datasource2": "", }, }, diff --git a/x-pack/platform/plugins/shared/lens/public/state_management/context_middleware/index.test.ts b/x-pack/platform/plugins/shared/lens/public/state_management/context_middleware/index.test.ts index 3c5cd53c4df32..9018ae1a3f73b 100644 --- a/x-pack/platform/plugins/shared/lens/public/state_management/context_middleware/index.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/state_management/context_middleware/index.test.ts @@ -27,8 +27,8 @@ const createMiddleware = (data: DataPublicPluginStart, state?: Partial ({ lens: state || { ...initialState, - activeDatasourceId: 'testDatasource', - datasourceStates: { testDatasource: { state: {} } }, + activeDatasourceId: 'formBased', + datasourceStates: { formBased: { state: {} } }, }, })), dispatch: jest.fn(), @@ -45,7 +45,7 @@ describe('contextMiddleware', () => { describe('time update', () => { it('does update the searchSessionId when the state changes and too much time passed', () => { const data = mockDataPlugin(); - storeDeps.datasourceMap.testDatasource.isTimeBased = () => true; + storeDeps.datasourceMap.formBased.isTimeBased = () => true; (data.nowProvider.get as jest.Mock).mockReturnValue(new Date(Date.now() - 30000)); (data.query.timefilter.timefilter.getTime as jest.Mock).mockReturnValue({ from: 'now-2m', @@ -81,7 +81,7 @@ describe('contextMiddleware', () => { }); it('does not update the searchSessionId when current state is not time based', () => { const data = mockDataPlugin(); - storeDeps.datasourceMap.testDatasource.isTimeBased = () => false; + storeDeps.datasourceMap.formBased.isTimeBased = () => false; (data.nowProvider.get as jest.Mock).mockReturnValue(new Date(Date.now() - 30000)); (data.query.timefilter.timefilter.getTime as jest.Mock).mockReturnValue({ from: 'now-2m', @@ -119,7 +119,7 @@ describe('contextMiddleware', () => { it('only updates searchSessionId when user applies changes', () => { // setup const data = mockDataPlugin(); - storeDeps.datasourceMap.testDatasource.isTimeBased = () => true; + storeDeps.datasourceMap.formBased.isTimeBased = () => true; (data.nowProvider.get as jest.Mock).mockReturnValue(new Date(Date.now() - 30000)); (data.query.timefilter.timefilter.getTime as jest.Mock).mockReturnValue({ from: 'now-2m', @@ -131,8 +131,8 @@ describe('contextMiddleware', () => { }); const { invoke, store } = createMiddleware(data, { ...initialState, - activeDatasourceId: 'testDatasource', - datasourceStates: { testDatasource: { state: {}, isLoading: false } }, + activeDatasourceId: 'formBased', + datasourceStates: { formBased: { state: {}, isLoading: false } }, autoApplyDisabled: true, }); diff --git a/x-pack/platform/plugins/shared/lens/public/state_management/lens_slice.test.ts b/x-pack/platform/plugins/shared/lens/public/state_management/lens_slice.test.ts index 09692252c951e..be246784df48e 100644 --- a/x-pack/platform/plugins/shared/lens/public/state_management/lens_slice.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/state_management/lens_slice.test.ts @@ -118,11 +118,11 @@ describe('lensSlice', () => { const newDatasourceState = {}; store.dispatch( updateDatasourceState({ - datasourceId: 'testDatasource', + datasourceId: 'formBased', newDatasourceState, }) ); - expect(store.getState().lens.datasourceStates.testDatasource.state).toStrictEqual( + expect(store.getState().lens.datasourceStates.formBased.state).toStrictEqual( newDatasourceState ); }); @@ -151,25 +151,25 @@ describe('lensSlice', () => { newVisualizationId: 'testVis2', visualizationState: newVisState, datasourceState: newDatasourceState, - datasourceId: 'testDatasource', + datasourceId: 'formBased', }, clearStagedPreview: true, }) ); expect(store.getState().lens.visualization.state).toBe(newVisState); - expect(store.getState().lens.datasourceStates.testDatasource.state).toBe(newDatasourceState); + expect(store.getState().lens.datasourceStates.formBased.state).toBe(newDatasourceState); }); it('should switch active datasource and initialize new state', () => { store.dispatch( switchDatasource({ - newDatasourceId: 'testDatasource2', + newDatasourceId: 'textBased', }) ); - expect(store.getState().lens.activeDatasourceId).toEqual('testDatasource2'); - expect(store.getState().lens.datasourceStates.testDatasource2.isLoading).toEqual(true); + expect(store.getState().lens.activeDatasourceId).toEqual('textBased'); + expect(store.getState().lens.datasourceStates.textBased.isLoading).toEqual(true); }); it('should not initialize already initialized datasource on switch', () => { @@ -177,11 +177,11 @@ describe('lensSlice', () => { const { store: customStore } = makeLensStore({ preloadedState: { datasourceStates: { - testDatasource: { + formBased: { state: {}, isLoading: false, }, - testDatasource2: { + textBased: { state: datasource2State, isLoading: false, }, @@ -191,28 +191,26 @@ describe('lensSlice', () => { customStore.dispatch( switchDatasource({ - newDatasourceId: 'testDatasource2', + newDatasourceId: 'textBased', }) ); - expect(customStore.getState().lens.activeDatasourceId).toEqual('testDatasource2'); - expect(customStore.getState().lens.datasourceStates.testDatasource2.isLoading).toEqual(false); - expect(customStore.getState().lens.datasourceStates.testDatasource2.state).toBe( - datasource2State - ); + expect(customStore.getState().lens.activeDatasourceId).toEqual('textBased'); + expect(customStore.getState().lens.datasourceStates.textBased.isLoading).toEqual(false); + expect(customStore.getState().lens.datasourceStates.textBased.state).toBe(datasource2State); }); describe('switching to a new datasource and modify the state', () => { it('should switch active datasource and initialize new state', () => { store.dispatch( switchAndCleanDatasource({ - newDatasourceId: 'testDatasource2', + newDatasourceId: 'textBased', visualizationId: 'testVis', currentIndexPatternId: 'testIndexPatternId', }) ); - expect(store.getState().lens.activeDatasourceId).toEqual('testDatasource2'); - expect(store.getState().lens.datasourceStates.testDatasource2.isLoading).toEqual(false); + expect(store.getState().lens.activeDatasourceId).toEqual('textBased'); + expect(store.getState().lens.datasourceStates.textBased.isLoading).toEqual(false); expect(store.getState().lens.visualization.activeId).toEqual('testVis'); }); @@ -223,11 +221,11 @@ describe('lensSlice', () => { const { store: customStore } = makeLensStore({ preloadedState: { datasourceStates: { - testDatasource: { + formBased: { state: {}, isLoading: false, }, - testDatasource2: { + textBased: { state: datasource2State, isLoading: false, }, @@ -237,24 +235,20 @@ describe('lensSlice', () => { customStore.dispatch( switchAndCleanDatasource({ - newDatasourceId: 'testDatasource2', + newDatasourceId: 'textBased', visualizationId: 'testVis', currentIndexPatternId: 'testIndexPatternId', }) ); - expect(customStore.getState().lens.activeDatasourceId).toEqual('testDatasource2'); - expect(customStore.getState().lens.datasourceStates.testDatasource2.isLoading).toEqual( - false - ); - expect(customStore.getState().lens.datasourceStates.testDatasource2.state).toStrictEqual( - {} - ); + expect(customStore.getState().lens.activeDatasourceId).toEqual('textBased'); + expect(customStore.getState().lens.datasourceStates.textBased.isLoading).toEqual(false); + expect(customStore.getState().lens.datasourceStates.textBased.state).toStrictEqual({}); }); }); describe('adding or removing layer', () => { - const testDatasource = (datasourceId: string) => { + const formBased = (datasourceId: string) => { return { id: datasourceId, getPublicAPI: () => ({ @@ -283,18 +277,18 @@ describe('lensSlice', () => { }; }; const datasourceStates = { - testDatasource: { + formBased: { isLoading: false, state: ['layer1'], }, - testDatasource2: { + textBased: { isLoading: false, state: ['layer2'], }, }; const datasourceMap = { - testDatasource: testDatasource('testDatasource'), - testDatasource2: testDatasource('testDatasource2'), + formBased: formBased('formBased'), + textBased: formBased('textBased'), }; const activeVisId = 'testVis'; @@ -318,7 +312,7 @@ describe('lensSlice', () => { beforeEach(() => { customStore = makeLensStore({ preloadedState: { - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', datasourceStates, visualization: { activeId: activeVisId, @@ -352,12 +346,12 @@ describe('lensSlice', () => { const state = customStore.getState().lens; expect(state.visualization.state).toEqual(['layer1', 'layer2', 'foo']); - expect(state.datasourceStates.testDatasource.state).toEqual([ + expect(state.datasourceStates.formBased.state).toEqual([ 'layer1', 'foo', 'linked-layer-id', ]); - expect(state.datasourceStates.testDatasource2.state).toEqual(['layer2']); + expect(state.datasourceStates.textBased.state).toEqual(['layer2']); expect(state.stagedPreview).not.toBeDefined(); }); @@ -382,7 +376,7 @@ describe('lensSlice', () => { groups: [{ groupId: 'to-group' } as VisualizationDimensionGroupConfig], })); activeVisualization.onDrop = jest.fn(({ prevState }) => prevState); - (datasourceMap.testDatasource as unknown as Datasource).syncColumns = jest.fn( + (datasourceMap.formBased as unknown as Datasource).syncColumns = jest.fn( ({ state }) => state ); @@ -396,7 +390,7 @@ describe('lensSlice', () => { expect( ( - (datasourceMap.testDatasource as unknown as Datasource).syncColumns as jest.Mock< + (datasourceMap.formBased as unknown as Datasource).syncColumns as jest.Mock< Datasource['syncColumns'] > ).mock.calls[0][0] @@ -466,15 +460,15 @@ describe('lensSlice', () => { describe('setLayerDefaultDimension', () => { it('should not call initializeDimension when layer has noDatasource: true', () => { const activeVisualization = visualizationMap[activeVisId] as Visualization; - const testDatasourceWithInit = { - ...datasourceMap.testDatasource, + const formBasedWithInit = { + ...datasourceMap.formBased, initializeDimension: jest.fn((state) => state), }; const setDimensionMock = jest.fn(({ prevState }) => prevState); const customStoreWithInit = makeLensStore({ preloadedState: { - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', datasourceStates, visualization: { activeId: activeVisId, @@ -506,7 +500,7 @@ describe('lensSlice', () => { }, } as unknown as VisualizationMap, datasourceMap: { - testDatasource: testDatasourceWithInit, + formBased: formBasedWithInit, } as unknown as DatasourceMap, }), }).store; @@ -519,20 +513,20 @@ describe('lensSlice', () => { }) ); - expect(testDatasourceWithInit.initializeDimension).not.toHaveBeenCalled(); + expect(formBasedWithInit.initializeDimension).not.toHaveBeenCalled(); expect(setDimensionMock).toHaveBeenCalled(); }); it('should call initializeDimension when layer does not have noDatasource flag', () => { const activeVisualization = visualizationMap[activeVisId] as Visualization; - const testDatasourceWithInit = { - ...datasourceMap.testDatasource, + const formBasedWithInit = { + ...datasourceMap.formBased, initializeDimension: jest.fn((state) => state), }; const customStoreWithInit = makeLensStore({ preloadedState: { - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', datasourceStates, visualization: { activeId: activeVisId, @@ -563,7 +557,7 @@ describe('lensSlice', () => { }, } as unknown as VisualizationMap, datasourceMap: { - testDatasource: testDatasourceWithInit, + formBased: formBasedWithInit, } as unknown as DatasourceMap, }), }).store; @@ -576,19 +570,19 @@ describe('lensSlice', () => { }) ); - expect(testDatasourceWithInit.initializeDimension).toHaveBeenCalled(); + expect(formBasedWithInit.initializeDimension).toHaveBeenCalled(); }); it('should not initialize dimension when no initialDimensions are specified', () => { const activeVisualization = visualizationMap[activeVisId] as Visualization; - const testDatasourceWithInit = { - ...datasourceMap.testDatasource, + const formBasedWithInit = { + ...datasourceMap.formBased, initializeDimension: jest.fn((state) => state), }; const customStoreWithInit = makeLensStore({ preloadedState: { - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', datasourceStates, visualization: { activeId: activeVisId, @@ -613,7 +607,7 @@ describe('lensSlice', () => { }, } as unknown as VisualizationMap, datasourceMap: { - testDatasource: testDatasourceWithInit, + formBased: formBasedWithInit, } as unknown as DatasourceMap, }), }).store; @@ -626,7 +620,7 @@ describe('lensSlice', () => { }) ); - expect(testDatasourceWithInit.initializeDimension).not.toHaveBeenCalled(); + expect(formBasedWithInit.initializeDimension).not.toHaveBeenCalled(); }); }); @@ -641,26 +635,26 @@ describe('lensSlice', () => { const state = customStore.getState().lens; expect(state.visualization.state).toEqual(['layer2']); - expect(state.datasourceStates.testDatasource.state).toEqual([]); - expect(state.datasourceStates.testDatasource2.state).toEqual(['layer2']); + expect(state.datasourceStates.formBased.state).toEqual([]); + expect(state.datasourceStates.textBased.state).toEqual(['layer2']); expect(state.stagedPreview).not.toBeDefined(); }); it('removeLayer: should remove all layers from visualization that were removed by datasource', () => { const removedLayerId = 'other-removed-layer'; - const testDatasource3 = testDatasource('testDatasource3'); - testDatasource3.removeLayer = (layerIds: unknown, layerId: string) => ({ + const formBased3 = formBased('formBased3'); + formBased3.removeLayer = (layerIds: unknown, layerId: string) => ({ newState: (layerIds as string[]).filter((id: string) => id !== layerId), removedLayerIds: [layerId, removedLayerId], }); const localStore = makeLensStore({ preloadedState: { - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', datasourceStates: { ...datasourceStates, - testDatasource3: { + formBased3: { isLoading: false, state: [], }, @@ -681,7 +675,7 @@ describe('lensSlice', () => { }, storeDeps: mockStoreDeps({ visualizationMap: visualizationMap as unknown as VisualizationMap, - datasourceMap: { ...datasourceMap, testDatasource3 } as unknown as DatasourceMap, + datasourceMap: { ...datasourceMap, formBased3 } as unknown as DatasourceMap, }), }).store; @@ -700,7 +694,7 @@ describe('lensSlice', () => { describe('removing a dimension', () => { const colToRemove = 'col-id'; const otherCol = 'other-col-id'; - const datasourceId = 'testDatasource'; + const datasourceId = 'formBased'; interface DatasourceState { cols: string[]; diff --git a/x-pack/platform/plugins/shared/lens/public/state_management/load_initial.test.tsx b/x-pack/platform/plugins/shared/lens/public/state_management/load_initial.test.tsx index 21e6931ec952e..b5599b4074ddb 100644 --- a/x-pack/platform/plugins/shared/lens/public/state_management/load_initial.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/state_management/load_initial.test.tsx @@ -62,14 +62,14 @@ describe('Initializing the store', () => { it('should initialize initial datasource', async () => { const { store, deps } = makeLensStore({ preloadedState }); await loadInitialAppState(store, defaultProps); - expect(deps.datasourceMap.testDatasource.initialize).toHaveBeenCalled(); + expect(deps.datasourceMap.formBased.initialize).toHaveBeenCalled(); }); it('should have initialized the initial datasource and visualization', async () => { const { store, deps } = makeLensStore({ preloadedState }); await loadInitialAppState(store, { ...defaultProps, initialInput: undefined }); - expect(deps.datasourceMap.testDatasource.initialize).toHaveBeenCalled(); - expect(deps.datasourceMap.testDatasource2.initialize).not.toHaveBeenCalled(); + expect(deps.datasourceMap.formBased.initialize).toHaveBeenCalled(); + expect(deps.datasourceMap.textBased.initialize).not.toHaveBeenCalled(); expect(deps.visualizationMap.testVis.initialize).toHaveBeenCalled(); expect(deps.visualizationMap.testVis2.initialize).not.toHaveBeenCalled(); }); @@ -85,8 +85,8 @@ describe('Initializing the store', () => { title: '', state: { datasourceStates: { - testDatasource: datasource1State, - testDatasource2: datasource2State, + formBased: datasource1State, + textBased: datasource2State, }, visualization: {}, query: { query: '', language: 'lucene' }, @@ -114,9 +114,9 @@ describe('Initializing the store', () => { }, }, datasourceMap: { - testDatasource: createMockDatasource('testDatasource'), - testDatasource2: createMockDatasource('testDatasource2'), - testDatasource3: createMockDatasource('testDatasource3'), + formBased: createMockDatasource('formBased'), + textBased: createMockDatasource('textBased'), + formBased3: createMockDatasource('formBased3'), }, }); @@ -128,21 +128,21 @@ describe('Initializing the store', () => { await loadInitialAppState(store, defaultProps); const { datasourceMap } = storeDeps; - expect(datasourceMap.testDatasource.initialize).toHaveBeenCalledWith( + expect(datasourceMap.formBased.initialize).toHaveBeenCalledWith( datasource1State, [], undefined, [], {} ); - expect(datasourceMap.testDatasource2.initialize).toHaveBeenCalledWith( + expect(datasourceMap.textBased.initialize).toHaveBeenCalledWith( datasource2State, [], undefined, [], {} ); - expect(datasourceMap.testDatasource3.initialize).not.toHaveBeenCalled(); + expect(datasourceMap.formBased3.initialize).not.toHaveBeenCalled(); expect(store.getState()).toMatchSnapshot(); }); @@ -176,7 +176,7 @@ describe('Initializing the store', () => { state: {}, selectedLayerId: null, }, - datasourceStates: { testDatasource: { isLoading: false, state: {} } }, + datasourceStates: { formBased: { isLoading: false, state: {} } }, }, }); @@ -187,9 +187,9 @@ describe('Initializing the store', () => { state: {}, selectedLayerId: null, }, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', datasourceStates: { - testDatasource: { isLoading: false, state: {} }, + formBased: { isLoading: false, state: {} }, }, }), }); @@ -207,10 +207,10 @@ describe('Initializing the store', () => { activeId: 'testVis', selectedLayerId: null, }, - activeDatasourceId: 'testDatasource2', // resets to first on the list + activeDatasourceId: 'textBased', // resets to first on the list datasourceStates: { - testDatasource: { isLoading: false, state: undefined }, // state resets to undefined - testDatasource2: { + formBased: { isLoading: false, state: undefined }, // state resets to undefined + textBased: { state: {}, // initializes first in the map }, }, @@ -249,7 +249,7 @@ describe('Initializing the store', () => { }), query: defaultDoc.state.query, isLoading: false, - activeDatasourceId: 'testDatasource', + activeDatasourceId: 'formBased', filters: mockFilters, }), }); diff --git a/x-pack/platform/plugins/shared/lens/public/trigger_actions/open_lens_config/in_app_embeddable_edit/in_app_embeddable_edit_action.test.tsx b/x-pack/platform/plugins/shared/lens/public/trigger_actions/open_lens_config/in_app_embeddable_edit/in_app_embeddable_edit_action.test.tsx index cb056ffc7a987..efbcf64afcf3b 100644 --- a/x-pack/platform/plugins/shared/lens/public/trigger_actions/open_lens_config/in_app_embeddable_edit/in_app_embeddable_edit_action.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/trigger_actions/open_lens_config/in_app_embeddable_edit/in_app_embeddable_edit_action.test.tsx @@ -29,7 +29,7 @@ describe('inapp editing of Lens embeddable', () => { query: { esql: 'from test' }, filters: [{ query: { match_phrase: { src: 'test' } }, meta: { index: 'index-pattern-0' } }], datasourceStates: { - testDatasource: 'datasource', + formBased: 'datasource', }, visualization: {}, }, diff --git a/x-pack/platform/plugins/shared/lens/public/utils.ts b/x-pack/platform/plugins/shared/lens/public/utils.ts index 884e49bfdc8dd..fd3a6569c6c06 100644 --- a/x-pack/platform/plugins/shared/lens/public/utils.ts +++ b/x-pack/platform/plugins/shared/lens/public/utils.ts @@ -33,6 +33,7 @@ import type { UserMessage, DatasourceStates, VisualizationState, + SupportedDatasourceId, TriggerEvent, } from '@kbn/lens-common'; import { @@ -92,13 +93,17 @@ export function getTimeZone(uiSettings: IUiSettingsClient) { return configuredTimeZone; } -export function getActiveDatasourceIdFromDoc(doc?: LensDocument) { + +export function getActiveDatasourceIdFromDoc(doc?: LensDocument): SupportedDatasourceId | null { if (!doc) { return null; } const [firstDatasourceFromDoc] = Object.keys(doc.state.datasourceStates); - return firstDatasourceFromDoc || null; + if (firstDatasourceFromDoc === 'formBased' || firstDatasourceFromDoc === 'textBased') { + return firstDatasourceFromDoc; + } + return null; } export function getActiveVisualizationIdFromDoc(doc?: LensDocument) { diff --git a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/visualization.test.tsx b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/visualization.test.tsx index 59ece7d4507ab..d808b48bfbf1f 100644 --- a/x-pack/platform/plugins/shared/lens/public/visualizations/xy/visualization.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/visualizations/xy/visualization.test.tsx @@ -2946,7 +2946,7 @@ describe('xy_visualization', () => { // current incompatibility is only for date and numeric histograms as xAccessors const datasourceLayers = { first: mockDatasource.publicAPIMock, - second: createMockDatasource('testDatasource').publicAPIMock, + second: createMockDatasource('formBased').publicAPIMock, }; datasourceLayers.first.getOperationForColumnId = jest.fn((id: string) => id === 'a' @@ -3003,7 +3003,7 @@ describe('xy_visualization', () => { // current incompatibility is only for date and numeric histograms as xAccessors const datasourceLayers = { first: mockDatasource.publicAPIMock, - second: createMockDatasource('testDatasource').publicAPIMock, + second: createMockDatasource('formBased').publicAPIMock, }; datasourceLayers.first.getOperationForColumnId = jest.fn((id: string) => id === 'a' From 0a2238907c0c52ba5f29e884e11319a8be7f4dbe Mon Sep 17 00:00:00 2001 From: "Walter M. Rafelsberger" Date: Fri, 30 Jan 2026 13:55:41 +0100 Subject: [PATCH 3/5] fix tests --- .../lens_configuration_flyout.test.tsx | 14 ++++++++++---- .../in_app_embeddable_edit_action.test.tsx | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.test.tsx b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.test.tsx index 86cb5fc74338f..2cc35c7afc25c 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/lens_configuration_flyout.test.tsx @@ -93,12 +93,17 @@ jest.mock('@kbn/esql-utils', () => { }; }); +// Shared state object for reference equality in isEqual comparisons +const mockFormBasedState = { layers: {} }; +// Different state to simulate changes detected +const mockFormBasedStateChanged = { layers: { layer1: {} } }; + const lensAttributes = { title: 'test', visualizationType: 'testVis', state: { datasourceStates: { - formBased: {}, + formBased: mockFormBasedStateChanged, }, visualization: {}, filters: [], @@ -173,7 +178,7 @@ describe('LensEditConfigurationFlyout', () => { datasourceStates: { formBased: { isLoading: false, - state: 'state', + state: mockFormBasedState, }, }, activeDatasourceId: 'formBased', @@ -273,7 +278,7 @@ describe('LensEditConfigurationFlyout', () => { title: 'test', visualizationType: 'testVis', state: { - datasourceStates: { formBased: 'state' }, + datasourceStates: { formBased: mockFormBasedState }, visualization: {}, filters: [], query: { esql: 'from index1 | limit 10' }, @@ -350,7 +355,8 @@ describe('LensEditConfigurationFlyout', () => { saveByRef: saveByRefSpy, attributes: lensAttributes, }; - newProps.attributes.state.datasourceStates.formBased = 'state'; + // Set formBased to match the preloaded Redux state so no changes are detected + newProps.attributes.state.datasourceStates.formBased = mockFormBasedState; await renderConfigFlyout(newProps); expect(screen.getByRole('button', { name: /apply and close/i })).toBeDisabled(); }); diff --git a/x-pack/platform/plugins/shared/lens/public/trigger_actions/open_lens_config/in_app_embeddable_edit/in_app_embeddable_edit_action.test.tsx b/x-pack/platform/plugins/shared/lens/public/trigger_actions/open_lens_config/in_app_embeddable_edit/in_app_embeddable_edit_action.test.tsx index efbcf64afcf3b..be369dffa9ebd 100644 --- a/x-pack/platform/plugins/shared/lens/public/trigger_actions/open_lens_config/in_app_embeddable_edit/in_app_embeddable_edit_action.test.tsx +++ b/x-pack/platform/plugins/shared/lens/public/trigger_actions/open_lens_config/in_app_embeddable_edit/in_app_embeddable_edit_action.test.tsx @@ -29,7 +29,7 @@ describe('inapp editing of Lens embeddable', () => { query: { esql: 'from test' }, filters: [{ query: { match_phrase: { src: 'test' } }, meta: { index: 'index-pattern-0' } }], datasourceStates: { - formBased: 'datasource', + formBased: { layers: {} }, }, visualization: {}, }, From 8fb4d6cc3ca2fcd2a3fbb48d9acc101dac30b154 Mon Sep 17 00:00:00 2001 From: "Walter M. Rafelsberger" Date: Fri, 30 Jan 2026 14:19:05 +0100 Subject: [PATCH 4/5] revert too aggressive rename --- .../app_plugin/show_underlying_data.test.ts | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/x-pack/platform/plugins/shared/lens/public/app_plugin/show_underlying_data.test.ts b/x-pack/platform/plugins/shared/lens/public/app_plugin/show_underlying_data.test.ts index e568956c07355..4c024f9cede52 100644 --- a/x-pack/platform/plugins/shared/lens/public/app_plugin/show_underlying_data.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/app_plugin/show_underlying_data.test.ts @@ -340,7 +340,7 @@ describe('combineQueryAndFilters', () => { { language: 'kuery', query: 'myfield: *' }, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { kuery: [], lucene: [] }, disabled: { kuery: [], lucene: [] } }, }, @@ -356,7 +356,7 @@ describe('combineQueryAndFilters', () => { { language: 'kuery', query: 'myfield: *' }, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { kuery: [[{ language: 'kuery', query: 'otherField: *' }]], lucene: [] }, @@ -378,7 +378,7 @@ describe('combineQueryAndFilters', () => { undefined, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { kuery: [[{ language: 'kuery', query: 'otherField: *' }]], lucene: [] }, @@ -398,7 +398,7 @@ describe('combineQueryAndFilters', () => { undefined, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { @@ -436,7 +436,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: 'myField' }, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { @@ -478,7 +478,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (kuery)', disabled: false, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -518,14 +518,14 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Existing kuery filters', disabled: false, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, } as Filter, ], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { @@ -566,7 +566,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Existing kuery filters', disabled: false, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -590,7 +590,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (lucene)', disabled: false, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -609,7 +609,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: 'myField' }, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { @@ -650,7 +650,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (kuery)', disabled: false, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -672,7 +672,7 @@ describe('combineQueryAndFilters', () => { ], [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { @@ -736,7 +736,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (kuery)', disabled: false, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -758,7 +758,7 @@ describe('combineQueryAndFilters', () => { [{ language: 'lucene', query: '' }], [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { @@ -778,7 +778,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: '' }, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { @@ -798,7 +798,7 @@ describe('combineQueryAndFilters', () => { undefined, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { @@ -850,14 +850,14 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Existing kuery filters', disabled: false, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, } as Filter, ], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { enabled: { @@ -912,7 +912,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Existing kuery filters', disabled: false, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -937,7 +937,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'Lens context (lucene)', disabled: false, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -957,7 +957,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: 'myField' }, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { disabled: { @@ -991,7 +991,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'anotherField (lucene)', disabled: true, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -1022,7 +1022,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'myfield: *', disabled: true, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -1041,7 +1041,7 @@ describe('combineQueryAndFilters', () => { undefined, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { disabled: { @@ -1085,7 +1085,7 @@ describe('combineQueryAndFilters', () => { meta: { alias: 'myfield: *abc*', disabled: true, - index: 'formBased', + index: 'testDatasource', negate: false, type: 'custom', }, @@ -1104,7 +1104,7 @@ describe('combineQueryAndFilters', () => { { language: 'lucene', query: 'myField' }, [], { - id: 'formBased', + id: 'testDatasource', columns: [], filters: { disabled: { @@ -1143,7 +1143,7 @@ describe('combineQueryAndFilters', () => { must_not: [], }, meta: { - index: 'formBased', + index: 'testDatasource', type: 'custom', disabled: false, negate: false, @@ -1167,7 +1167,7 @@ describe('combineQueryAndFilters', () => { must_not: [], }, meta: { - index: 'formBased', + index: 'testDatasource', type: 'custom', disabled: true, negate: false, @@ -1198,7 +1198,7 @@ describe('combineQueryAndFilters', () => { must_not: [], }, meta: { - index: 'formBased', + index: 'testDatasource', type: 'custom', disabled: true, negate: false, From 732fcea2a25f8aa261e114c1be3b127084e5dcf9 Mon Sep 17 00:00:00 2001 From: "Walter M. Rafelsberger" Date: Fri, 30 Jan 2026 15:16:27 +0100 Subject: [PATCH 5/5] tweak tests --- .../editor_frame/suggestion_helpers.test.ts | 96 ++++++++++--------- .../state_management/lens_slice.test.ts | 1 + 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts index 44a0014e93e86..1d0bc04831f54 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_helpers.test.ts @@ -38,11 +38,11 @@ let dataViews: DataViewsState; beforeEach(() => { datasourceMap = { - mock: createMockDatasource('a'), + formBased: createMockDatasource('formBased'), }; datasourceStates = { - mock: { + formBased: { isLoading: false, state: {}, }, @@ -54,7 +54,7 @@ beforeEach(() => { describe('suggestion helpers', () => { it('should return suggestions array', () => { const mockVisualization = createMockVisualization(); - datasourceMap.mock.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ generateSuggestion(), ]); const suggestedState = {}; @@ -86,7 +86,7 @@ describe('suggestion helpers', () => { it('should concatenate suggestions from all visualizations', () => { const mockVisualization1 = createMockVisualization(); const mockVisualization2 = createMockVisualization(); - datasourceMap.mock.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ generateSuggestion(), ]); const visualizationMap = { @@ -131,7 +131,9 @@ describe('suggestion helpers', () => { }); it('should call getDatasourceSuggestionsForField when a field is passed', () => { - datasourceMap.mock.getDatasourceSuggestionsForField.mockReturnValue([generateSuggestion()]); + datasourceMap.formBased.getDatasourceSuggestionsForField.mockReturnValue([ + generateSuggestion(), + ]); const droppedField = {}; const visualizationMap = { testVis: createMockVisualization(), @@ -145,8 +147,8 @@ describe('suggestion helpers', () => { field: droppedField, dataViews, }); - expect(datasourceMap.mock.getDatasourceSuggestionsForField).toHaveBeenCalledWith( - datasourceStates.mock.state, + expect(datasourceMap.formBased.getDatasourceSuggestionsForField).toHaveBeenCalledWith( + datasourceStates.formBased.state, droppedField, expect.any(Function), dataViews.indexPatterns @@ -157,19 +159,19 @@ describe('suggestion helpers', () => { // but the algorithm handles N datasources generically. it('should call getDatasourceSuggestionsForField from all datasources with a state', () => { const multiDatasourceStates = { - mock: { + formBased: { isLoading: false, state: {}, }, - mock2: { + textBased: { isLoading: false, state: {}, }, }; const multiDatasourceMap = { - mock: createMockDatasource('a'), - mock2: createMockDatasource('a'), - mock3: createMockDatasource('a'), + formBased: createMockDatasource('formBased'), + textBased: createMockDatasource('textBased'), + thirdDatasource: createMockDatasource('thirdDatasource'), }; const visualizationMap = { testVis: createMockVisualization(), @@ -184,23 +186,25 @@ describe('suggestion helpers', () => { field: droppedField, dataViews, }); - expect(multiDatasourceMap.mock.getDatasourceSuggestionsForField).toHaveBeenCalledWith( - multiDatasourceStates.mock.state, + expect(multiDatasourceMap.formBased.getDatasourceSuggestionsForField).toHaveBeenCalledWith( + multiDatasourceStates.formBased.state, droppedField, expect.any(Function), dataViews.indexPatterns ); - expect(multiDatasourceMap.mock2.getDatasourceSuggestionsForField).toHaveBeenCalledWith( - multiDatasourceStates.mock2.state, + expect(multiDatasourceMap.textBased.getDatasourceSuggestionsForField).toHaveBeenCalledWith( + multiDatasourceStates.textBased.state, droppedField, expect.any(Function), dataViews.indexPatterns ); - expect(multiDatasourceMap.mock3.getDatasourceSuggestionsForField).not.toHaveBeenCalled(); + expect( + multiDatasourceMap.thirdDatasource.getDatasourceSuggestionsForField + ).not.toHaveBeenCalled(); }); it('should call getDatasourceSuggestionsForVisualizeField when a visualizeTriggerField is passed', () => { - datasourceMap.mock.getDatasourceSuggestionsForVisualizeField.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsForVisualizeField.mockReturnValue([ generateSuggestion(), ]); @@ -220,8 +224,8 @@ describe('suggestion helpers', () => { }, dataViews, }); - expect(datasourceMap.mock.getDatasourceSuggestionsForVisualizeField).toHaveBeenCalledWith( - datasourceStates.mock.state, + expect(datasourceMap.formBased.getDatasourceSuggestionsForVisualizeField).toHaveBeenCalledWith( + datasourceStates.formBased.state, '1', 'test', dataViews.indexPatterns @@ -232,19 +236,19 @@ describe('suggestion helpers', () => { // but the algorithm handles N datasources generically. it('should call getDatasourceSuggestionsForVisualizeField from all datasources with a state', () => { const multiDatasourceStates = { - mock: { + formBased: { isLoading: false, state: {}, }, - mock2: { + textBased: { isLoading: false, state: {}, }, }; const multiDatasourceMap = { - mock: createMockDatasource('a'), - mock2: createMockDatasource('a'), - mock3: createMockDatasource('a'), + formBased: createMockDatasource('formBased'), + textBased: createMockDatasource('textBased'), + thirdDatasource: createMockDatasource('thirdDatasource'), }; const visualizeTriggerField = { dataViewSpec: { id: '1' }, @@ -263,27 +267,31 @@ describe('suggestion helpers', () => { visualizeTriggerFieldContext: visualizeTriggerField, dataViews, }); - expect(multiDatasourceMap.mock.getDatasourceSuggestionsForVisualizeField).toHaveBeenCalledWith( - multiDatasourceStates.mock.state, + expect( + multiDatasourceMap.formBased.getDatasourceSuggestionsForVisualizeField + ).toHaveBeenCalledWith( + multiDatasourceStates.formBased.state, '1', 'test', dataViews.indexPatterns ); - expect(multiDatasourceMap.mock2.getDatasourceSuggestionsForVisualizeField).toHaveBeenCalledWith( - multiDatasourceStates.mock2.state, + expect( + multiDatasourceMap.textBased.getDatasourceSuggestionsForVisualizeField + ).toHaveBeenCalledWith( + multiDatasourceStates.textBased.state, '1', 'test', dataViews.indexPatterns ); expect( - multiDatasourceMap.mock3.getDatasourceSuggestionsForVisualizeField + multiDatasourceMap.thirdDatasource.getDatasourceSuggestionsForVisualizeField ).not.toHaveBeenCalled(); }); it('should rank the visualizations by score', () => { const mockVisualization1 = createMockVisualization(); const mockVisualization2 = createMockVisualization(); - datasourceMap.mock.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ generateSuggestion(), ]); const visualizationMap = { @@ -344,7 +352,7 @@ describe('suggestion helpers', () => { layerId: 'first', changeType: 'unchanged', }; - datasourceMap.mock.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ { state: {}, table: table1, keptLayerIds: ['first'] }, { state: {}, table: table2, keptLayerIds: ['first'] }, ]); @@ -371,7 +379,7 @@ describe('suggestion helpers', () => { const mockVisualization2 = createMockVisualization(); const tableState1 = {}; const tableState2 = {}; - datasourceMap.mock.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ generateSuggestion(tableState1), generateSuggestion(tableState2), ]); @@ -422,18 +430,18 @@ describe('suggestion helpers', () => { dataViews, }); expect(suggestions[0].datasourceState).toBe(tableState1); - expect(suggestions[0].datasourceId).toBe('mock'); + expect(suggestions[0].datasourceId).toBe('formBased'); expect(suggestions[1].datasourceState).toBe(tableState2); - expect(suggestions[1].datasourceId).toBe('mock'); + expect(suggestions[1].datasourceId).toBe('formBased'); expect(suggestions[2].datasourceState).toBe(tableState2); - expect(suggestions[2].datasourceId).toBe('mock'); + expect(suggestions[2].datasourceId).toBe('formBased'); }); it('should pass the state of the currently active visualization to getSuggestions', () => { const mockVisualization1 = createMockVisualization(); const mockVisualization2 = createMockVisualization(); const currentState = {}; - datasourceMap.mock.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ generateSuggestion(0), generateSuggestion(1), ]); @@ -473,7 +481,7 @@ describe('suggestion helpers', () => { name: 'mock', }, }; - datasourceMap.mock.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ generateSuggestion(0), generateSuggestion(1), ]); @@ -513,7 +521,7 @@ describe('suggestion helpers', () => { }, }; mockVisualization1.getMainPalette = jest.fn(() => mainPalette); - datasourceMap.mock.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsFromCurrentState.mockReturnValue([ generateSuggestion(0), generateSuggestion(1), ]); @@ -544,7 +552,7 @@ describe('suggestion helpers', () => { let mockDatasourceState: unknown; let defaultParams: Parameters; beforeEach(() => { - datasourceMap.mock.getDatasourceSuggestionsForField.mockReturnValue([ + datasourceMap.formBased.getDatasourceSuggestionsForField.mockReturnValue([ { state: {}, table: { @@ -596,9 +604,9 @@ describe('suggestion helpers', () => { }, }, { activeId: 'testVis', state: {}, selectedLayerId: null }, - { a: { state: mockDatasourceState, isLoading: false } }, + { formBased: { state: mockDatasourceState, isLoading: false } }, { testVis: mockVisualization1 }, - datasourceMap.mock, + datasourceMap.formBased, { id: 'myfield', humanData: { label: 'myfieldLabel' } }, dataViews, ]; @@ -607,7 +615,7 @@ describe('suggestion helpers', () => { it('should return top suggestion for field', () => { const result = getTopSuggestionForField(...defaultParams); expect(result!.title).toEqual('top suggestion'); - expect(datasourceMap.mock.getDatasourceSuggestionsForField).toHaveBeenCalledWith( + expect(datasourceMap.formBased.getDatasourceSuggestionsForField).toHaveBeenCalledWith( mockDatasourceState, { id: 'myfield', @@ -665,7 +673,7 @@ describe('suggestion helpers', () => { }); it('should return nothing if datasource does not produce suggestions', () => { - datasourceMap.mock.getDatasourceSuggestionsForField.mockReturnValue([]); + datasourceMap.formBased.getDatasourceSuggestionsForField.mockReturnValue([]); defaultParams[3] = { testVis: { ...mockVisualization1, getSuggestions: () => [] }, vis2: mockVisualization2, diff --git a/x-pack/platform/plugins/shared/lens/public/state_management/lens_slice.test.ts b/x-pack/platform/plugins/shared/lens/public/state_management/lens_slice.test.ts index be246784df48e..21066fbd01bed 100644 --- a/x-pack/platform/plugins/shared/lens/public/state_management/lens_slice.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/state_management/lens_slice.test.ts @@ -643,6 +643,7 @@ describe('lensSlice', () => { it('removeLayer: should remove all layers from visualization that were removed by datasource', () => { const removedLayerId = 'other-removed-layer'; + // formBased3 is an artificial test datasource. Production only supports formBased and textBased. const formBased3 = formBased('formBased3'); formBased3.removeLayer = (layerIds: unknown, layerId: string) => ({ newState: (layerIds as string[]).filter((id: string) => id !== layerId),