Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ describe('Lens App', () => {
},
selectedLayerId: null,
},
activeDatasourceId: 'testDatasource',
activeDatasourceId: 'formBased',
datasourceStates: {
testDatasource: {
formBased: {
isLoading: false,
state: { datasourceState: true },
},
Expand Down Expand Up @@ -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,
},
},
})
Expand Down Expand Up @@ -352,8 +352,8 @@ describe('Lens App', () => {
await renderApp({
datasourceMapOverride: {
...datasourceMap,
testDatasource: {
...datasourceMap.testDatasource,
formBased: {
...datasourceMap.formBased,
isTimeBased: jest.fn((_state, _indexPatterns) => true),
},
},
Expand All @@ -373,8 +373,8 @@ describe('Lens App', () => {
await renderApp({
datasourceMapOverride: {
...datasourceMap,
testDatasource: {
...datasourceMap.testDatasource,
formBased: {
...datasourceMap.formBased,
isTimeBased: jest.fn((_state, _indexPatterns) => false),
},
},
Expand Down Expand Up @@ -1403,7 +1403,7 @@ describe('Lens App', () => {
state: {
...localDoc.state,
datasourceStates: {
testDatasource: 'datasource',
formBased: 'datasource',
},
visualization: {},
},
Expand All @@ -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
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
EuiBasicTableColumn,
EuiConfirmModalProps,
EuiTableSelectionType,
IconType,
} from '@elastic/eui';
import {
EuiBasicTable,
Expand All @@ -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<LensLayerType, 'metricTrendline'>;

/**
* Conversion data from generateEsqlQuery.
*/
export interface EsqlConversionData {
esAggsIdMap: Record<string, OriginalColumn[]>;
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<LayerType, (count: number) => string> = {
data: (count: number) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, OriginalColumn[]>;
partialRows: boolean;
}

/**
* Lens layer types that can appear in the ES|QL conversion UI.
* Excludes internal metricTrendline sub-layer.
*/
export type LayerType = Exclude<LensLayerType, 'metricTrendline'>;

/**
* 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
);
Expand All @@ -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 },
})
Expand All @@ -62,7 +62,7 @@ describe('Lens flyout', () => {
// testing
store.dispatch(
updateDatasourceState({
datasourceId: 'testDatasource2',
datasourceId: 'textBased',
newDatasourceState: {},
})
);
Expand Down
Loading
Loading