diff --git a/dev_docs/lens/config_api.mdx b/dev_docs/lens/config_api.mdx index 624d80b651501..f2362434b1498 100644 --- a/dev_docs/lens/config_api.mdx +++ b/dev_docs/lens/config_api.mdx @@ -12,9 +12,9 @@ tags: ['kibana', 'dev', 'lens', 'introduction'] The Lens Config Builder API provides a streamlined and flexible interface for developers to construct and integrate Lens configurations within their applications. Lens, as a powerful visualization tool in Kibana, enables users to create, visualize, and analyze data in diverse and complex ways. This API aims to simplify the process of generating these visualizations programmatically, allowing for dynamic and customizable integration points with Lens. By abstracting the complexities of Lens configuration details, developers can focus on delivering rich data visualization experiences tailored to their application's needs. ``` -import LensConfigBuilder, LensConfig from '@kbn/lens-embeddable-utils/config_builder'; +import { LensConfigBuilder, LensApiConfig } from '@kbn/lens-embeddable-utils'; -const config: LensConfig = { +const config: LensApiConfig = { chartType: 'metric', title: 'my metric chart', dataset: { esql: 'from my_index | stats sum=sum(my_field)'} @@ -22,7 +22,7 @@ const config: LensConfig = { } const configBuilder = new LensConfigBuilder(dataViewsAPI, lensFormulaAPI); -const lensConfig = configBuilder(config, { +const lensConfig = configBuilder(config, { timeRange: { from: 'now-30d', to: 'now', type: 'relative' }, embeddable: true, } @@ -46,11 +46,11 @@ The constructor requires two parameters: #### build Method -The `build` method is the primary method used to generate a Lens configuration. It accepts a `LensConfig` object, detailing the type of chart and its options, and an optional `LensConfigOptions` object for additional configuration options like filters, queries, and time ranges. +The `build` method is the primary method used to generate a Lens configuration. It accepts a `LensApiConfig` object, detailing the type of chart and its options, and an optional `LensConfigOptions` object for additional configuration options like filters, queries, and time ranges. **Parameters:** -- `config`: A `LensConfig` object specifying the chart type and its configuration. +- `config`: A `LensApiConfig` object specifying the chart type and its configuration. - `options` (optional): A `LensConfigOptions` object providing additional settings such as embeddable options, time range overrides, filters, and queries. **Returns:** A Promise resolving to either `LensAttributes` or `LensEmbeddableInput`, depending on the options provided. This allows the generated configuration to be directly used within Kibana Lens visualizations. diff --git a/src/platform/packages/shared/kbn-lens-common-2/README.md b/src/platform/packages/shared/kbn-lens-common-2/README.md index 890b9d079f825..2d2a07bc11931 100644 --- a/src/platform/packages/shared/kbn-lens-common-2/README.md +++ b/src/platform/packages/shared/kbn-lens-common-2/README.md @@ -1,7 +1,7 @@ # @kbn/lens-common-2 -Split off of `@kbn/lens-common` because of circular dependence issues importing LensApiSchemaType. +Split off of `@kbn/lens-common` because of circular dependence issues importing LensApiConfig. ```ts -import type { LensApiSchemaType } from '@kbn/lens-embeddable-utils'; +import type { LensApiConfig } from '@kbn/lens-embeddable-utils'; ``` diff --git a/src/platform/packages/shared/kbn-lens-common-2/index.ts b/src/platform/packages/shared/kbn-lens-common-2/index.ts index 9021d56fc2715..36ddcfb7d1229 100644 --- a/src/platform/packages/shared/kbn-lens-common-2/index.ts +++ b/src/platform/packages/shared/kbn-lens-common-2/index.ts @@ -26,7 +26,7 @@ import type { SerializedTitles, SerializedTimeRange, } from '@kbn/presentation-publishing'; -import type { LensApiSchemaType } from '@kbn/lens-embeddable-utils'; +import type { LensApiConfig } from '@kbn/lens-embeddable-utils'; import type { Simplify } from '@kbn/chart-expressions-common'; import type { LensByValueBase, @@ -51,7 +51,7 @@ type LensPersistableState = SerializedTitles & // title, description, hide_title export type LensByValueSerializedAPIConfig = LensPersistableState & { // Temporarily allow both old and new attributes until all chart types are supported and feature flag removed - attributes: LensApiSchemaType | LensByValueBase['attributes']; + attributes: LensApiConfig | LensByValueBase['attributes']; ref_id?: string; // really should be never but creates type issues }; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/config_builder.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/config_builder.ts index d221104bd9d78..bd8e84f252e0a 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/config_builder.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/config_builder.ts @@ -53,7 +53,7 @@ import { fromAPItoLensState as fromDatatableAPItoLensState, fromLensStateToAPI as fromDatatableLensStateToAPI, } from './transforms/charts/datatable'; -import type { LensApiState } from './schema'; +import type { LensApiConfig } from './schema'; import { filtersAndQueryToApiFormat, filtersAndQueryToLensState } from './transforms/utils'; import { isLensLegacyFormat } from './utils'; @@ -75,7 +75,7 @@ const compatibilityMap: Record = { type ChartTypeLike = | Pick | Pick - | Pick + | Pick | { visualizationType: null | undefined } | undefined; @@ -225,7 +225,7 @@ export class LensConfigBuilder { return chartState as LensAttributes; } - fromAPIFormat(config: LensApiState): LensAttributes { + fromAPIFormat(config: LensApiConfig): LensAttributes { const chartType = config.type; if (!(chartType in this.apiConvertersByChart)) { @@ -253,7 +253,7 @@ export class LensConfigBuilder { }; } - toAPIFormat(config: LensAttributes): LensApiState { + toAPIFormat(config: LensAttributes): LensApiConfig { const visType = config.visualizationType; const type = compatibilityMap[visType] ?? visType; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/index.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/index.ts index 402723b23470a..be3818fa2bd83 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/index.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/index.ts @@ -37,7 +37,15 @@ export type { LensBaseLayer, LensXYConfigBase, LensBreakdownConfig, + LensYBoundsConfig, } from './types'; -export { lensApiStateSchema, lensApiStateSchemaNoESQL } from './schema'; -export type { LensApiState as LensApiSchemaType } from './schema'; +export { + isLensESQLConfig, + isLensDSLConfig, + isLensAPIFormat, + isLensLegacyFormat, + isLensLegacyAttributes, +} from './utils'; + +export * from './schema'; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.test.ts index 70b76d0d796d4..074336e2e1be0 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.test.ts @@ -8,11 +8,11 @@ */ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; -import type { DatatableState } from './datatable'; -import { datatableStateSchema } from './datatable'; +import type { DatatableConfig } from './datatable'; +import { datatableConfigSchema } from './datatable'; -type DefaultDatatableConfig = Pick; -type DatatableWithoutDefaultsConfig = Omit; +type DefaultDatatableConfig = Pick; +type DatatableWithoutDefaultsConfig = Omit; describe('Datatable Schema', () => { const baseDatatableConfig: Omit = { @@ -40,7 +40,7 @@ describe('Datatable Schema', () => { ], }; - const validated = datatableStateSchema.validate(input); + const validated = datatableConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -80,7 +80,7 @@ describe('Datatable Schema', () => { ], }; - const validated = datatableStateSchema.validate(input); + const validated = datatableConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -127,7 +127,7 @@ describe('Datatable Schema', () => { }, }; - const validated = datatableStateSchema.validate(input); + const validated = datatableConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -174,7 +174,7 @@ describe('Datatable Schema', () => { }, }; - const validated = datatableStateSchema.validate(input); + const validated = datatableConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -222,7 +222,7 @@ describe('Datatable Schema', () => { }, }; - const validated = datatableStateSchema.validate(input); + const validated = datatableConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -275,7 +275,7 @@ describe('Datatable Schema', () => { }, }; - const validated = datatableStateSchema.validate(input); + const validated = datatableConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); @@ -300,7 +300,7 @@ describe('Datatable Schema', () => { ], }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws on empty metrics for non-esql', () => { @@ -318,7 +318,7 @@ describe('Datatable Schema', () => { ], }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws on empty rows', () => { @@ -344,7 +344,7 @@ describe('Datatable Schema', () => { ], }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws on empty split_metrics_by', () => { @@ -363,7 +363,7 @@ describe('Datatable Schema', () => { split_metrics_by: [], }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws when using invalid density height type', () => { @@ -390,7 +390,7 @@ describe('Datatable Schema', () => { }, }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws when using invalid density mode', () => { @@ -415,7 +415,7 @@ describe('Datatable Schema', () => { }, }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws when using invalid height type', () => { @@ -436,7 +436,7 @@ describe('Datatable Schema', () => { styling: { density: { height: { header: { type: 'invalid' } } } }, }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws when missing summary type', () => { @@ -457,7 +457,7 @@ describe('Datatable Schema', () => { ], }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws when using term buckets operation in an esql configuration', () => { @@ -480,7 +480,7 @@ describe('Datatable Schema', () => { rows: [{ operation: 'terms', fields: ['geo.dest'], limit: 10 }], }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws when esql datatable has no metrics and no rows', () => { @@ -492,7 +492,7 @@ describe('Datatable Schema', () => { }, }; - expect(() => datatableStateSchema.validate(input)).toThrow( + expect(() => datatableConfigSchema.validate(input)).toThrow( 'Datatable must have at least one column' ); }); @@ -512,7 +512,7 @@ describe('Datatable Schema', () => { ], }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws on empty rows array for esql', () => { @@ -530,7 +530,7 @@ describe('Datatable Schema', () => { rows: [], }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws when using invalid sorting index', () => { @@ -576,7 +576,7 @@ describe('Datatable Schema', () => { }, }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws when using invalid sorting index for pivoted_metric', () => { @@ -623,7 +623,7 @@ describe('Datatable Schema', () => { }, }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); it('throws when using invalid values length for pivoted_metric', () => { @@ -675,7 +675,7 @@ describe('Datatable Schema', () => { }, }; - expect(() => datatableStateSchema.validate(input)).toThrow(); + expect(() => datatableConfigSchema.validate(input)).toThrow(); }); }); @@ -764,7 +764,7 @@ describe('Datatable Schema', () => { ], }; - const validated = datatableStateSchema.validate(input); + const validated = datatableConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -852,7 +852,7 @@ describe('Datatable Schema', () => { ], }; - const validated = datatableStateSchema.validate(input); + const validated = datatableConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -890,7 +890,7 @@ describe('Datatable Schema', () => { ], }; - const validated = datatableStateSchema.validate(input); + const validated = datatableConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.ts index fbcc49e2e3126..f73f6794e85bf 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/datatable.ts @@ -221,7 +221,7 @@ const datatableStylingSchema = schema.object( } ); -const datatableStateCommonOptionsSchema = { +const datatableConfigCommonOptionsSchema = { /** * Where to apply the color (background, value or badge) */ @@ -241,8 +241,8 @@ const datatableStateCommonOptionsSchema = { ), }; -const datatableStateRowsOptionsNoESQLSchema = { - ...datatableStateCommonOptionsSchema, +const datatableConfigRowsOptionsNoESQLSchema = { + ...datatableConfigCommonOptionsSchema, /** * Alignment of the rows */ @@ -277,8 +277,8 @@ const datatableStateRowsOptionsNoESQLSchema = { collapse_by: schema.maybe(collapseBySchema), }; -const datatableStateRowsOptionsESQLSchema = { - ...datatableStateRowsOptionsNoESQLSchema, +const datatableConfigRowsOptionsESQLSchema = { + ...datatableConfigRowsOptionsNoESQLSchema, /** * Color configuration */ @@ -293,8 +293,8 @@ const datatableStateRowsOptionsESQLSchema = { ), }; -const datatableStateMetricsOptionsSchema = { - ...datatableStateCommonOptionsSchema, +const datatableConfigMetricsOptionsSchema = { + ...datatableConfigCommonOptionsSchema, /** * Color configuration */ @@ -397,7 +397,7 @@ function validateSortBy({ } } -export const datatableStateSchemaNoESQL = schema.object( +export const datatableConfigSchemaNoESQL = schema.object( { type: schema.literal('data_table'), ...sharedPanelInfoSchema, @@ -409,7 +409,7 @@ export const datatableStateSchemaNoESQL = schema.object( * Metric columns configuration, must define operation. */ metrics: schema.arrayOf( - mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps(datatableStateMetricsOptionsSchema), + mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps(datatableConfigMetricsOptionsSchema), { minSize: 1, maxSize: 1000, @@ -421,7 +421,7 @@ export const datatableStateSchemaNoESQL = schema.object( */ rows: schema.maybe( schema.arrayOf( - mergeAllBucketsWithChartDimensionSchema(datatableStateRowsOptionsNoESQLSchema), + mergeAllBucketsWithChartDimensionSchema(datatableConfigRowsOptionsNoESQLSchema), { minSize: 1, maxSize: 50, @@ -450,7 +450,7 @@ export const datatableStateSchemaNoESQL = schema.object( } ); -export const datatableStateSchemaESQL = schema.object( +export const datatableConfigSchemaESQL = schema.object( { type: schema.literal('data_table'), ...sharedPanelInfoSchema, @@ -462,7 +462,7 @@ export const datatableStateSchemaESQL = schema.object( */ metrics: schema.maybe( schema.arrayOf( - esqlColumnWithFormatSchema.extends(datatableStateMetricsOptionsSchema, { + esqlColumnWithFormatSchema.extends(datatableConfigMetricsOptionsSchema, { meta: { id: 'datatableESQLMetric', title: 'Datatable Metric (ES|QL)' }, }), { @@ -476,7 +476,7 @@ export const datatableStateSchemaESQL = schema.object( * Row configuration, optional operations. */ rows: schema.maybe( - schema.arrayOf(esqlColumnWithFormatSchema.extends(datatableStateRowsOptionsESQLSchema), { + schema.arrayOf(esqlColumnWithFormatSchema.extends(datatableConfigRowsOptionsESQLSchema), { minSize: 1, maxSize: 50, meta: { description: 'Array of operations to split the datatable rows by' }, @@ -514,8 +514,8 @@ export const datatableStateSchemaESQL = schema.object( } ); -export const datatableStateSchema = objectUnion( - [datatableStateSchemaNoESQL, datatableStateSchemaESQL], +export const datatableConfigSchema = objectUnion( + [datatableConfigSchemaNoESQL, datatableConfigSchemaESQL], { meta: { id: 'datatableChart', @@ -525,7 +525,6 @@ export const datatableStateSchema = objectUnion( } ); -export type DatatableState = TypeOf; -export type DatatableStateNoESQL = TypeOf; -export type DatatableStateESQL = TypeOf; -export type DatatableStyling = TypeOf; +export type DatatableConfig = TypeOf; +export type DatatableConfigNoESQL = TypeOf; +export type DatatableConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.test.ts index dab4d036ffea4..04da615ef232b 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.test.ts @@ -10,8 +10,8 @@ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; import type { ColorByValueType } from '../color'; -import type { GaugeState } from './gauge'; -import { gaugeStateSchema } from './gauge'; +import type { GaugeConfig } from './gauge'; +import { gaugeConfigSchema } from './gauge'; describe('Gauge Schema', () => { const baseGaugeConfig = { @@ -20,14 +20,14 @@ describe('Gauge Schema', () => { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'test-data-view', }, - } satisfies Partial; + } satisfies Partial; const defaultValues = { sampling: 1, ignore_global_filters: false, - } satisfies Partial; + } satisfies Partial; - type GaugeInput = Omit; + type GaugeInput = Omit; it('validates minimal configuration', () => { const input = { @@ -39,7 +39,7 @@ describe('Gauge Schema', () => { }, } satisfies GaugeInput; - const validated = gaugeStateSchema.validate(input); + const validated = gaugeConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -96,7 +96,7 @@ describe('Gauge Schema', () => { }, } satisfies GaugeInput; - const validated = gaugeStateSchema.validate(input); + const validated = gaugeConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); } }); @@ -116,7 +116,7 @@ describe('Gauge Schema', () => { }, } satisfies GaugeInput; - const validated = gaugeStateSchema.validate(input); + const validated = gaugeConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -136,7 +136,7 @@ describe('Gauge Schema', () => { }, } satisfies GaugeInput; - const validated = gaugeStateSchema.validate(input); + const validated = gaugeConfigSchema.validate(input); expect(validated.styling?.shape).toEqual({ type: 'bullet', orientation: 'horizontal', @@ -157,7 +157,7 @@ describe('Gauge Schema', () => { }, } satisfies GaugeInput; - const validated = gaugeStateSchema.validate(input); + const validated = gaugeConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -200,7 +200,7 @@ describe('Gauge Schema', () => { }, } satisfies GaugeInput; - const validated = gaugeStateSchema.validate(input); + const validated = gaugeConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -228,7 +228,7 @@ describe('Gauge Schema', () => { }, } satisfies GaugeInput; - expect(() => gaugeStateSchema.validate(input)).toThrow(); + expect(() => gaugeConfigSchema.validate(input)).toThrow(); }); it('throws on invalid operations as metric', () => { @@ -237,7 +237,7 @@ describe('Gauge Schema', () => { { operation: 'moving_average', window: 5, field: 'bytes' }, ]; for (const op of invalidOps) { - expect(() => gaugeStateSchema.validate({ ...baseGaugeConfig, metric: op })).toThrow(); + expect(() => gaugeConfigSchema.validate({ ...baseGaugeConfig, metric: op })).toThrow(); } }); @@ -257,7 +257,7 @@ describe('Gauge Schema', () => { }, } satisfies GaugeInput; - expect(() => gaugeStateSchema.validate(input)).toThrow(); + expect(() => gaugeConfigSchema.validate(input)).toThrow(); }); it('throws on invalid ticks value', () => { @@ -273,6 +273,6 @@ describe('Gauge Schema', () => { }, } satisfies GaugeInput; - expect(() => gaugeStateSchema.validate(input)).toThrow(); + expect(() => gaugeConfigSchema.validate(input)).toThrow(); }); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.ts index a24e56b1fc06c..54ff515b670d0 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/gauge.ts @@ -71,7 +71,7 @@ const gaugeStylingSchema = schema.object( } ); -const gaugeStateMetricInnerNoESQLOpsSchema = { +const gaugeConfigMetricInnerNoESQLOpsSchema = { /** * Minimum value for the gauge * Note: label, format and other visual options are ignored @@ -89,7 +89,7 @@ const gaugeStateMetricInnerNoESQLOpsSchema = { goal: schema.maybe(metricOperationDefinitionSchema), }; -const gaugeStateMetricInnerESQLOpsSchema = { +const gaugeConfigMetricInnerESQLOpsSchema = { /** * Minimum value for the gauge */ @@ -104,7 +104,7 @@ const gaugeStateMetricInnerESQLOpsSchema = { goal: schema.maybe(esqlColumnSchema), }; -const gaugeStateMetricOptionsSchema = { +const gaugeConfigMetricOptionsSchema = { /** * Title configuration */ @@ -160,7 +160,7 @@ const gaugeStateMetricOptionsSchema = { ), }; -export const gaugeStateSchemaNoESQL = schema.object( +export const gaugeConfigSchemaNoESQL = schema.object( { type: schema.literal('gauge'), ...sharedPanelInfoSchema, @@ -172,14 +172,14 @@ export const gaugeStateSchemaNoESQL = schema.object( * Primary value configuration, must define operation. */ metric: mergeAllMetricsWithChartDimensionSchema({ - ...gaugeStateMetricOptionsSchema, - ...gaugeStateMetricInnerNoESQLOpsSchema, + ...gaugeConfigMetricOptionsSchema, + ...gaugeConfigMetricInnerNoESQLOpsSchema, }), }, { meta: { id: 'gaugeNoESQL', title: 'Gauge Chart (DSL)' } } ); -export const gaugeStateSchemaESQL = schema.object( +export const gaugeConfigSchemaESQL = schema.object( { type: schema.literal('gauge'), ...sharedPanelInfoSchema, @@ -190,17 +190,17 @@ export const gaugeStateSchemaESQL = schema.object( * Primary value configuration, must define operation. */ metric: esqlColumnWithFormatSchema.extends({ - ...gaugeStateMetricOptionsSchema, - ...gaugeStateMetricInnerESQLOpsSchema, + ...gaugeConfigMetricOptionsSchema, + ...gaugeConfigMetricInnerESQLOpsSchema, }), }, { meta: { id: 'gaugeESQL', title: 'Gauge Chart (ES|QL)' } } ); -export const gaugeStateSchema = objectUnion([gaugeStateSchemaNoESQL, gaugeStateSchemaESQL], { +export const gaugeConfigSchema = objectUnion([gaugeConfigSchemaNoESQL, gaugeConfigSchemaESQL], { meta: { id: 'gaugeChart', title: 'Gauge Chart' }, }); -export type GaugeState = TypeOf; -export type GaugeStateNoESQL = TypeOf; -export type GaugeStateESQL = TypeOf; +export type GaugeConfig = TypeOf; +export type GaugeConfigNoESQL = TypeOf; +export type GaugeConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/heatmap.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/heatmap.ts index f1d17cf6bf326..eaba5908cdc71 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/heatmap.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/heatmap.ts @@ -84,7 +84,7 @@ const heatmapStylingSchema = schema.object( } ); -const heatmapSharedStateSchema = { +const heatmapSharedConfigSchema = { type: schema.literal('heatmap'), legend: schema.maybe( schema.object(legendSchemaProps, { @@ -145,17 +145,17 @@ const heatmapSharedStateSchema = { ), }; -const heatmapAxesStateSchemaProps = { +const heatmapAxesConfigSchemaProps = { x: bucketOperationDefinitionSchema, y: schema.maybe(bucketOperationDefinitionSchema), }; -const heatmapAxesStateESQLSchemaProps = { +const heatmapAxesConfigESQLSchemaProps = { x: esqlColumnWithFormatSchema, y: schema.maybe(esqlColumnWithFormatSchema), }; -const heatmapStateMetricOptionsSchemaProps = { +const heatmapConfigMetricOptionsSchemaProps = { color: schema.maybe( schema.oneOf([colorByValueSchema, autoColorSchema], { defaultValue: AUTO_COLOR, @@ -163,35 +163,38 @@ const heatmapStateMetricOptionsSchemaProps = { ), }; -export const heatmapStateSchemaNoESQL = schema.object( +export const heatmapConfigSchemaNoESQL = schema.object( { - ...heatmapSharedStateSchema, - ...heatmapAxesStateSchemaProps, + ...heatmapSharedConfigSchema, + ...heatmapAxesConfigSchemaProps, ...dslOnlyPanelInfoSchema, ...dataSourceSchema, styling: schema.maybe(heatmapStylingSchema), metric: mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps( - heatmapStateMetricOptionsSchemaProps + heatmapConfigMetricOptionsSchemaProps ), }, { meta: { id: 'heatmapNoESQL', title: 'Heatmap Chart (DSL)' } } ); -export const heatmapStateSchemaESQL = schema.object( +export const heatmapConfigSchemaESQL = schema.object( { - ...heatmapSharedStateSchema, - ...heatmapAxesStateESQLSchemaProps, + ...heatmapSharedConfigSchema, + ...heatmapAxesConfigESQLSchemaProps, ...dataSourceEsqlTableSchema, styling: schema.maybe(heatmapStylingSchema), - metric: esqlColumnWithFormatSchema.extends(heatmapStateMetricOptionsSchemaProps), + metric: esqlColumnWithFormatSchema.extends(heatmapConfigMetricOptionsSchemaProps), }, { meta: { id: 'heatmapESQL', title: 'Heatmap Chart (ES|QL)' } } ); -export const heatmapStateSchema = objectUnion([heatmapStateSchemaNoESQL, heatmapStateSchemaESQL], { - meta: { id: 'heatmapChart', title: 'Heatmap Chart' }, -}); +export const heatmapConfigSchema = objectUnion( + [heatmapConfigSchemaNoESQL, heatmapConfigSchemaESQL], + { + meta: { id: 'heatmapChart', title: 'Heatmap Chart' }, + } +); -export type HeatmapState = TypeOf; -export type HeatmapStateNoESQL = TypeOf; -export type HeatmapStateESQL = TypeOf; +export type HeatmapConfig = TypeOf; +export type HeatmapConfigNoESQL = TypeOf; +export type HeatmapConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.test.ts index 3009b6a45516f..7c3d083f95884 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.test.ts @@ -9,8 +9,8 @@ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; -import type { LegacyMetricState, LegacyMetricStateESQL } from './legacy_metric'; -import { legacyMetricStateSchema } from './legacy_metric'; +import type { LegacyMetricConfig, LegacyMetricConfigESQL } from './legacy_metric'; +import { legacyMetricConfigSchema } from './legacy_metric'; describe('Legacy Metric Schema', () => { const baseLegacyMetricConfig = { @@ -19,14 +19,14 @@ describe('Legacy Metric Schema', () => { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'test-data-view', }, - } satisfies Partial; + } satisfies Partial; const defaultValues = { sampling: 1, ignore_global_filters: false, - } satisfies Partial; + } satisfies Partial; - type LegacyMetricInput = Omit; + type LegacyMetricInput = Omit; describe('metric configuration', () => { it('validates base count metric operation', () => { @@ -39,7 +39,7 @@ describe('Legacy Metric Schema', () => { }, } satisfies LegacyMetricInput; - const validated = legacyMetricStateSchema.validate(input); + const validated = legacyMetricConfigSchema.validate(input); expect(validated.metric.size).toBeUndefined(); expect(validated.metric.labels).toBeUndefined(); expect(validated.metric.values).toBeUndefined(); @@ -64,7 +64,7 @@ describe('Legacy Metric Schema', () => { }, } satisfies LegacyMetricInput; - const validated = legacyMetricStateSchema.validate(input); + const validated = legacyMetricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -89,7 +89,7 @@ describe('Legacy Metric Schema', () => { }, } satisfies LegacyMetricInput; - const validated = legacyMetricStateSchema.validate(input); + const validated = legacyMetricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); @@ -104,7 +104,7 @@ describe('Legacy Metric Schema', () => { }, } satisfies LegacyMetricInput; - expect(() => legacyMetricStateSchema.validate(input)).toThrow(); + expect(() => legacyMetricConfigSchema.validate(input)).toThrow(); }); it('throws on invalid alignment value', () => { @@ -120,7 +120,7 @@ describe('Legacy Metric Schema', () => { }, } satisfies LegacyMetricInput; - expect(() => legacyMetricStateSchema.validate(input)).toThrow(); + expect(() => legacyMetricConfigSchema.validate(input)).toThrow(); }); it('throws on invalid size value', () => { @@ -133,7 +133,7 @@ describe('Legacy Metric Schema', () => { }, }; - expect(() => legacyMetricStateSchema.validate(input)).toThrow(); + expect(() => legacyMetricConfigSchema.validate(input)).toThrow(); }); it('throws on invalid apply_color_to value', () => { @@ -155,7 +155,7 @@ describe('Legacy Metric Schema', () => { }, } satisfies LegacyMetricInput; - expect(() => legacyMetricStateSchema.validate(input)).toThrow(); + expect(() => legacyMetricConfigSchema.validate(input)).toThrow(); }); it('throws when color by value is not absolute', () => { @@ -177,7 +177,7 @@ describe('Legacy Metric Schema', () => { }, } satisfies LegacyMetricInput; - expect(() => legacyMetricStateSchema.validate(input)).toThrow(); + expect(() => legacyMetricConfigSchema.validate(input)).toThrow(); }); }); @@ -208,7 +208,7 @@ describe('Legacy Metric Schema', () => { }, } satisfies LegacyMetricInput; - const validated = legacyMetricStateSchema.validate(input); + const validated = legacyMetricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -228,9 +228,9 @@ describe('Legacy Metric Schema', () => { labels: { alignment: 'top' }, values: { alignment: 'center' }, }, - } satisfies Omit; + } satisfies Omit; - expect(() => legacyMetricStateSchema.validate(input)).toThrow(); + expect(() => legacyMetricConfigSchema.validate(input)).toThrow(); }); }); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.ts index 6208356d7f566..86aaec072525b 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/legacy_metric.ts @@ -23,7 +23,7 @@ import { horizontalAlignmentSchema, verticalAlignmentSchema } from '../alignment import { mergeAllMetricsWithChartDimensionSchema } from './shared'; import { objectUnion } from './utils/object_union'; -const legacyMetricStateMetricOptionsSchema = { +const legacyMetricConfigMetricOptionsSchema = { /** * Font scale for the legacy metric label and value. */ @@ -87,7 +87,7 @@ const legacyMetricStateMetricOptionsSchema = { ), }; -export const legacyMetricStateSchemaNoESQL = schema.object( +export const legacyMetricConfigSchemaNoESQL = schema.object( { type: schema.literal('legacy_metric'), ...sharedPanelInfoSchema, @@ -97,12 +97,12 @@ export const legacyMetricStateSchemaNoESQL = schema.object( /** * Metric configuration, must define operation. */ - metric: mergeAllMetricsWithChartDimensionSchema(legacyMetricStateMetricOptionsSchema), + metric: mergeAllMetricsWithChartDimensionSchema(legacyMetricConfigMetricOptionsSchema), }, { meta: { id: 'legacyMetricNoESQL', title: 'Legacy Metric Chart (DSL)' } } ); -const esqlLegacyMetricState = schema.object( +const esqlLegacyMetricConfig = schema.object( { type: schema.literal('legacy_metric'), ...sharedPanelInfoSchema, @@ -111,16 +111,16 @@ const esqlLegacyMetricState = schema.object( /** * Metric configuration, must define operation. */ - metric: esqlColumnWithFormatSchema.extends(legacyMetricStateMetricOptionsSchema), + metric: esqlColumnWithFormatSchema.extends(legacyMetricConfigMetricOptionsSchema), }, { meta: { id: 'legacyMetricESQL', title: 'Legacy Metric Chart (ES|QL)' } } ); // Legacy metric is not currently supported for ES|QL datasets -export const legacyMetricStateSchema = objectUnion([legacyMetricStateSchemaNoESQL], { +export const legacyMetricConfigSchema = objectUnion([legacyMetricConfigSchemaNoESQL], { meta: { id: 'legacyMetricChart', title: 'Legacy Metric Chart' }, }); -export type LegacyMetricState = TypeOf; -export type LegacyMetricStateNoESQL = TypeOf; -export type LegacyMetricStateESQL = TypeOf; +export type LegacyMetricConfig = TypeOf; +export type LegacyMetricConfigNoESQL = TypeOf; +export type LegacyMetricConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.test.ts index ffc0fc1b7393e..e6b53b0db1bff 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.test.ts @@ -9,8 +9,8 @@ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; -import type { MetricState } from './metric'; -import { metricStateSchema } from './metric'; +import type { MetricConfig } from './metric'; +import { metricConfigSchema } from './metric'; describe('Metric Schema', () => { const baseMetricConfig = { @@ -19,14 +19,14 @@ describe('Metric Schema', () => { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'test-data-view', }, - } satisfies Partial; + } satisfies Partial; const defaultValues = { sampling: 1, ignore_global_filters: false, - } satisfies Partial; + } satisfies Partial; - type MetricInput = Omit; + type MetricInput = Omit; describe('primary metric configuration', () => { it('validates count metric operation', () => { @@ -49,7 +49,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -76,7 +76,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -109,7 +109,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -139,7 +139,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -164,7 +164,7 @@ describe('Metric Schema', () => { ], } satisfies MetricInput; - expect(() => metricStateSchema.validate(input)).toThrow( + expect(() => metricConfigSchema.validate(input)).toThrow( 'When using percentage-based dynamic coloring, a breakdown dimension or max must be defined.' ); }); @@ -195,7 +195,7 @@ describe('Metric Schema', () => { }, }; - expect(() => metricStateSchema.validate(input)).not.toThrow(); + expect(() => metricConfigSchema.validate(input)).not.toThrow(); }); it('accepts percentage-based dynamic coloring with bar background_chart', () => { @@ -222,7 +222,7 @@ describe('Metric Schema', () => { ], }; - expect(() => metricStateSchema.validate(input)).not.toThrow(); + expect(() => metricConfigSchema.validate(input)).not.toThrow(); }); }); }); @@ -256,7 +256,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -288,7 +288,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); @@ -314,7 +314,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -344,7 +344,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); @@ -362,7 +362,7 @@ describe('Metric Schema', () => { ], } satisfies MetricInput; - expect(() => metricStateSchema.validate(input)).toThrow(); + expect(() => metricConfigSchema.validate(input)).toThrow(); }); it('throws on invalid styling alignment value', () => { @@ -386,7 +386,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - expect(() => metricStateSchema.validate(input)).toThrow(); + expect(() => metricConfigSchema.validate(input)).toThrow(); }); it('throws on invalid breakdown collapse_by value', () => { @@ -408,7 +408,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - expect(() => metricStateSchema.validate(input)).toThrow(); + expect(() => metricConfigSchema.validate(input)).toThrow(); }); it('throws if metric type is missing', () => { @@ -424,7 +424,7 @@ describe('Metric Schema', () => { ], } satisfies MetricInput; - expect(() => metricStateSchema.validate(input)).toThrow(); + expect(() => metricConfigSchema.validate(input)).toThrow(); }); it('throws for two primary metrics', () => { @@ -446,7 +446,7 @@ describe('Metric Schema', () => { ], } satisfies MetricInput; - expect(() => metricStateSchema.validate(input)).toThrow(); + expect(() => metricConfigSchema.validate(input)).toThrow(); }); it('throws for two secondary metrics', () => { @@ -466,7 +466,7 @@ describe('Metric Schema', () => { ], }; - expect(() => metricStateSchema.validate(input)).toThrow(); + expect(() => metricConfigSchema.validate(input)).toThrow(); }); it('throws if the only metric is secondary', () => { @@ -482,7 +482,7 @@ describe('Metric Schema', () => { ], } satisfies MetricInput; - expect(() => metricStateSchema.validate(input)).toThrow(); + expect(() => metricConfigSchema.validate(input)).toThrow(); }); it('throws if the icon name is invalid', () => { @@ -506,7 +506,7 @@ describe('Metric Schema', () => { ], } satisfies MetricInput; - expect(() => metricStateSchema.validate(input)).toThrow(); + expect(() => metricConfigSchema.validate(input)).toThrow(); }); }); @@ -565,7 +565,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -594,7 +594,7 @@ describe('Metric Schema', () => { }, } satisfies MetricInput; - const validated = metricStateSchema.validate(input); + const validated = metricConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.ts index f8ac90323bc20..af1897cfb4a32 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/metric.ts @@ -104,14 +104,14 @@ export const complementaryVizSchemaESQL = barBackgroundChartSchema.extends( { meta: { id: 'metricComplementaryBar', title: 'Complementary Bar' } } ); -const metricStateBackgroundChartSchemaNoESQL = { +const metricConfigBackgroundChartSchemaNoESQL = { /** * Complementary visualization */ background_chart: schema.maybe(complementaryVizSchemaNoESQL), }; -const metricStateBackgroundChartSchemaESQL = { +const metricConfigBackgroundChartSchemaESQL = { /** * Complementary visualization */ @@ -318,7 +318,7 @@ const metricStylingSchema = schema.object( } ); -const metricStatePrimaryMetricOptionsSchema = { +const metricConfigPrimaryMetricOptionsSchema = { // this is used to differentiate primary and secondary metrics // unfortunately given the lack of tuple schema support we need to have some way // to avoid default injection in the wrong type @@ -343,7 +343,7 @@ const metricStatePrimaryMetricOptionsSchema = { apply_color_to: schema.maybe(applyColorToSchema), }; -const metricStateSecondaryMetricOptionsSchema = { +const metricConfigSecondaryMetricOptionsSchema = { // this is used to differentiate primary and secondary metrics // unfortunately given the lack of tuple schema support we need to have some way // to avoid default injection in the wrong type @@ -378,7 +378,7 @@ const metricStateSecondaryMetricOptionsSchema = { ), }; -const metricStateBreakdownByOptionsSchema = { +const metricConfigBreakdownByOptionsSchema = { /** * Number of columns */ @@ -428,14 +428,14 @@ function validateMetrics(metrics: (PrimaryMetricType | SecondaryMetricType)[]) { } export const primaryMetricSchemaNoESQL = mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps({ - ...metricStatePrimaryMetricOptionsSchema, - ...metricStateBackgroundChartSchemaNoESQL, + ...metricConfigPrimaryMetricOptionsSchema, + ...metricConfigBackgroundChartSchemaNoESQL, }); const secondaryMetricSchemaNoESQL = mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps( - metricStateSecondaryMetricOptionsSchema + metricConfigSecondaryMetricOptionsSchema ); -export const metricStateSchemaNoESQL = schema.object( +export const metricConfigSchemaNoESQL = schema.object( { type: schema.literal('metric'), ...sharedPanelInfoSchema, @@ -458,7 +458,7 @@ export const metricStateSchemaNoESQL = schema.object( * Configure how to break down the metric (e.g. show one metric per term). */ breakdown_by: schema.maybe( - mergeAllBucketsWithChartDimensionSchema(metricStateBreakdownByOptionsSchema) + mergeAllBucketsWithChartDimensionSchema(metricConfigBreakdownByOptionsSchema) ), }, { @@ -480,14 +480,14 @@ export const metricStateSchemaNoESQL = schema.object( ); const primaryMetricESQL = esqlColumnWithFormatSchema - .extends(metricStatePrimaryMetricOptionsSchema) - .extends(metricStateBackgroundChartSchemaESQL); + .extends(metricConfigPrimaryMetricOptionsSchema) + .extends(metricConfigBackgroundChartSchemaESQL); const secondaryMetricESQL = esqlColumnWithFormatSchema.extends( - metricStateSecondaryMetricOptionsSchema + metricConfigSecondaryMetricOptionsSchema ); -export const esqlMetricState = schema.object( +export const metricConfigSchemaESQL = schema.object( { type: schema.literal('metric'), ...sharedPanelInfoSchema, @@ -506,7 +506,7 @@ export const esqlMetricState = schema.object( * Configure how to break down the metric (e.g. show one metric per term). */ breakdown_by: schema.maybe( - esqlColumnWithFormatSchema.extends(metricStateBreakdownByOptionsSchema) + esqlColumnWithFormatSchema.extends(metricConfigBreakdownByOptionsSchema) ), }, { @@ -527,15 +527,13 @@ export const esqlMetricState = schema.object( } ); -export const metricStateSchema = objectUnion([metricStateSchemaNoESQL, esqlMetricState], { +export const metricConfigSchema = objectUnion([metricConfigSchemaNoESQL, metricConfigSchemaESQL], { meta: { id: 'metricChart', title: 'Metric Chart' }, }); -export type MetricState = TypeOf; -export type MetricStateNoESQL = TypeOf; -export type MetricStateESQL = TypeOf; - -export type MetricStyling = TypeOf; +export type MetricConfig = TypeOf; +export type MetricConfigNoESQL = TypeOf; +export type MetricConfigESQL = TypeOf; export type PrimaryMetricType = | TypeOf diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.test.ts index df49e7da5ae69..88984d65ab877 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.test.ts @@ -8,12 +8,12 @@ */ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; -import type { MosaicState, MosaicStateESQL, MosaicStateNoESQL } from './mosaic'; -import { mosaicStateSchema } from './mosaic'; +import type { MosaicConfig, MosaicConfigESQL, MosaicConfigNoESQL } from './mosaic'; +import { mosaicConfigSchema } from './mosaic'; describe('Mosaic Schema', () => { const baseMosaicConfig: Pick< - MosaicStateNoESQL, + MosaicConfigNoESQL, 'type' | 'data_source' | 'ignore_global_filters' | 'sampling' > = { type: 'mosaic', @@ -27,7 +27,7 @@ describe('Mosaic Schema', () => { describe('Non-ES|QL Schema', () => { it('validates minimal configuration with single outer grouping', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -42,7 +42,7 @@ describe('Mosaic Schema', () => { ], }; - const validated = mosaicStateSchema.validate(input); + const validated = mosaicConfigSchema.validate(input); expect(validated.type).toBe('mosaic'); expect(validated.metric).toHaveProperty('operation', 'count'); expect(validated.group_by).toHaveLength(1); @@ -57,11 +57,11 @@ describe('Mosaic Schema', () => { }, }; - expect(() => mosaicStateSchema.validate(input)).toThrow(); + expect(() => mosaicConfigSchema.validate(input)).toThrow(); }); it('validates configuration with both outer and inner grouping', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'sum', @@ -86,14 +86,14 @@ describe('Mosaic Schema', () => { ], }; - const validated = mosaicStateSchema.validate(input); + const validated = mosaicConfigSchema.validate(input); expect(validated.metric).toHaveProperty('operation', 'sum'); expect(validated.group_by).toHaveLength(1); expect(validated.group_breakdown_by).toHaveLength(1); }); it('validates configuration with collapsed dimensions', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -124,13 +124,13 @@ describe('Mosaic Schema', () => { ], }; - const validated = mosaicStateSchema.validate(input); + const validated = mosaicConfigSchema.validate(input); expect(validated.group_by).toHaveLength(2); expect(validated.group_breakdown_by).toHaveLength(1); }); it('validates full configuration with legend and value display', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, title: 'Sales Mosaic', description: 'Sales data visualization', @@ -166,14 +166,14 @@ describe('Mosaic Schema', () => { }, }; - const validated = mosaicStateSchema.validate(input); + const validated = mosaicConfigSchema.validate(input); expect(validated.title).toBe('Sales Mosaic'); expect(validated.legend?.nested).toBe(true); expect(validated.styling?.values?.visible).toBe(false); }); it('throws on empty group_by array', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -182,11 +182,11 @@ describe('Mosaic Schema', () => { group_by: [], }; - expect(() => mosaicStateSchema.validate(input)).toThrow(); + expect(() => mosaicConfigSchema.validate(input)).toThrow(); }); it('throws on empty group_breakdown_by array', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -202,12 +202,12 @@ describe('Mosaic Schema', () => { group_breakdown_by: [], }; - expect(() => mosaicStateSchema.validate(input)).toThrow(); + expect(() => mosaicConfigSchema.validate(input)).toThrow(); }); describe('Grouping Cardinality Validation', () => { it('allows single non-collapsed dimension in group_by', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -222,11 +222,11 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).not.toThrow(); + expect(() => mosaicConfigSchema.validate(input)).not.toThrow(); }); it('allows multiple collapsed dimensions in group_by', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -253,11 +253,11 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).not.toThrow(); + expect(() => mosaicConfigSchema.validate(input)).not.toThrow(); }); it('throws when group_by has multiple non-collapsed dimensions', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -277,13 +277,13 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).toThrow( + expect(() => mosaicConfigSchema.validate(input)).toThrow( /only a single non-collapsed dimension is allowed/i ); }); it('throws when group_by has multiple non-collapsed dimensions with some collapsed', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -309,13 +309,13 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).toThrow( + expect(() => mosaicConfigSchema.validate(input)).toThrow( /only a single non-collapsed dimension is allowed/i ); }); it('allows single non-collapsed dimension in group_breakdown_by', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -339,11 +339,11 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).not.toThrow(); + expect(() => mosaicConfigSchema.validate(input)).not.toThrow(); }); it('allows multiple collapsed dimensions in group_breakdown_by', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -380,11 +380,11 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).not.toThrow(); + expect(() => mosaicConfigSchema.validate(input)).not.toThrow(); }); it('throws when group_breakdown_by has multiple non-collapsed dimensions', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -414,13 +414,13 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).toThrow( + expect(() => mosaicConfigSchema.validate(input)).toThrow( /only a single non-collapsed dimension is allowed/i ); }); it('throws when group_breakdown_by has multiple non-collapsed dimensions with some collapsed', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -456,13 +456,13 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).toThrow( + expect(() => mosaicConfigSchema.validate(input)).toThrow( /only a single non-collapsed dimension is allowed/i ); }); it('throws when no grouping dimension are defined', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -470,13 +470,13 @@ describe('Mosaic Schema', () => { }, }; - expect(() => mosaicStateSchema.validate(input)).toThrow( + expect(() => mosaicConfigSchema.validate(input)).toThrow( /Either a group_by or a group_breakdown_by dimension must be specified/i ); }); it('allows only the group_breakdown_by definition without group_by', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'count', @@ -506,11 +506,11 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).not.toThrow(); + expect(() => mosaicConfigSchema.validate(input)).not.toThrow(); }); it('allows valid combination with both outer and inner having multiple collapsed dimensions', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseMosaicConfig, metric: { operation: 'sum', @@ -560,14 +560,14 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).not.toThrow(); + expect(() => mosaicConfigSchema.validate(input)).not.toThrow(); }); }); }); describe('ES|QL Schema', () => { const baseESQLMosaicConfig: Pick< - MosaicStateESQL, + MosaicConfigESQL, 'type' | 'data_source' | 'ignore_global_filters' | 'sampling' > = { type: 'mosaic', @@ -580,20 +580,20 @@ describe('Mosaic Schema', () => { }; it('throws when no grouping dimension are defined', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseESQLMosaicConfig, metric: { column: 'foo', }, }; - expect(() => mosaicStateSchema.validate(input)).toThrow( + expect(() => mosaicConfigSchema.validate(input)).toThrow( /Either a group_by or a group_breakdown_by dimension must be specified/i ); }); it('allows only the group_breakdown_by definition without group_by', () => { - const input: MosaicState = { + const input: MosaicConfig = { ...baseESQLMosaicConfig, metric: { column: 'foo', @@ -613,7 +613,7 @@ describe('Mosaic Schema', () => { ], }; - expect(() => mosaicStateSchema.validate(input)).not.toThrow(); + expect(() => mosaicConfigSchema.validate(input)).not.toThrow(); }); }); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.ts index 8d67aa997ffd6..cbb3654ecde84 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/mosaic.ts @@ -29,7 +29,7 @@ import { import { objectUnion } from './utils/object_union'; import { groupIsNotCollapsed } from '../../utils'; -const mosaicStateSharedSchema = { +const mosaicConfigSharedSchema = { legend: schema.maybe( schema.object( { @@ -62,9 +62,9 @@ const mosaicStylingSchema = schema.object( } ); -const partitionStatePrimaryMetricOptionsSchema = {}; +const partitionConfigPrimaryMetricOptionsSchema = {}; -const partitionStateBreakdownByOptionsSchema = { +const partitionConfigBreakdownByOptionsSchema = { /** * Color configuration: color mapping */ @@ -105,24 +105,24 @@ function validateMosaicGroupings({ return; } -export const mosaicStateSchemaNoESQL = schema.object( +export const mosaicConfigSchemaNoESQL = schema.object( { type: schema.literal('mosaic'), ...sharedPanelInfoSchema, ...layerSettingsSchema, ...dataSourceSchema, ...dslOnlyPanelInfoSchema, - ...mosaicStateSharedSchema, + ...mosaicConfigSharedSchema, styling: schema.maybe(mosaicStylingSchema), /** * Primary value configuration, must define operation. Supports field-based operations (count, unique count, metrics, sum, last value, percentile, percentile ranks), reference-based operations (differences, moving average, cumulative sum, counter rate), and formula-like operations (static value, formula). */ metric: mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps( - partitionStatePrimaryMetricOptionsSchema + partitionConfigPrimaryMetricOptionsSchema ), group_by: schema.maybe( schema.arrayOf( - mergeAllBucketsWithChartDimensionSchema(partitionStateBreakdownByOptionsSchema), + mergeAllBucketsWithChartDimensionSchema(partitionConfigBreakdownByOptionsSchema), { minSize: 1, maxSize: 100, @@ -157,18 +157,18 @@ export const mosaicStateSchemaNoESQL = schema.object( } ); -export const mosaicStateSchemaESQL = schema.object( +export const mosaicConfigSchemaESQL = schema.object( { type: schema.literal('mosaic'), ...sharedPanelInfoSchema, ...layerSettingsSchema, ...dataSourceEsqlTableSchema, - ...mosaicStateSharedSchema, + ...mosaicConfigSharedSchema, styling: schema.maybe(mosaicStylingSchema), /** * Primary value configuration, must define operation. In ES|QL mode, uses column-based configuration. */ - metric: esqlColumnWithFormatSchema.extends(partitionStatePrimaryMetricOptionsSchema, { + metric: esqlColumnWithFormatSchema.extends(partitionConfigPrimaryMetricOptionsSchema, { meta: { description: 'Metric configuration for ES|QL mode, combining generic options, primary metric options, and column selection', @@ -178,14 +178,14 @@ export const mosaicStateSchemaESQL = schema.object( * Configure how to break down the metric (e.g. show one metric per term). In ES|QL mode, uses column-based configuration. */ group_by: schema.maybe( - schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionStateBreakdownByOptionsSchema), { + schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionConfigBreakdownByOptionsSchema), { minSize: 1, maxSize: 100, meta: { description: 'Array of breakdown dimensions (minimum 1)' }, }) ), group_breakdown_by: schema.maybe( - schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionStateBreakdownByOptionsSchema), { + schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionConfigBreakdownByOptionsSchema), { minSize: 1, maxSize: 100, meta: { description: 'Array of group breakdown dimensions (minimum 1)' }, @@ -203,7 +203,7 @@ export const mosaicStateSchemaESQL = schema.object( } ); -export const mosaicStateSchema = objectUnion([mosaicStateSchemaNoESQL, mosaicStateSchemaESQL], { +export const mosaicConfigSchema = objectUnion([mosaicConfigSchemaNoESQL, mosaicConfigSchemaESQL], { meta: { id: 'mosaicChart', title: 'Mosaic Chart', @@ -212,6 +212,6 @@ export const mosaicStateSchema = objectUnion([mosaicStateSchemaNoESQL, mosaicSta }, }); -export type MosaicState = TypeOf; -export type MosaicStateNoESQL = TypeOf; -export type MosaicStateESQL = TypeOf; +export type MosaicConfig = TypeOf; +export type MosaicConfigNoESQL = TypeOf; +export type MosaicConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/partition.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/partition.ts index 30dc316382ccd..b3c892b90f7b5 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/partition.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/partition.ts @@ -8,30 +8,30 @@ */ import { schema } from '@kbn/config-schema'; -import type { MosaicState, MosaicStateESQL, MosaicStateNoESQL } from './mosaic'; -import { mosaicStateSchema } from './mosaic'; -import type { PieState, PieStateESQL, PieStateNoESQL } from './pie'; -import { pieStateSchema } from './pie'; -import type { TreemapState, TreemapStateESQL, TreemapStateNoESQL } from './treemap'; -import { treemapStateSchema } from './treemap'; -import type { WaffleState, WaffleStateESQL, WaffleStateNoESQL } from './waffle'; -import { waffleStateSchema } from './waffle'; +import type { MosaicConfig, MosaicConfigESQL, MosaicConfigNoESQL } from './mosaic'; +import { mosaicConfigSchema } from './mosaic'; +import type { PieConfig, PieConfigESQL, PieConfigNoESQL } from './pie'; +import { pieConfigSchema } from './pie'; +import type { TreemapConfig, TreemapConfigESQL, TreemapConfigNoESQL } from './treemap'; +import { treemapConfigSchema } from './treemap'; +import type { WaffleConfig, WaffleConfigESQL, WaffleConfigNoESQL } from './waffle'; +import { waffleConfigSchema } from './waffle'; -export const partitionStateSchema = schema.oneOf([ - mosaicStateSchema, - pieStateSchema, - treemapStateSchema, - waffleStateSchema, +export const partitionConfigSchema = schema.oneOf([ + mosaicConfigSchema, + pieConfigSchema, + treemapConfigSchema, + waffleConfigSchema, ]); -export type PartitionState = PieState | MosaicState | TreemapState | WaffleState; -export type PartitionStateNoESQL = - | PieStateNoESQL - | MosaicStateNoESQL - | TreemapStateNoESQL - | WaffleStateNoESQL; -export type PartitionStateESQL = - | PieStateESQL - | MosaicStateESQL - | TreemapStateESQL - | WaffleStateESQL; +export type PartitionConfig = PieConfig | MosaicConfig | TreemapConfig | WaffleConfig; +export type PartitionConfigNoESQL = + | PieConfigNoESQL + | MosaicConfigNoESQL + | TreemapConfigNoESQL + | WaffleConfigNoESQL; +export type PartitionConfigESQL = + | PieConfigESQL + | MosaicConfigESQL + | TreemapConfigESQL + | WaffleConfigESQL; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.test.ts index 91ecb7f3e3918..7dee1fa822057 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.test.ts @@ -8,8 +8,8 @@ */ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; -import type { PieStateESQL, PieStateNoESQL } from './pie'; -import { pieStateSchema } from './pie'; +import type { PieConfigESQL, PieConfigNoESQL } from './pie'; +import { pieConfigSchema } from './pie'; describe('Pie Schema', () => { describe('pie chart type', () => { @@ -22,10 +22,10 @@ describe('Pie Schema', () => { }, ignore_global_filters: false, sampling: 1, - } satisfies Partial; + } satisfies Partial; it('validates minimal configuration with single metric', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -35,14 +35,14 @@ describe('Pie Schema', () => { ], }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.type).toBe('pie'); expect(validated.metrics).toHaveLength(1); expect(validated.metrics[0]).toHaveProperty('operation', 'count'); }); it('validates configuration with metrics and group_by', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -59,13 +59,13 @@ describe('Pie Schema', () => { ], }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.metrics).toHaveLength(1); expect(validated.group_by).toHaveLength(1); }); it('validates configuration with donut_hole', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -86,12 +86,12 @@ describe('Pie Schema', () => { }, }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.styling?.donut_hole).toBe('m'); }); it('validates full configuration with specific options', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, title: 'Sales Chart', description: 'Sales data visualization', @@ -129,7 +129,7 @@ describe('Pie Schema', () => { }, }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.title).toBe('Sales Chart'); expect(validated.legend?.nested).toBe(false); expect(validated.styling?.donut_hole).toBe('s'); @@ -138,7 +138,7 @@ describe('Pie Schema', () => { }); it('validates configuration with multiple group_by dimensions', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -165,12 +165,12 @@ describe('Pie Schema', () => { ], }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.group_by).toHaveLength(3); }); it('validates configuration with color mapping', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -225,12 +225,12 @@ describe('Pie Schema', () => { ], }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.group_by?.[0].color).toHaveProperty('mode', 'categorical'); }); it('validates configuration with collapsed dimensions', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -253,22 +253,22 @@ describe('Pie Schema', () => { ], }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.group_by).toHaveLength(2); expect(validated.group_by?.[0].collapse_by).toBe('sum'); }); it('throws on empty metrics array', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [], }; - expect(() => pieStateSchema.validate(input)).toThrow(); + expect(() => pieConfigSchema.validate(input)).toThrow(); }); it('throws on empty group_by array', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -279,11 +279,11 @@ describe('Pie Schema', () => { group_by: [], }; - expect(() => pieStateSchema.validate(input)).toThrow(); + expect(() => pieConfigSchema.validate(input)).toThrow(); }); it('throws on invalid donut hole size', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -304,11 +304,11 @@ describe('Pie Schema', () => { }, }; - expect(() => pieStateSchema.validate(input)).toThrow(); + expect(() => pieConfigSchema.validate(input)).toThrow(); }); it('throws on invalid label position', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -331,13 +331,13 @@ describe('Pie Schema', () => { }, }; - expect(() => pieStateSchema.validate(input)).toThrow(); + expect(() => pieConfigSchema.validate(input)).toThrow(); }); describe('Grouping Validation', () => { describe('Single Metric Scenarios', () => { it('allows single metric with single non-collapsed breakdown', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -354,11 +354,11 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).not.toThrow(); + expect(() => pieConfigSchema.validate(input)).not.toThrow(); }); it('allows single metric with two non-collapsed breakdowns', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -380,11 +380,11 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).not.toThrow(); + expect(() => pieConfigSchema.validate(input)).not.toThrow(); }); it('allows single metric with three non-collapsed breakdowns', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -411,11 +411,11 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).not.toThrow(); + expect(() => pieConfigSchema.validate(input)).not.toThrow(); }); it('allows single metric with multiple collapsed and three non-collapsed breakdowns', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -454,11 +454,11 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).not.toThrow(); + expect(() => pieConfigSchema.validate(input)).not.toThrow(); }); it('throws when single metric has more than three non-collapsed breakdowns', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -490,7 +490,7 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).toThrow( + expect(() => pieConfigSchema.validate(input)).toThrow( /number of non-collapsed group_by dimensions must not exceed 3/i ); }); @@ -498,7 +498,7 @@ describe('Pie Schema', () => { describe('Multiple Metrics Scenarios', () => { it('allows multiple metrics without group_by', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -513,11 +513,11 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).not.toThrow(); + expect(() => pieConfigSchema.validate(input)).not.toThrow(); }); it('allows multiple metrics with single non-collapsed breakdown', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -539,11 +539,11 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).not.toThrow(); + expect(() => pieConfigSchema.validate(input)).not.toThrow(); }); it('allows multiple metrics with two non-collapsed breakdowns', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -570,11 +570,11 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).not.toThrow(); + expect(() => pieConfigSchema.validate(input)).not.toThrow(); }); it('allows multiple metrics with multiple collapsed and two non-collapsed breakdowns', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -615,11 +615,11 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).not.toThrow(); + expect(() => pieConfigSchema.validate(input)).not.toThrow(); }); it('throws when multiple metrics have more than 2 non-collapsed breakdowns', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -651,13 +651,13 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).toThrow( + expect(() => pieConfigSchema.validate(input)).toThrow( /the number of non-collapsed group_by dimensions must not exceed 2/i ); }); it('throws when multiple metrics have one collapsed and three non-collapsed breakdowns', () => { - const input: PieStateNoESQL = { + const input: PieConfigNoESQL = { ...basePieConfig, metrics: [ { @@ -699,7 +699,7 @@ describe('Pie Schema', () => { ], }; - expect(() => pieStateSchema.validate(input)).toThrow( + expect(() => pieConfigSchema.validate(input)).toThrow( /the number of non-collapsed group_by dimensions must not exceed 2/i ); }); @@ -716,9 +716,9 @@ describe('Pie Schema', () => { }, ignore_global_filters: false, sampling: 1, - } satisfies Partial; + } satisfies Partial; it('validates minimal ES|QL configuration', () => { - const input: PieStateESQL = { + const input: PieConfigESQL = { ...baseESQLPieConfig, metrics: [ { @@ -727,13 +727,13 @@ describe('Pie Schema', () => { ], }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.data_source.type).toBe('esql'); expect(validated.metrics[0]).toHaveProperty('column', 'count'); }); it('validates ES|QL configuration with group_by', () => { - const input: PieStateESQL = { + const input: PieConfigESQL = { ...baseESQLPieConfig, metrics: [ { @@ -747,13 +747,13 @@ describe('Pie Schema', () => { ], }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.group_by).toHaveLength(1); expect(validated.group_by?.[0]).toHaveProperty('column', 'category'); }); it('validates ES|QL configuration with multiple metrics', () => { - const input: PieStateESQL = { + const input: PieConfigESQL = { ...baseESQLPieConfig, metrics: [ { @@ -765,12 +765,12 @@ describe('Pie Schema', () => { ], }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.metrics).toHaveLength(2); }); it('validates ES|QL configuration with full options', () => { - const input: PieStateESQL = { + const input: PieConfigESQL = { ...baseESQLPieConfig, title: 'Sales Chart', metrics: [ @@ -835,7 +835,7 @@ describe('Pie Schema', () => { }, }; - const validated = pieStateSchema.validate(input); + const validated = pieConfigSchema.validate(input); expect(validated.title).toBe('Sales Chart'); expect(validated.styling?.donut_hole).toBe('l'); expect(validated.styling?.labels?.position).toBe('outside'); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts index 53a5e1682209a..67fc3eb872865 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts @@ -98,7 +98,7 @@ const pieStylingSchema = schema.object( /** * Color configuration for primary metric in pie chart */ -const partitionStatePrimaryMetricOptionsSchema = { +const partitionConfigPrimaryMetricOptionsSchema = { color: schema.maybe( schema.oneOf([staticColorSchema, autoColorSchema], { defaultValue: AUTO_COLOR, @@ -109,7 +109,7 @@ const partitionStatePrimaryMetricOptionsSchema = { /** * Breakdown configuration including color mapping and collapse behavior */ -const partitionStateBreakdownByOptionsSchema = { +const partitionConfigBreakdownByOptionsSchema = { color: schema.maybe(colorMappingSchema), collapse_by: schema.maybe(collapseBySchema), }; @@ -139,7 +139,7 @@ function validateForMultipleMetrics({ /** * Pie chart configuration for standard (non-ES|QL) queries */ -export const pieStateSchemaNoESQL = schema.object( +export const pieConfigSchemaNoESQL = schema.object( { type: pieTypeSchema, ...sharedPanelInfoSchema, @@ -150,7 +150,7 @@ export const pieStateSchemaNoESQL = schema.object( styling: schema.maybe(pieStylingSchema), metrics: schema.arrayOf( mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps( - partitionStatePrimaryMetricOptionsSchema + partitionConfigPrimaryMetricOptionsSchema ), { minSize: 1, @@ -160,7 +160,7 @@ export const pieStateSchemaNoESQL = schema.object( ), group_by: schema.maybe( schema.arrayOf( - mergeAllBucketsWithChartDimensionSchema(partitionStateBreakdownByOptionsSchema), + mergeAllBucketsWithChartDimensionSchema(partitionConfigBreakdownByOptionsSchema), { minSize: 1, maxSize: 100, @@ -182,7 +182,7 @@ export const pieStateSchemaNoESQL = schema.object( /** * Pie chart configuration for ES|QL queries */ -export const pieStateSchemaESQL = schema.object( +export const pieConfigSchemaESQL = schema.object( { type: pieTypeSchema, ...sharedPanelInfoSchema, @@ -191,7 +191,7 @@ export const pieStateSchemaESQL = schema.object( ...pieStateSharedSchema, styling: schema.maybe(pieStylingSchema), metrics: schema.arrayOf( - esqlColumnWithFormatSchema.extends(partitionStatePrimaryMetricOptionsSchema, { + esqlColumnWithFormatSchema.extends(partitionConfigPrimaryMetricOptionsSchema, { meta: { description: 'ES|QL column reference for primary metric' }, }), { @@ -201,7 +201,7 @@ export const pieStateSchemaESQL = schema.object( } ), group_by: schema.maybe( - schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionStateBreakdownByOptionsSchema), { + schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionConfigBreakdownByOptionsSchema), { minSize: 1, maxSize: 100, meta: { description: 'Array of breakdown dimensions (minimum 1)' }, @@ -221,7 +221,7 @@ export const pieStateSchemaESQL = schema.object( /** * Complete pie chart configuration supporting both standard and ES|QL queries */ -export const pieStateSchema = objectUnion([pieStateSchemaNoESQL, pieStateSchemaESQL], { +export const pieConfigSchema = objectUnion([pieConfigSchemaNoESQL, pieConfigSchemaESQL], { meta: { id: 'pieChart', title: 'Pie Chart', @@ -229,6 +229,6 @@ export const pieStateSchema = objectUnion([pieStateSchemaNoESQL, pieStateSchemaE }, }); -export type PieState = TypeOf; -export type PieStateNoESQL = TypeOf; -export type PieStateESQL = TypeOf; +export type PieConfig = TypeOf; +export type PieConfigNoESQL = TypeOf; +export type PieConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.test.ts index e3f40b89d9d13..7939495471bdc 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.test.ts @@ -9,13 +9,13 @@ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; -import type { RegionMapState } from './region_map'; -import { regionMapStateSchema } from './region_map'; +import type { RegionMapConfig } from './region_map'; +import { regionMapConfigSchema } from './region_map'; -type DefaultRegionMapConfig = Pick; -type RegionMapWithoutDefaultsConfig = Omit; +type DefaultRegionMapConfig = Pick; +type RegionMapWithoutDefaultsConfig = Omit; -type RegionTerms = Extract; +type RegionTerms = Extract; interface RegionMapTermsRegionBaseConfig { region: Omit; } @@ -50,7 +50,7 @@ describe('Region Map Schema', () => { }, }; - const validated = regionMapStateSchema.validate(input); + const validated = regionMapConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -79,7 +79,7 @@ describe('Region Map Schema', () => { }, }; - const validated = regionMapStateSchema.validate(input); + const validated = regionMapConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); @@ -103,7 +103,7 @@ describe('Region Map Schema', () => { }, }; - const validated = regionMapStateSchema.validate(input); + const validated = regionMapConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); @@ -131,7 +131,7 @@ describe('Region Map Schema', () => { }, }; - expect(() => regionMapStateSchema.validate(input)).toThrow(); + expect(() => regionMapConfigSchema.validate(input)).toThrow(); }); it('throws on missing region operation', () => { @@ -148,7 +148,7 @@ describe('Region Map Schema', () => { fields: ['location'], }, }; - expect(() => regionMapStateSchema.validate(input)).toThrow(); + expect(() => regionMapConfigSchema.validate(input)).toThrow(); }); it('throws on missing ems join field', () => { @@ -175,7 +175,7 @@ describe('Region Map Schema', () => { }, }; - expect(() => regionMapStateSchema.validate(input)).toThrow(); + expect(() => regionMapConfigSchema.validate(input)).toThrow(); }); it('throw when using term buckets operation in an esql configuration', () => { @@ -194,7 +194,7 @@ describe('Region Map Schema', () => { limit: 5, }, }; - expect(() => regionMapStateSchema.validate(input)).toThrow(); + expect(() => regionMapConfigSchema.validate(input)).toThrow(); }); }); @@ -219,7 +219,7 @@ describe('Region Map Schema', () => { }, }; - const validated = regionMapStateSchema.validate(input); + const validated = regionMapConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); @@ -244,7 +244,7 @@ describe('Region Map Schema', () => { }, }; - const validated = regionMapStateSchema.validate(input); + const validated = regionMapConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.ts index aaa96f4d61cea..343582dd3ebdb 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/region_map.ts @@ -19,7 +19,7 @@ import { dslOnlyPanelInfoSchema, layerSettingsSchema, sharedPanelInfoSchema } fr import { mergeAllBucketsWithChartDimensionSchema } from './shared'; import { objectUnion } from './utils/object_union'; -const regionMapStateRegionOptionsSchema = { +const regionMapConfigRegionOptionsSchema = { ems: schema.maybe( schema.object({ boundaries: schema.string({ meta: { description: 'EMS boundaries' } }), @@ -28,7 +28,7 @@ const regionMapStateRegionOptionsSchema = { ), }; -export const regionMapStateSchemaNoESQL = schema.object( +export const regionMapConfigSchemaNoESQL = schema.object( { type: schema.literal('region_map'), ...sharedPanelInfoSchema, @@ -42,12 +42,12 @@ export const regionMapStateSchemaNoESQL = schema.object( /** * Configure how to break down to regions */ - region: mergeAllBucketsWithChartDimensionSchema(regionMapStateRegionOptionsSchema), + region: mergeAllBucketsWithChartDimensionSchema(regionMapConfigRegionOptionsSchema), }, { meta: { id: 'regionMapNoESQL', title: 'Region Map (DSL)' } } ); -export const regionMapStateSchemaESQL = schema.object( +export const regionMapConfigSchemaESQL = schema.object( { type: schema.literal('region_map'), ...sharedPanelInfoSchema, @@ -60,16 +60,16 @@ export const regionMapStateSchemaESQL = schema.object( /** * Configure how to break down to regions */ - region: esqlColumnSchema.extends(regionMapStateRegionOptionsSchema), + region: esqlColumnSchema.extends(regionMapConfigRegionOptionsSchema), }, { meta: { id: 'regionMapESQL', title: 'Region Map (ES|QL)' } } ); -export const regionMapStateSchema = objectUnion( - [regionMapStateSchemaNoESQL, regionMapStateSchemaESQL], +export const regionMapConfigSchema = objectUnion( + [regionMapConfigSchemaNoESQL, regionMapConfigSchemaESQL], { meta: { id: 'regionMapChart', title: 'Region Map' } } ); -export type RegionMapState = TypeOf; -export type RegionMapStateNoESQL = TypeOf; -export type RegionMapStateESQL = TypeOf; +export type RegionMapConfig = TypeOf; +export type RegionMapConfigNoESQL = TypeOf; +export type RegionMapConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.test.ts index a97b5ceecf767..3688e3c3fba85 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.test.ts @@ -9,7 +9,7 @@ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; import { LENS_EMPTY_AS_NULL_DEFAULT_VALUE } from '../../transforms/columns/utils'; -import { tagcloudStateSchema } from './tagcloud'; +import { tagcloudConfigSchema } from './tagcloud'; describe('Tagcloud Schema', () => { const baseTagcloudConfig = { @@ -40,7 +40,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -66,7 +66,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -99,7 +99,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -126,7 +126,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -152,7 +152,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -178,7 +178,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -209,7 +209,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -235,7 +235,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -261,7 +261,7 @@ describe('Tagcloud Schema', () => { }, }; - expect(() => tagcloudStateSchema.validate(input)).toThrow(); + expect(() => tagcloudConfigSchema.validate(input)).toThrow(); }); it('throws on missing tag_by operation', () => { @@ -273,7 +273,7 @@ describe('Tagcloud Schema', () => { }, }; - expect(() => tagcloudStateSchema.validate(input)).toThrow(); + expect(() => tagcloudConfigSchema.validate(input)).toThrow(); }); it('throws on invalid orientation value', () => { @@ -293,7 +293,7 @@ describe('Tagcloud Schema', () => { }, }; - expect(() => tagcloudStateSchema.validate(input)).toThrow(); + expect(() => tagcloudConfigSchema.validate(input)).toThrow(); }); it('throws on invalid font size minimum', () => { @@ -316,7 +316,7 @@ describe('Tagcloud Schema', () => { }, }; - expect(() => tagcloudStateSchema.validate(input)).toThrow(); + expect(() => tagcloudConfigSchema.validate(input)).toThrow(); }); it('throws on invalid font size maximum', () => { @@ -338,7 +338,7 @@ describe('Tagcloud Schema', () => { }, }; - expect(() => tagcloudStateSchema.validate(input)).toThrow(); + expect(() => tagcloudConfigSchema.validate(input)).toThrow(); }); it('throw when missing DSL and esql operation in a configuration', () => { @@ -357,7 +357,7 @@ describe('Tagcloud Schema', () => { limit: 5, }, }; - expect(() => tagcloudStateSchema.validate(input)).toThrow(); + expect(() => tagcloudConfigSchema.validate(input)).toThrow(); }); it('throws when tag_by color is not a palette mapping', () => { @@ -381,7 +381,7 @@ describe('Tagcloud Schema', () => { }, }; - expect(() => tagcloudStateSchema.validate(input)).toThrow(); + expect(() => tagcloudConfigSchema.validate(input)).toThrow(); }); }); @@ -419,7 +419,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input, @@ -455,7 +455,7 @@ describe('Tagcloud Schema', () => { }, }; - const validated = tagcloudStateSchema.validate(input); + const validated = tagcloudConfigSchema.validate(input); expect(validated).toEqual({ ...defaultValues, ...input }); }); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.ts index 204ada0b64ad8..830ba131148aa 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/tagcloud.ts @@ -21,7 +21,7 @@ import { } from './shared'; import { objectUnion } from './utils/object_union'; -const tagcloudStateTagsByOptionsSchema = { +const tagcloudConfigTagsByOptionsSchema = { /** * Color configuration */ @@ -82,7 +82,7 @@ const tagcloudStylingSchema = schema.object( } ); -export const tagcloudStateSchemaNoESQL = schema.object( +export const tagcloudConfigSchemaNoESQL = schema.object( { type: schema.literal('tag_cloud'), ...sharedPanelInfoSchema, @@ -97,12 +97,12 @@ export const tagcloudStateSchemaNoESQL = schema.object( /** * Configure how to break down to tags */ - tag_by: mergeAllBucketsWithChartDimensionSchema(tagcloudStateTagsByOptionsSchema), + tag_by: mergeAllBucketsWithChartDimensionSchema(tagcloudConfigTagsByOptionsSchema), }, { meta: { id: 'tagcloudNoESQL', title: 'Tag Cloud Chart (DSL)' } } ); -export const tagcloudStateSchemaESQL = schema.object( +export const tagcloudConfigSchemaESQL = schema.object( { type: schema.literal('tag_cloud'), ...sharedPanelInfoSchema, @@ -116,18 +116,18 @@ export const tagcloudStateSchemaESQL = schema.object( /** * Configure how to break down the metric (e.g. show one metric per term). */ - tag_by: esqlColumnWithFormatSchema.extends(tagcloudStateTagsByOptionsSchema), + tag_by: esqlColumnWithFormatSchema.extends(tagcloudConfigTagsByOptionsSchema), }, { meta: { id: 'tagcloudESQL', title: 'Tag Cloud Chart (ES|QL)' } } ); -export const tagcloudStateSchema = objectUnion( - [tagcloudStateSchemaNoESQL, tagcloudStateSchemaESQL], +export const tagcloudConfigSchema = objectUnion( + [tagcloudConfigSchemaNoESQL, tagcloudConfigSchemaESQL], { meta: { id: 'tagcloudChart', title: 'Tag Cloud Chart' }, } ); -export type TagcloudState = TypeOf; -export type TagcloudStateNoESQL = TypeOf; -export type TagcloudStateESQL = TypeOf; +export type TagcloudConfig = TypeOf; +export type TagcloudConfigNoESQL = TypeOf; +export type TagcloudConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.test.ts index 3f7a38337cf6a..a0a43f0853dd5 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.test.ts @@ -8,8 +8,8 @@ */ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; -import type { TreemapStateESQL, TreemapStateNoESQL } from './treemap'; -import { treemapStateSchema } from './treemap'; +import type { TreemapConfigESQL, TreemapConfigNoESQL } from './treemap'; +import { treemapConfigSchema } from './treemap'; describe('Treemap Schema', () => { describe('Non-ES|QL Schema', () => { @@ -21,10 +21,10 @@ describe('Treemap Schema', () => { }, ignore_global_filters: false, sampling: 1, - } satisfies Partial; + } satisfies Partial; it('validates minimal configuration with single metric', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -34,14 +34,14 @@ describe('Treemap Schema', () => { ], }; - const validated = treemapStateSchema.validate(input); + const validated = treemapConfigSchema.validate(input); expect(validated.type).toBe('treemap'); expect(validated.metrics).toHaveLength(1); expect(validated.metrics[0]).toHaveProperty('operation', 'count'); }); it('validates configuration with metrics and group_by', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -58,13 +58,13 @@ describe('Treemap Schema', () => { ], }; - const validated = treemapStateSchema.validate(input); + const validated = treemapConfigSchema.validate(input); expect(validated.metrics).toHaveLength(1); expect(validated.group_by).toHaveLength(1); }); it('validates full configuration with treemap-specific label position', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, title: 'Sales Treemap', description: 'Sales data visualization', @@ -101,7 +101,7 @@ describe('Treemap Schema', () => { }, }; - const validated = treemapStateSchema.validate(input); + const validated = treemapConfigSchema.validate(input); expect(validated.title).toBe('Sales Treemap'); expect(validated.legend?.nested).toBe(true); expect(validated.styling?.labels?.visible).toBe(true); @@ -110,7 +110,7 @@ describe('Treemap Schema', () => { }); it('validates configuration with two group_by dimensions', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -132,12 +132,12 @@ describe('Treemap Schema', () => { ], }; - const validated = treemapStateSchema.validate(input); + const validated = treemapConfigSchema.validate(input); expect(validated.group_by).toHaveLength(2); }); it('validates configuration with color mapping', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -192,12 +192,12 @@ describe('Treemap Schema', () => { ], }; - const validated = treemapStateSchema.validate(input); + const validated = treemapConfigSchema.validate(input); expect(validated.group_by?.[0].color).toHaveProperty('mode', 'categorical'); }); it('validates configuration with collapsed dimensions', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -220,22 +220,22 @@ describe('Treemap Schema', () => { ], }; - const validated = treemapStateSchema.validate(input); + const validated = treemapConfigSchema.validate(input); expect(validated.group_by).toHaveLength(2); expect(validated.group_by?.[0].collapse_by).toBe('sum'); }); it('throws on empty metrics array', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [], }; - expect(() => treemapStateSchema.validate(input)).toThrow(); + expect(() => treemapConfigSchema.validate(input)).toThrow(); }); it('throws on empty group_by array', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -246,13 +246,13 @@ describe('Treemap Schema', () => { group_by: [], }; - expect(() => treemapStateSchema.validate(input)).toThrow(); + expect(() => treemapConfigSchema.validate(input)).toThrow(); }); describe('Grouping Validation', () => { describe('Single Metric Scenarios', () => { it('allows single metric with single non-collapsed breakdown', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -269,11 +269,11 @@ describe('Treemap Schema', () => { ], }; - expect(() => treemapStateSchema.validate(input)).not.toThrow(); + expect(() => treemapConfigSchema.validate(input)).not.toThrow(); }); it('allows single metric with two non-collapsed breakdowns', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -295,11 +295,11 @@ describe('Treemap Schema', () => { ], }; - expect(() => treemapStateSchema.validate(input)).not.toThrow(); + expect(() => treemapConfigSchema.validate(input)).not.toThrow(); }); it('allows single metric with multiple collapsed and two non-collapsed breakdowns', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -333,11 +333,11 @@ describe('Treemap Schema', () => { ], }; - expect(() => treemapStateSchema.validate(input)).not.toThrow(); + expect(() => treemapConfigSchema.validate(input)).not.toThrow(); }); it('throws when single metric has more than two non-collapsed breakdowns', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -364,7 +364,7 @@ describe('Treemap Schema', () => { ], }; - expect(() => treemapStateSchema.validate(input)).toThrow( + expect(() => treemapConfigSchema.validate(input)).toThrow( / The number of non-collapsed group_by dimensions must not exceed 2/i ); }); @@ -372,7 +372,7 @@ describe('Treemap Schema', () => { describe('Multiple Metrics Scenarios', () => { it('allows multiple metrics without group_by', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -387,7 +387,7 @@ describe('Treemap Schema', () => { ], }; - expect(() => treemapStateSchema.validate(input)).not.toThrow(); + expect(() => treemapConfigSchema.validate(input)).not.toThrow(); }); it('allows multiple metrics with single non-collapsed breakdown', () => { @@ -413,11 +413,11 @@ describe('Treemap Schema', () => { ], }; - expect(() => treemapStateSchema.validate(input)).not.toThrow(); + expect(() => treemapConfigSchema.validate(input)).not.toThrow(); }); it('allows multiple metrics with multiple collapsed and one non-collapsed breakdown', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -453,11 +453,11 @@ describe('Treemap Schema', () => { ], }; - expect(() => treemapStateSchema.validate(input)).not.toThrow(); + expect(() => treemapConfigSchema.validate(input)).not.toThrow(); }); it('throws when multiple metrics have two non-collapsed breakdowns', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -484,13 +484,13 @@ describe('Treemap Schema', () => { ], }; - expect(() => treemapStateSchema.validate(input)).toThrow( + expect(() => treemapConfigSchema.validate(input)).toThrow( /the number of non-collapsed group_by dimensions must not exceed 1/i ); }); it('throws when multiple metrics have one collapsed and two non-collapsed breakdowns', () => { - const input: TreemapStateNoESQL = { + const input: TreemapConfigNoESQL = { ...baseTreemapConfig, metrics: [ { @@ -527,7 +527,7 @@ describe('Treemap Schema', () => { ], }; - expect(() => treemapStateSchema.validate(input)).toThrow( + expect(() => treemapConfigSchema.validate(input)).toThrow( /the number of non-collapsed group_by dimensions must not exceed 1/i ); }); @@ -544,10 +544,10 @@ describe('Treemap Schema', () => { }, ignore_global_filters: false, sampling: 1, - } satisfies Partial; + } satisfies Partial; it('validates minimal ES|QL configuration', () => { - const input: TreemapStateESQL = { + const input: TreemapConfigESQL = { ...baseESQLTreemapConfig, metrics: [ { @@ -556,13 +556,13 @@ describe('Treemap Schema', () => { ], }; - const validated = treemapStateSchema.validate(input); + const validated = treemapConfigSchema.validate(input); expect(validated.data_source.type).toBe('esql'); expect(validated.metrics[0]).toHaveProperty('column', 'count'); }); it('validates ES|QL configuration with group_by', () => { - const input: TreemapStateESQL = { + const input: TreemapConfigESQL = { ...baseESQLTreemapConfig, metrics: [ { @@ -576,12 +576,12 @@ describe('Treemap Schema', () => { ], }; - const validated = treemapStateSchema.validate(input); + const validated = treemapConfigSchema.validate(input); expect(validated.group_by?.[0]).toHaveProperty('column', 'category'); }); it('validates ES|QL configuration with full options', () => { - const input: TreemapStateESQL = { + const input: TreemapConfigESQL = { ...baseESQLTreemapConfig, title: 'Sales Treemap', metrics: [ @@ -645,7 +645,7 @@ describe('Treemap Schema', () => { }, }; - const validated = treemapStateSchema.validate(input); + const validated = treemapConfigSchema.validate(input); expect(validated.title).toBe('Sales Treemap'); expect(validated.styling?.labels?.visible).toBe(true); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.ts index 7b74b532d63fe..4bb3c6f0616c3 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/treemap.ts @@ -35,7 +35,7 @@ import { import { objectUnion } from './utils/object_union'; import { groupIsNotCollapsed } from '../../utils'; -const treemapSharedStateSchema = { +const treemapSharedConfigSchema = { legend: schema.maybe( schema.object( { @@ -79,7 +79,7 @@ const treemapStylingSchema = schema.object( } ); -const partitionStatePrimaryMetricOptionsSchema = { +const partitionConfigPrimaryMetricOptionsSchema = { /** * Color configuration */ @@ -90,7 +90,7 @@ const partitionStatePrimaryMetricOptionsSchema = { ), }; -const partitionStateBreakdownByOptionsSchema = { +const partitionConfigBreakdownByOptionsSchema = { /** * Color configuration: color mapping only */ @@ -129,21 +129,21 @@ function validateForMultipleMetrics({ return validateColoringAssignments({ metrics, group_by }); } -export const treemapStateSchemaNoESQL = schema.object( +export const treemapConfigSchemaNoESQL = schema.object( { type: schema.literal('treemap'), ...sharedPanelInfoSchema, ...layerSettingsSchema, ...dataSourceSchema, ...dslOnlyPanelInfoSchema, - ...treemapSharedStateSchema, + ...treemapSharedConfigSchema, styling: schema.maybe(treemapStylingSchema), /** * Primary value configuration, must define operation. Supports field-based operations (count, unique count, metrics, sum, last value, percentile, percentile ranks), reference-based operations (differences, moving average, cumulative sum, counter rate), and formula-like operations (static value, formula). */ metrics: schema.arrayOf( mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps( - partitionStatePrimaryMetricOptionsSchema + partitionConfigPrimaryMetricOptionsSchema ), { minSize: 1, @@ -156,7 +156,7 @@ export const treemapStateSchemaNoESQL = schema.object( */ group_by: schema.maybe( schema.arrayOf( - mergeAllBucketsWithChartDimensionSchema(partitionStateBreakdownByOptionsSchema), + mergeAllBucketsWithChartDimensionSchema(partitionConfigBreakdownByOptionsSchema), { minSize: 1, maxSize: 100, @@ -176,19 +176,19 @@ export const treemapStateSchemaNoESQL = schema.object( } ); -export const treemapStateSchemaESQL = schema.object( +export const treemapConfigSchemaESQL = schema.object( { type: schema.literal('treemap'), ...sharedPanelInfoSchema, ...layerSettingsSchema, ...dataSourceEsqlTableSchema, - ...treemapSharedStateSchema, + ...treemapSharedConfigSchema, styling: schema.maybe(treemapStylingSchema), /** * Primary value configuration, must define operation. In ES|QL mode, uses column-based configuration. */ metrics: schema.arrayOf( - esqlColumnWithFormatSchema.extends(partitionStatePrimaryMetricOptionsSchema), + esqlColumnWithFormatSchema.extends(partitionConfigPrimaryMetricOptionsSchema), { minSize: 1, maxSize: 100, @@ -199,7 +199,7 @@ export const treemapStateSchemaESQL = schema.object( * Configure how to break down the metric (e.g. show one metric per term). In ES|QL mode, uses column-based configuration. */ group_by: schema.maybe( - schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionStateBreakdownByOptionsSchema), { + schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionConfigBreakdownByOptionsSchema), { minSize: 1, maxSize: 100, meta: { description: 'Array of breakdown dimensions (minimum 1)' }, @@ -217,15 +217,18 @@ export const treemapStateSchemaESQL = schema.object( } ); -export const treemapStateSchema = objectUnion([treemapStateSchemaNoESQL, treemapStateSchemaESQL], { - meta: { - id: 'treemapChart', - title: 'Treemap Chart', - description: - 'Treemap chart configuration schema supporting both data source queries (non-ES|QL) and ES|QL query modes', - }, -}); +export const treemapConfigSchema = objectUnion( + [treemapConfigSchemaNoESQL, treemapConfigSchemaESQL], + { + meta: { + id: 'treemapChart', + title: 'Treemap Chart', + description: + 'Treemap chart configuration schema supporting both data source queries (non-ES|QL) and ES|QL query modes', + }, + } +); -export type TreemapState = TypeOf; -export type TreemapStateNoESQL = TypeOf; -export type TreemapStateESQL = TypeOf; +export type TreemapConfig = TypeOf; +export type TreemapConfigNoESQL = TypeOf; +export type TreemapConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.test.ts index c98b82c2a53cc..a4ba17ca79f2b 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.test.ts @@ -8,8 +8,8 @@ */ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; -import type { WaffleStateNoESQL, WaffleStateESQL } from './waffle'; -import { waffleStateSchema } from './waffle'; +import type { WaffleConfigNoESQL, WaffleConfigESQL } from './waffle'; +import { waffleConfigSchema } from './waffle'; describe('Waffle Schema', () => { describe('Non-ES|QL Schema', () => { @@ -21,10 +21,10 @@ describe('Waffle Schema', () => { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, ref_id: 'test-data-view', }, - } satisfies Partial; + } satisfies Partial; it('validates minimal configuration with single metric', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -34,14 +34,14 @@ describe('Waffle Schema', () => { ], }; - const validated = waffleStateSchema.validate(input); + const validated = waffleConfigSchema.validate(input); expect(validated.type).toBe('waffle'); expect(validated.metrics).toHaveLength(1); expect(validated.metrics[0]).toHaveProperty('operation', 'count'); }); it('validates configuration with metrics and group_by', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -58,13 +58,13 @@ describe('Waffle Schema', () => { ], }; - const validated = waffleStateSchema.validate(input); + const validated = waffleConfigSchema.validate(input); expect(validated.metrics).toHaveLength(1); expect(validated.group_by).toHaveLength(1); }); it('validates full configuration with waffle-specific legend values', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, title: 'Sales Waffle', description: 'Sales data visualization', @@ -101,14 +101,14 @@ describe('Waffle Schema', () => { }, }; - const validated = waffleStateSchema.validate(input); + const validated = waffleConfigSchema.validate(input); expect(validated.title).toBe('Sales Waffle'); expect(validated.legend?.values).toEqual(['absolute']); expect(validated.styling?.values?.mode).toBe('percentage'); }); it('validates multiple metrics without group_by', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -124,12 +124,12 @@ describe('Waffle Schema', () => { ], }; - const validated = waffleStateSchema.validate(input); + const validated = waffleConfigSchema.validate(input); expect(validated.metrics).toHaveLength(2); }); it('validates configuration with color by value', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -185,12 +185,12 @@ describe('Waffle Schema', () => { ], }; - const validated = waffleStateSchema.validate(input); + const validated = waffleConfigSchema.validate(input); expect(validated.group_by?.[0].color).toHaveProperty('mode', 'categorical'); }); it('validates configuration with collapsed dimensions', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -213,22 +213,22 @@ describe('Waffle Schema', () => { ], }; - const validated = waffleStateSchema.validate(input); + const validated = waffleConfigSchema.validate(input); expect(validated.group_by).toHaveLength(2); expect(validated.group_by?.[0].collapse_by).toBe('sum'); }); it('throws on empty metrics array', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [], }; - expect(() => waffleStateSchema.validate(input)).toThrow(); + expect(() => waffleConfigSchema.validate(input)).toThrow(); }); it('throws on empty group_by array', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -239,12 +239,12 @@ describe('Waffle Schema', () => { group_by: [], }; - expect(() => waffleStateSchema.validate(input)).toThrow(); + expect(() => waffleConfigSchema.validate(input)).toThrow(); }); describe('Grouping Validation', () => { it('allows single metric with single non-collapsed breakdown', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -261,11 +261,11 @@ describe('Waffle Schema', () => { ], }; - expect(() => waffleStateSchema.validate(input)).not.toThrow(); + expect(() => waffleConfigSchema.validate(input)).not.toThrow(); }); it('allows single metric with multiple collapsed breakdowns and one non-collapsed', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -294,11 +294,11 @@ describe('Waffle Schema', () => { ], }; - expect(() => waffleStateSchema.validate(input)).not.toThrow(); + expect(() => waffleConfigSchema.validate(input)).not.toThrow(); }); it('throws when single metric has multiple non-collapsed breakdowns', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -320,13 +320,13 @@ describe('Waffle Schema', () => { ], }; - expect(() => waffleStateSchema.validate(input)).toThrow( + expect(() => waffleConfigSchema.validate(input)).toThrow( /Only a single non-collapsed dimension is allowed for group_by/i ); }); it('allows multiple metrics without group_by', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -341,11 +341,11 @@ describe('Waffle Schema', () => { ], }; - expect(() => waffleStateSchema.validate(input)).not.toThrow(); + expect(() => waffleConfigSchema.validate(input)).not.toThrow(); }); it('throws with multiple metrics and a single non-collapsed breakdown', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -367,11 +367,11 @@ describe('Waffle Schema', () => { ], }; - expect(() => waffleStateSchema.validate(input)).toThrow(); + expect(() => waffleConfigSchema.validate(input)).toThrow(); }); it('allows multiple metrics with multiple collapsed breakdowns', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -402,11 +402,11 @@ describe('Waffle Schema', () => { ], }; - expect(() => waffleStateSchema.validate(input)).not.toThrow(); + expect(() => waffleConfigSchema.validate(input)).not.toThrow(); }); it('throws when multiple metrics have one collapsed and multiple non-collapsed breakdowns', () => { - const input: WaffleStateNoESQL = { + const input: WaffleConfigNoESQL = { ...baseWaffleConfig, metrics: [ { @@ -441,7 +441,7 @@ describe('Waffle Schema', () => { ], }; - expect(() => waffleStateSchema.validate(input)).toThrow( + expect(() => waffleConfigSchema.validate(input)).toThrow( /only collapsed group_by dimensions are allowed/i ); }); @@ -457,10 +457,10 @@ describe('Waffle Schema', () => { type: 'esql', query: 'FROM my-index | STATS count() BY category', }, - } satisfies Partial; + } satisfies Partial; it('validates minimal ES|QL configuration', () => { - const input: WaffleStateESQL = { + const input: WaffleConfigESQL = { ...baseESQLWaffleConfig, metrics: [ { @@ -469,13 +469,13 @@ describe('Waffle Schema', () => { ], }; - const validated = waffleStateSchema.validate(input); + const validated = waffleConfigSchema.validate(input); expect(validated.data_source.type).toBe('esql'); expect(validated.metrics[0]).toHaveProperty('column', 'count'); }); it('validates ES|QL configuration with group_by', () => { - const input: WaffleStateESQL = { + const input: WaffleConfigESQL = { ...baseESQLWaffleConfig, metrics: [ { @@ -489,7 +489,7 @@ describe('Waffle Schema', () => { ], }; - const validated = waffleStateSchema.validate(input); + const validated = waffleConfigSchema.validate(input); expect(validated.group_by).toHaveLength(1); if (validated.group_by?.[0] && 'column' in validated.group_by?.[0]) { expect(validated.group_by?.[0]?.column).toBe('category'); @@ -497,7 +497,7 @@ describe('Waffle Schema', () => { }); it('validates ES|QL configuration with multiple metrics', () => { - const input: WaffleStateESQL = { + const input: WaffleConfigESQL = { ...baseESQLWaffleConfig, metrics: [ { @@ -509,7 +509,7 @@ describe('Waffle Schema', () => { ], }; - const validated = waffleStateSchema.validate(input); + const validated = waffleConfigSchema.validate(input); expect(validated.metrics).toHaveLength(2); }); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.ts index 656f3fe200cc1..c502f424b94a1 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/waffle.ts @@ -28,7 +28,7 @@ import { } from './shared'; import { objectUnion } from './utils/object_union'; -const waffleStateSharedSchema = { +const waffleConfigSharedSchema = { legend: schema.maybe( schema.object( { @@ -74,7 +74,7 @@ const waffleStylingSchema = schema.object( /** * Color configuration for primary metric in waffle chart */ -const partitionStatePrimaryMetricOptionsSchema = { +const partitionConfigPrimaryMetricOptionsSchema = { /** * Color configuration */ @@ -88,7 +88,7 @@ const partitionStatePrimaryMetricOptionsSchema = { /** * Breakdown configuration including color mapping and collapse behavior */ -const partitionStateBreakdownByOptionsSchema = { +const partitionConfigBreakdownByOptionsSchema = { color: schema.maybe(colorMappingSchema), collapse_by: schema.maybe(collapseBySchema), }; @@ -96,18 +96,18 @@ const partitionStateBreakdownByOptionsSchema = { /** * Waffle chart configuration for standard (non-ES|QL) queries */ -export const waffleStateSchemaNoESQL = schema.object( +export const waffleConfigSchemaNoESQL = schema.object( { type: schema.literal('waffle'), ...sharedPanelInfoSchema, ...layerSettingsSchema, ...dataSourceSchema, ...dslOnlyPanelInfoSchema, - ...waffleStateSharedSchema, + ...waffleConfigSharedSchema, styling: schema.maybe(waffleStylingSchema), metrics: schema.arrayOf( mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps( - partitionStatePrimaryMetricOptionsSchema + partitionConfigPrimaryMetricOptionsSchema ), { minSize: 1, @@ -117,7 +117,7 @@ export const waffleStateSchemaNoESQL = schema.object( ), group_by: schema.maybe( schema.arrayOf( - mergeAllBucketsWithChartDimensionSchema(partitionStateBreakdownByOptionsSchema), + mergeAllBucketsWithChartDimensionSchema(partitionConfigBreakdownByOptionsSchema), { minSize: 1, maxSize: 100, @@ -139,16 +139,16 @@ export const waffleStateSchemaNoESQL = schema.object( /** * Waffle chart configuration for ES|QL queries */ -export const waffleStateSchemaESQL = schema.object( +export const waffleConfigSchemaESQL = schema.object( { type: schema.literal('waffle'), ...sharedPanelInfoSchema, ...layerSettingsSchema, ...dataSourceEsqlTableSchema, - ...waffleStateSharedSchema, + ...waffleConfigSharedSchema, styling: schema.maybe(waffleStylingSchema), metrics: schema.arrayOf( - esqlColumnWithFormatSchema.extends(partitionStatePrimaryMetricOptionsSchema), + esqlColumnWithFormatSchema.extends(partitionConfigPrimaryMetricOptionsSchema), { minSize: 1, maxSize: 100, @@ -156,7 +156,7 @@ export const waffleStateSchemaESQL = schema.object( } ), group_by: schema.maybe( - schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionStateBreakdownByOptionsSchema), { + schema.arrayOf(esqlColumnWithFormatSchema.extends(partitionConfigBreakdownByOptionsSchema), { minSize: 1, maxSize: 100, meta: { description: 'Array of ES|QL breakdown columns (minimum 1)' }, @@ -176,7 +176,7 @@ export const waffleStateSchemaESQL = schema.object( /** * Complete waffle chart configuration supporting both standard and ES|QL queries */ -export const waffleStateSchema = objectUnion([waffleStateSchemaNoESQL, waffleStateSchemaESQL], { +export const waffleConfigSchema = objectUnion([waffleConfigSchemaNoESQL, waffleConfigSchemaESQL], { meta: { id: 'waffleChart', title: 'Waffle Chart', @@ -184,6 +184,6 @@ export const waffleStateSchema = objectUnion([waffleStateSchemaNoESQL, waffleSta }, }); -export type WaffleState = TypeOf; -export type WaffleStateNoESQL = TypeOf; -export type WaffleStateESQL = TypeOf; +export type WaffleConfig = TypeOf; +export type WaffleConfigNoESQL = TypeOf; +export type WaffleConfigESQL = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.test.ts index b57b36f32e30e..4542ca5a63201 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.test.ts @@ -9,8 +9,8 @@ import type { TypeOf } from '@kbn/config-schema'; import type { DataSourceTypeESQL } from '../data_source'; -import type { xyDataLayerSharedSchema, XYState } from './xy'; -import { statisticsOptionsSize, statisticsSchema, xyStateSchema } from './xy'; +import type { xyDataLayerSharedSchema, XYConfig } from './xy'; +import { statisticsOptionsSize, statisticsSchema, xyConfigSchema } from './xy'; import { AS_CODE_DATA_VIEW_REFERENCE_TYPE, AS_CODE_DATA_VIEW_SPEC_TYPE, @@ -62,14 +62,14 @@ describe('XY', () => { y: [{ operation: 'count', empty_as_null: false }], }, ], - } satisfies XYState; - expect(() => xyStateSchema.validate(input)).not.toThrow(); + } satisfies XYConfig; + expect(() => xyConfigSchema.validate(input)).not.toThrow(); } ); it.each(anyType)('should pass validation for %s with breakdown', (type) => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `${type} Chart`, layers: [ @@ -82,7 +82,7 @@ describe('XY', () => { breakdown_by: { operation: 'terms', fields: ['product'], limit: 5 }, }, ], - } satisfies XYState) + } satisfies XYConfig) ).not.toThrow(); }); @@ -90,7 +90,7 @@ describe('XY', () => { 'should pass validation for a date histogram %s with breakdown with multiple terms', (type) => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `${type} Chart`, layers: [ @@ -110,14 +110,14 @@ describe('XY', () => { breakdown_by: { operation: 'terms', fields: ['product', 'category'], limit: 5 }, }, ], - } satisfies XYState) + } satisfies XYConfig) ).not.toThrow(); } ); it.each(anyType)('should pass validation in ES|QL mode as %s chart', (type) => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `${type} Chart`, layers: [ @@ -135,13 +135,13 @@ describe('XY', () => { breakdown_by: { column: 'product' }, }, ], - } satisfies XYState) + } satisfies XYConfig) ).not.toThrow(); }); it.each(anyType)('should support reference lines in %s charts', (type) => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `${type} Chart`, layers: [ @@ -180,13 +180,13 @@ describe('XY', () => { ], }, ], - } satisfies XYState) + } satisfies XYConfig) ).not.toThrow(); }); it.each(anyType)('should support annotations in %s charts', (type) => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `${type} Chart`, layers: [ @@ -226,7 +226,7 @@ describe('XY', () => { ], }, ], - } satisfies XYState) + } satisfies XYConfig) ).not.toThrow(); }); }); @@ -239,7 +239,7 @@ describe('XY', () => { 'should handle multiple metric in multiple layers with %s + %s', (type1, type2) => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `Mixed Chart`, layers: [ @@ -280,7 +280,7 @@ describe('XY', () => { breakdown_by: { operation: 'terms', fields: ['product', 'category'], limit: 5 }, }, ], - } satisfies XYState) + } satisfies XYConfig) ).not.toThrow(); } ); @@ -289,7 +289,7 @@ describe('XY', () => { 'should handle multiple metric in multiple layers %s + %s with reference lines and annotations', (type1, type2) => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `Mixed Chart`, layers: [ @@ -406,7 +406,7 @@ describe('XY', () => { ], }, ], - } satisfies XYState) + } satisfies XYConfig) ).not.toThrow(); } ); @@ -415,7 +415,7 @@ describe('XY', () => { 'should handle multiple metric in multiple layers %s + %s with reference lines and annotations (DSL layers only)', (type1, type2) => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `Mixed Chart`, layers: [ @@ -559,7 +559,7 @@ describe('XY', () => { ], }, ], - } satisfies XYState) + } satisfies XYConfig) ).not.toThrow(); } ); @@ -568,17 +568,17 @@ describe('XY', () => { describe('invalid xy charts', () => { it('should throw for no layers', () => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `Faulty Chart`, layers: [], - } satisfies XYState) + } satisfies XYConfig) ).toThrow(); }); it('should not let mix esql data_source with dsl operations', () => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `Faulty Chart`, layers: [ @@ -602,13 +602,13 @@ describe('XY', () => { breakdown_by: { operation: 'terms', fields: ['product', 'category'], limit: 5 }, }, ], - } satisfies XYState) + } satisfies XYConfig) ).toThrow(); }); it('should not let esql annotations', () => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: `Faulty Chart`, layers: [ @@ -649,13 +649,13 @@ describe('XY', () => { ], }, ], - } satisfies XYState) + } satisfies XYConfig) ).toThrow(); }); it('should reject mixing ES|QL and DSL layers in one chart', () => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: 'Mixed mode chart', layers: [ @@ -683,13 +683,13 @@ describe('XY', () => { y: [{ operation: 'value', column: 'value' }], }, ], - } as XYState) + } as XYConfig) ).toThrow(); }); it('should reject list legend layout for left positions', () => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: 'Invalid list legend position', legend: { @@ -722,7 +722,7 @@ describe('XY', () => { describe('legend layout schema', () => { it('should allow list legend layout for top/bottom', () => { expect(() => - xyStateSchema.validate({ + xyConfigSchema.validate({ type: 'xy', title: 'Valid list legend', legend: { diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.ts index 287745cb58e27..48d390452667c 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/xy.ts @@ -992,7 +992,7 @@ const xyLayerUnionESQL = objectUnion([xyDataLayerSchemaESQL], { /** * XY chart state for DSL layers */ -export const xyStateSchemaNoESQL = schema.object( +export const xyConfigSchemaNoESQL = schema.object( { type: schema.literal('xy'), ...sharedPanelInfoSchema, @@ -1016,7 +1016,7 @@ export const xyStateSchemaNoESQL = schema.object( /** * XY chart state for ES|QL layers only (reference lines are not supported) */ -export const xyStateSchemaESQL = schema.object( +export const xyConfigSchemaESQL = schema.object( { type: schema.literal('xy'), ...sharedPanelInfoSchema, @@ -1039,7 +1039,7 @@ export const xyStateSchemaESQL = schema.object( /** * XY chart state */ -export const xyStateSchema = objectUnion([xyStateSchemaNoESQL, xyStateSchemaESQL], { +export const xyConfigSchema = objectUnion([xyConfigSchemaNoESQL, xyConfigSchemaESQL], { meta: { id: 'xyChart', title: 'XY Chart', @@ -1047,9 +1047,9 @@ export const xyStateSchema = objectUnion([xyStateSchemaNoESQL, xyStateSchemaESQL }, }); -export type XYStateNoESQL = TypeOf; -export type XYStateESQL = TypeOf; -export type XYState = TypeOf; +export type XYConfigNoESQL = TypeOf; +export type XYConfigESQL = TypeOf; +export type XYConfig = TypeOf; export type DataLayerTypeESQL = TypeOf; export type DataLayerTypeNoESQL = TypeOf; export type DataLayerType = DataLayerTypeNoESQL | DataLayerTypeESQL; @@ -1071,5 +1071,3 @@ export type LayerTypeNoESQL = | ReferenceLineLayerTypeNoESQL | AnnotationLayerType; export type XYLayer = LayerTypeNoESQL | LayerTypeESQL; - -export type XYStyling = TypeOf; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/index.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/index.ts index 1859f14c000a4..e4ad4261706bf 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/index.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/index.ts @@ -16,212 +16,221 @@ import type { } from '@kbn/config-schema/src/types'; import type { ObjectUnionType } from './charts/utils/object_union'; import { objectUnion } from './charts/utils/object_union'; -import type { MetricState, MetricStateESQL, MetricStateNoESQL } from './charts/metric'; -import { esqlMetricState, metricStateSchema, metricStateSchemaNoESQL } from './charts/metric'; -import type { LegacyMetricState, LegacyMetricStateNoESQL } from './charts/legacy_metric'; -import { legacyMetricStateSchema, legacyMetricStateSchemaNoESQL } from './charts/legacy_metric'; -import type { GaugeState, GaugeStateESQL, GaugeStateNoESQL } from './charts/gauge'; -import { gaugeStateSchema, gaugeStateSchemaESQL, gaugeStateSchemaNoESQL } from './charts/gauge'; -import type { HeatmapState, HeatmapStateESQL, HeatmapStateNoESQL } from './charts/heatmap'; +import type { MetricConfig, MetricConfigESQL, MetricConfigNoESQL } from './charts/metric'; import { - heatmapStateSchema, - heatmapStateSchemaESQL, - heatmapStateSchemaNoESQL, + metricConfigSchema, + metricConfigSchemaESQL, + metricConfigSchemaNoESQL, +} from './charts/metric'; +import type { LegacyMetricConfig, LegacyMetricConfigNoESQL } from './charts/legacy_metric'; +import { legacyMetricConfigSchema, legacyMetricConfigSchemaNoESQL } from './charts/legacy_metric'; +import type { GaugeConfig, GaugeConfigESQL, GaugeConfigNoESQL } from './charts/gauge'; +import { gaugeConfigSchema, gaugeConfigSchemaESQL, gaugeConfigSchemaNoESQL } from './charts/gauge'; +import type { HeatmapConfig, HeatmapConfigESQL, HeatmapConfigNoESQL } from './charts/heatmap'; +import { + heatmapConfigSchema, + heatmapConfigSchemaESQL, + heatmapConfigSchemaNoESQL, } from './charts/heatmap'; -import type { TagcloudState, TagcloudStateESQL, TagcloudStateNoESQL } from './charts/tagcloud'; +import type { TagcloudConfig, TagcloudConfigESQL, TagcloudConfigNoESQL } from './charts/tagcloud'; import { - tagcloudStateSchema, - tagcloudStateSchemaESQL, - tagcloudStateSchemaNoESQL, + tagcloudConfigSchema, + tagcloudConfigSchemaESQL, + tagcloudConfigSchemaNoESQL, } from './charts/tagcloud'; -import type { XYState, XYStateESQL, XYStateNoESQL } from './charts/xy'; -import { xyStateSchema, xyStateSchemaESQL, xyStateSchemaNoESQL } from './charts/xy'; -import type { RegionMapState, RegionMapStateESQL, RegionMapStateNoESQL } from './charts/region_map'; +import type { XYConfig, XYConfigESQL, XYConfigNoESQL } from './charts/xy'; +import { xyConfigSchema, xyConfigSchemaESQL, xyConfigSchemaNoESQL } from './charts/xy'; +import type { + RegionMapConfig, + RegionMapConfigESQL, + RegionMapConfigNoESQL, +} from './charts/region_map'; import { - regionMapStateSchema, - regionMapStateSchemaESQL, - regionMapStateSchemaNoESQL, + regionMapConfigSchema, + regionMapConfigSchemaESQL, + regionMapConfigSchemaNoESQL, } from './charts/region_map'; -import type { DatatableState, DatatableStateESQL, DatatableStateNoESQL } from './charts/datatable'; +import type { + DatatableConfig, + DatatableConfigESQL, + DatatableConfigNoESQL, +} from './charts/datatable'; import { - datatableStateSchema, - datatableStateSchemaESQL, - datatableStateSchemaNoESQL, + datatableConfigSchema, + datatableConfigSchemaESQL, + datatableConfigSchemaNoESQL, } from './charts/datatable'; import type { LensApiAllMetricOrFormulaOperations, LensApiStaticValueOperation, } from './metric_ops'; import type { LensApiBucketOperations } from './bucket_ops'; -import type { MosaicState, MosaicStateESQL, MosaicStateNoESQL } from './charts/mosaic'; -import { mosaicStateSchema, mosaicStateSchemaESQL, mosaicStateSchemaNoESQL } from './charts/mosaic'; -import type { TreemapState, TreemapStateESQL, TreemapStateNoESQL } from './charts/treemap'; +import type { MosaicConfig, MosaicConfigESQL, MosaicConfigNoESQL } from './charts/mosaic'; +import { + mosaicConfigSchema, + mosaicConfigSchemaESQL, + mosaicConfigSchemaNoESQL, +} from './charts/mosaic'; +import type { TreemapConfig, TreemapConfigESQL, TreemapConfigNoESQL } from './charts/treemap'; import { - treemapStateSchema, - treemapStateSchemaESQL, - treemapStateSchemaNoESQL, + treemapConfigSchema, + treemapConfigSchemaESQL, + treemapConfigSchemaNoESQL, } from './charts/treemap'; -import type { WaffleState, WaffleStateESQL, WaffleStateNoESQL } from './charts/waffle'; -import { waffleStateSchema, waffleStateSchemaESQL, waffleStateSchemaNoESQL } from './charts/waffle'; -import type { PieState, PieStateESQL, PieStateNoESQL } from './charts/pie'; -import { pieStateSchema, pieStateSchemaESQL, pieStateSchemaNoESQL } from './charts/pie'; +import type { WaffleConfig, WaffleConfigESQL, WaffleConfigNoESQL } from './charts/waffle'; +import { + waffleConfigSchema, + waffleConfigSchemaESQL, + waffleConfigSchemaNoESQL, +} from './charts/waffle'; +import type { PieConfig, PieConfigESQL, PieConfigNoESQL } from './charts/pie'; +import { pieConfigSchema, pieConfigSchemaESQL, pieConfigSchemaNoESQL } from './charts/pie'; /** * We need to break the type inference here to avoid exceeding the ts compiler serialization limit. * * This requires: * - Casting the schema as any - * - Defining the `LensApiState` type from the schema types - * - Exporting this value as `Type` + * - Defining the `LensApiConfig` type from the schema types + * - Exporting this value as `Type` */ -export const _lensApiStateSchema: any = objectUnion( +export const _lensApiConfigSchema: any = objectUnion( [ - ...metricStateSchema.getUnionTypes(), - ...legacyMetricStateSchema.getUnionTypes(), - ...xyStateSchema.getUnionTypes(), - ...gaugeStateSchema.getUnionTypes(), - ...heatmapStateSchema.getUnionTypes(), - ...tagcloudStateSchema.getUnionTypes(), - ...regionMapStateSchema.getUnionTypes(), - ...datatableStateSchema.getUnionTypes(), - ...pieStateSchema.getUnionTypes(), - ...mosaicStateSchema.getUnionTypes(), - ...treemapStateSchema.getUnionTypes(), - ...waffleStateSchema.getUnionTypes(), + ...metricConfigSchema.getUnionTypes(), + ...legacyMetricConfigSchema.getUnionTypes(), + ...xyConfigSchema.getUnionTypes(), + ...gaugeConfigSchema.getUnionTypes(), + ...heatmapConfigSchema.getUnionTypes(), + ...tagcloudConfigSchema.getUnionTypes(), + ...regionMapConfigSchema.getUnionTypes(), + ...datatableConfigSchema.getUnionTypes(), + ...pieConfigSchema.getUnionTypes(), + ...mosaicConfigSchema.getUnionTypes(), + ...treemapConfigSchema.getUnionTypes(), + ...waffleConfigSchema.getUnionTypes(), ], - { meta: { id: 'lensApiState', title: 'Visualizations' } } + { meta: { id: 'lensApiConfig', title: 'Visualizations' } } ); -export type LensApiState = - | MetricState - | LegacyMetricState - | GaugeState - | XYState - | HeatmapState - | TagcloudState - | RegionMapState - | DatatableState - | PieState - | MosaicState - | TreemapState - | WaffleState; - -export const lensApiStateSchema: Type = _lensApiStateSchema; +export type LensApiConfig = + | MetricConfig + | LegacyMetricConfig + | GaugeConfig + | XYConfig + | HeatmapConfig + | TagcloudConfig + | RegionMapConfig + | DatatableConfig + | PieConfig + | MosaicConfig + | TreemapConfig + | WaffleConfig; + +export const lensApiConfigSchema: Type = _lensApiConfigSchema; /** * We need to break the type inference here to avoid exceeding the ts compiler serialization limit. * * This requires: * - Casting the schema as any - * - Defining the `LensApiState` type from the schema types - * - Exporting this value as `Type` + * - Defining the `LensApiConfig` type from the schema types + * - Exporting this value as `Type` */ -export const _lensApiStateSchemaNoESQL: any = objectUnion( +export const _lensApiConfigSchemaNoESQL: any = objectUnion( [ - metricStateSchemaNoESQL, - legacyMetricStateSchemaNoESQL, - xyStateSchemaNoESQL, - gaugeStateSchemaNoESQL, - heatmapStateSchemaNoESQL, - tagcloudStateSchemaNoESQL, - regionMapStateSchemaNoESQL, - datatableStateSchemaNoESQL, - pieStateSchemaNoESQL, - mosaicStateSchemaNoESQL, - treemapStateSchemaNoESQL, - waffleStateSchemaNoESQL, + metricConfigSchemaNoESQL, + legacyMetricConfigSchemaNoESQL, + xyConfigSchemaNoESQL, + gaugeConfigSchemaNoESQL, + heatmapConfigSchemaNoESQL, + tagcloudConfigSchemaNoESQL, + regionMapConfigSchemaNoESQL, + datatableConfigSchemaNoESQL, + pieConfigSchemaNoESQL, + mosaicConfigSchemaNoESQL, + treemapConfigSchemaNoESQL, + waffleConfigSchemaNoESQL, ], - { meta: { id: 'lensApiStateNoESQL', title: 'Visualizations (DSL)' } } + { meta: { id: 'lensApiConfigNoESQL', title: 'Visualizations (DSL)' } } ); -export type LensApiStateNoESQL = - | MetricStateNoESQL - | LegacyMetricStateNoESQL - | GaugeStateNoESQL - | XYStateNoESQL - | HeatmapStateNoESQL - | TagcloudStateNoESQL - | RegionMapStateNoESQL - | DatatableStateNoESQL - | PieStateNoESQL - | MosaicStateNoESQL - | TreemapStateNoESQL - | WaffleStateNoESQL; - -export const lensApiStateSchemaNoESQL: Type = _lensApiStateSchemaNoESQL; +export type LensApiConfigNoESQL = + | MetricConfigNoESQL + | LegacyMetricConfigNoESQL + | GaugeConfigNoESQL + | XYConfigNoESQL + | HeatmapConfigNoESQL + | TagcloudConfigNoESQL + | RegionMapConfigNoESQL + | DatatableConfigNoESQL + | PieConfigNoESQL + | MosaicConfigNoESQL + | TreemapConfigNoESQL + | WaffleConfigNoESQL; + +export const lensApiConfigSchemaNoESQL: Type = _lensApiConfigSchemaNoESQL; /** * We need to break the type inference here to avoid exceeding the ts compiler serialization limit. * * This requires: * - Casting the schema as any - * - Defining the `LensApiState` type from the schema types - * - Exporting this value as `Type` + * - Defining the `LensApiConfig` type from the schema types + * - Exporting this value as `Type` */ -export const _lensApiStateSchemaESQL: any = objectUnion( +export const _lensApiConfigSchemaESQL: any = objectUnion( [ - esqlMetricState, - xyStateSchemaESQL, - gaugeStateSchemaESQL, - heatmapStateSchemaESQL, - tagcloudStateSchemaESQL, - regionMapStateSchemaESQL, - datatableStateSchemaESQL, - pieStateSchemaESQL, - mosaicStateSchemaESQL, - treemapStateSchemaESQL, - waffleStateSchemaESQL, + metricConfigSchemaESQL, + xyConfigSchemaESQL, + gaugeConfigSchemaESQL, + heatmapConfigSchemaESQL, + tagcloudConfigSchemaESQL, + regionMapConfigSchemaESQL, + datatableConfigSchemaESQL, + pieConfigSchemaESQL, + mosaicConfigSchemaESQL, + treemapConfigSchemaESQL, + waffleConfigSchemaESQL, ], - { meta: { id: 'lensApiStateESQL', title: 'Visualizations (ES|QL)' } } + { meta: { id: 'lensApiConfigESQL', title: 'Visualizations (ES|QL)' } } ); -export type LensApiStateESQL = - | MetricStateESQL - | GaugeStateESQL - | XYStateESQL - | HeatmapStateESQL - | TagcloudStateESQL - | RegionMapStateESQL - | DatatableStateESQL - | PieStateESQL - | MosaicStateESQL - | TreemapStateESQL - | WaffleStateESQL; - -export const lensApiStateSchemaESQL: Type = _lensApiStateSchemaESQL; +export type LensApiConfigESQL = + | MetricConfigESQL + | GaugeConfigESQL + | XYConfigESQL + | HeatmapConfigESQL + | TagcloudConfigESQL + | RegionMapConfigESQL + | DatatableConfigESQL + | PieConfigESQL + | MosaicConfigESQL + | TreemapConfigESQL + | WaffleConfigESQL; + +export const lensApiConfigSchemaESQL: Type = _lensApiConfigSchemaESQL; /** - * Extends `lensApiStateSchema` with extra props and options. + * Extends `lensApiConfigSchema` with extra props and options. * - * This type will be be union of all `LensApiState` intersected with the new props. + * This type will be be union of all `LensApiConfig` intersected with the new props. */ -export function extendLensApiStateSchema( +export function extendLensApiConfigSchema( props: T, - options?: TypeOptions -): Type> { + options?: TypeOptions +): Type> { // these types are a bit of a hack mainly due to the tsc compiler limit // but baseSchema can extend with any props correctly and return the correct `Type` wrapper - const baseSchema = _lensApiStateSchema as ObjectUnionType<[ObjectType], LensApiState & T>; + const baseSchema = _lensApiConfigSchema as ObjectUnionType<[ObjectType], LensApiConfig & T>; return baseSchema.extends(props, options as any).toType(); } -export type { MetricState, metricStateSchemaNoESQL } from './charts/metric'; -export type { LegacyMetricState, legacyMetricStateSchemaNoESQL } from './charts/legacy_metric'; -export type { XYState, XYStateNoESQL, XYStateESQL, XYLayer } from './charts/xy'; -export type { GaugeState, gaugeStateSchemaNoESQL } from './charts/gauge'; -export type { HeatmapState, heatmapStateSchemaNoESQL } from './charts/heatmap'; -export type { TagcloudState, TagcloudStateNoESQL, TagcloudStateESQL } from './charts/tagcloud'; -export type { RegionMapState, RegionMapStateNoESQL, RegionMapStateESQL } from './charts/region_map'; -export type { DatatableState, DatatableStateNoESQL, DatatableStateESQL } from './charts/datatable'; -export { tagcloudStateSchema } from './charts/tagcloud'; -export { regionMapStateSchema } from './charts/region_map'; -export { datatableStateSchema } from './charts/datatable'; - export type { LensApiFieldMetricOrFormulaOperation, LensApiAllMetricOrFormulaOperations, } from './metric_ops'; export type { LensApiBucketOperations } from './bucket_ops'; +export type { XYLayer } from './charts/xy'; export type NarrowByType = T extends { type?: U } ? T : never; @@ -229,3 +238,85 @@ export type LensApiAllOperations = | LensApiAllMetricOrFormulaOperations | LensApiBucketOperations | LensApiStaticValueOperation; + +export { + // Combined schemas + metricConfigSchema, + legacyMetricConfigSchema, + gaugeConfigSchema, + tagcloudConfigSchema, + xyConfigSchema, + regionMapConfigSchema, + heatmapConfigSchema, + datatableConfigSchema, + pieConfigSchema, + treemapConfigSchema, + waffleConfigSchema, + mosaicConfigSchema, + // ESQL schemas + metricConfigSchemaESQL, + gaugeConfigSchemaESQL, + tagcloudConfigSchemaESQL, + xyConfigSchemaESQL, + regionMapConfigSchemaESQL, + heatmapConfigSchemaESQL, + datatableConfigSchemaESQL, + pieConfigSchemaESQL, + treemapConfigSchemaESQL, + waffleConfigSchemaESQL, + mosaicConfigSchemaESQL, + // DSL schemas + metricConfigSchemaNoESQL, + legacyMetricConfigSchemaNoESQL, + gaugeConfigSchemaNoESQL, + tagcloudConfigSchemaNoESQL, + xyConfigSchemaNoESQL, + regionMapConfigSchemaNoESQL, + heatmapConfigSchemaNoESQL, + datatableConfigSchemaNoESQL, + pieConfigSchemaNoESQL, + treemapConfigSchemaNoESQL, + waffleConfigSchemaNoESQL, + mosaicConfigSchemaNoESQL, +}; + +export type { + // Combined schemas + MetricConfig, + LegacyMetricConfig, + GaugeConfig, + TagcloudConfig, + XYConfig, + RegionMapConfig, + HeatmapConfig, + DatatableConfig, + PieConfig, + TreemapConfig, + WaffleConfig, + MosaicConfig, + // ESQL schemas + MetricConfigESQL, + GaugeConfigESQL, + TagcloudConfigESQL, + XYConfigESQL, + RegionMapConfigESQL, + HeatmapConfigESQL, + DatatableConfigESQL, + PieConfigESQL, + TreemapConfigESQL, + WaffleConfigESQL, + MosaicConfigESQL, + // DSL schemas + MetricConfigNoESQL, + LegacyMetricConfigNoESQL, + GaugeConfigNoESQL, + TagcloudConfigNoESQL, + XYConfigNoESQL, + RegionMapConfigNoESQL, + HeatmapConfigNoESQL, + DatatableConfigNoESQL, + PieConfigNoESQL, + TreemapConfigNoESQL, + WaffleConfigNoESQL, + MosaicConfigNoESQL, +}; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/datatable.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/datatable.test.ts index 62df8f0e8b56f..374baec5368fd 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/datatable.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/datatable.test.ts @@ -8,8 +8,9 @@ */ import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; -import { datatableStateSchema } from '../../schema'; -import type { DatatableState } from '../../schema'; + +import { datatableConfigSchema } from '../../schema'; +import type { DatatableConfig } from '../../schema'; import { AUTO_COLOR } from '../../schema/color'; import { LensConfigBuilder } from '../../config_builder'; import { validateAPIConverter, validateConverter } from '../validate'; @@ -49,103 +50,103 @@ import { describe('Datatable', () => { describe('validateConverter', () => { it('should convert a datatable chart with single metric column', () => { - validateConverter(singleMetricDatatableAttributes, datatableStateSchema); + validateConverter(singleMetricDatatableAttributes, datatableConfigSchema); }); it('should convert a datatable chart with single metric, row, split by columns', () => { - validateConverter(singleMetricRowSplitDatatableAttributes, datatableStateSchema); + validateConverter(singleMetricRowSplitDatatableAttributes, datatableConfigSchema); }); it('should convert a datatable chart with multiple metrics, rows, split by columns', () => { - validateConverter(multiMetricRowSplitDatatableAttributes, datatableStateSchema); + validateConverter(multiMetricRowSplitDatatableAttributes, datatableConfigSchema); }); it('should convert a datatable chart with full config', () => { - validateConverter(fullConfigDatatableAttributes, datatableStateSchema); + validateConverter(fullConfigDatatableAttributes, datatableConfigSchema); }); it('should convert a datatable chart sorted by a transposed metric column', () => { - validateConverter(sortedByTransposedMetricColumnDatatableAttributes, datatableStateSchema); + validateConverter(sortedByTransposedMetricColumnDatatableAttributes, datatableConfigSchema); }); it('should convert a datatable chart sorted by a row', () => { - validateConverter(sortedByRowDatatableAttributes, datatableStateSchema); + validateConverter(sortedByRowDatatableAttributes, datatableConfigSchema); }); it('should convert an ESQL datatable chart with single metric column', () => { - validateConverter(singleMetricESQLDatatableAttributes, datatableStateSchema); + validateConverter(singleMetricESQLDatatableAttributes, datatableConfigSchema); }); it('should convert an ESQL datatable chart with single metric, row, split by columns', () => { - validateConverter(singleMetricRowSplitESQLDatatableAttributes, datatableStateSchema); + validateConverter(singleMetricRowSplitESQLDatatableAttributes, datatableConfigSchema); }); it('should convert an ESQL datatable chart with multiple metrics, rows, split by columns', () => { - validateConverter(multipleMetricRowSplitESQLDatatableAttributes, datatableStateSchema); + validateConverter(multipleMetricRowSplitESQLDatatableAttributes, datatableConfigSchema); }); it('should convert an ESQL datatable chart with full config', () => { - validateConverter(fullConfigESQLDatatableAttributes, datatableStateSchema); + validateConverter(fullConfigESQLDatatableAttributes, datatableConfigSchema); }); it('should convert an ESQL datatable chart sorted by a transposed metric column', () => { validateConverter( sortedByTransposedMetricColumnESQLDatatableAttributes, - datatableStateSchema + datatableConfigSchema ); }); it('should convert a default color by value palette', () => { - validateConverter(defaultColorByValueAttributes, datatableStateSchema); + validateConverter(defaultColorByValueAttributes, datatableConfigSchema); }); it('should convert a selector color by value palette', () => { - validateConverter(selectorColorByValueAttributes, datatableStateSchema); + validateConverter(selectorColorByValueAttributes, datatableConfigSchema); }); }); describe('validateAPIConverter ', () => { it('should convert a datatable chart with single metric column', () => { - validateAPIConverter(singleMetricDatatableWithAdhocDataView, datatableStateSchema); + validateAPIConverter(singleMetricDatatableWithAdhocDataView, datatableConfigSchema); }); it('should convert a datatable chart with multiple metrics, rows, split by columns', () => { - validateAPIConverter(multiMetricRowSplitByDatatableWithAdhocDataView, datatableStateSchema); + validateAPIConverter(multiMetricRowSplitByDatatableWithAdhocDataView, datatableConfigSchema); }); it('should convert a datatable chart with full config and ad hoc dataView', () => { - validateAPIConverter(fullConfigDatatableWithAdhocDataView, datatableStateSchema); + validateAPIConverter(fullConfigDatatableWithAdhocDataView, datatableConfigSchema); }); it('should convert a datatable chart with full config and dataView', () => { - validateAPIConverter(fullConfigDatatableWithDataView, datatableStateSchema); + validateAPIConverter(fullConfigDatatableWithDataView, datatableConfigSchema); }); it('should convert a datatable chart sorted by a transposed column', () => { - validateAPIConverter(sortedByPivotedMetricColumnDatatable, datatableStateSchema); + validateAPIConverter(sortedByPivotedMetricColumnDatatable, datatableConfigSchema); }); it('should convert a datatable chart sorted by a row column', () => { - validateAPIConverter(sortedByRowDatatable, datatableStateSchema); + validateAPIConverter(sortedByRowDatatable, datatableConfigSchema); }); it('should convert an ESQL datatable chart with single metric column', () => { - validateAPIConverter(singleMetricESQLDatatable, datatableStateSchema); + validateAPIConverter(singleMetricESQLDatatable, datatableConfigSchema); }); it('should convert an ESQL datatable chart with multiple metrics, rows, split by columns', () => { - validateAPIConverter(multipleMetricRowSplitESQLDatatable, datatableStateSchema); + validateAPIConverter(multipleMetricRowSplitESQLDatatable, datatableConfigSchema); }); it('should convert an ESQL datatable chart with full config', () => { - validateAPIConverter(fullConfigESQLDatatable, datatableStateSchema); + validateAPIConverter(fullConfigESQLDatatable, datatableConfigSchema); }); it('should convert an ESQL datatable chart sorted by a transposed column', () => { - validateAPIConverter(sortedByPivotedMetricColumnESQLDatatable, datatableStateSchema); + validateAPIConverter(sortedByPivotedMetricColumnESQLDatatable, datatableConfigSchema); }); it('should convert an ESQL datatable chart sorted by a row column', () => { - validateAPIConverter(sortedByRowColumnESQLDatatable, datatableStateSchema); + validateAPIConverter(sortedByRowColumnESQLDatatable, datatableConfigSchema); }); }); @@ -172,11 +173,11 @@ describe('Datatable', () => { apply_color_to: 'value', }, ], - } satisfies DatatableState; + } satisfies DatatableConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as DatatableState; + const apiOutput = builder.toAPIFormat(lensState) as DatatableConfig; expect(apiOutput.metrics?.[0].color).toEqual(AUTO_COLOR); expect(apiOutput.metrics?.[0].apply_color_to).toBe('value'); @@ -194,11 +195,11 @@ describe('Datatable', () => { apply_color_to: 'background', }, ], - } satisfies DatatableState; + } satisfies DatatableConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as DatatableState; + const apiOutput = builder.toAPIFormat(lensState) as DatatableConfig; expect(apiOutput.rows?.[0].color).toEqual(AUTO_COLOR); expect(apiOutput.rows?.[0].apply_color_to).toBe('background'); @@ -213,11 +214,11 @@ describe('Datatable', () => { empty_as_null: false, }, ], - } satisfies DatatableState; + } satisfies DatatableConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as DatatableState; + const apiOutput = builder.toAPIFormat(lensState) as DatatableConfig; expect(apiOutput.metrics?.[0].color).not.toBeDefined(); expect(apiOutput.metrics?.[0].apply_color_to).not.toBeDefined(); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_dsl.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_dsl.mock.ts index af944edadf0c7..d81fec7a00330 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_dsl.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_dsl.mock.ts @@ -11,12 +11,12 @@ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE, AS_CODE_DATA_VIEW_SPEC_TYPE, } from '@kbn/as-code-data-views-schema'; -import type { DatatableState, DatatableStateNoESQL } from '../../schema'; +import type { DatatableConfig, DatatableConfigNoESQL } from '../../schema'; /** * Basic datatable with single metric column and ad hoc dataView */ -export const singleMetricDatatableWithAdhocDataView: DatatableState = { +export const singleMetricDatatableWithAdhocDataView: DatatableConfig = { title: 'Single metric', type: 'data_table', data_source: { @@ -32,12 +32,12 @@ export const singleMetricDatatableWithAdhocDataView: DatatableState = { empty_as_null: true, }, ], -} satisfies DatatableStateNoESQL; +} satisfies DatatableConfigNoESQL; /** * Datatable with multiple metrics, rows, and split_metrics_by columns */ -export const multiMetricRowSplitByDatatableWithAdhocDataView: DatatableState = { +export const multiMetricRowSplitByDatatableWithAdhocDataView: DatatableConfig = { title: 'Multiple metrics, rows, split by with ad hoc dataView', type: 'data_table', data_source: { @@ -108,12 +108,12 @@ export const multiMetricRowSplitByDatatableWithAdhocDataView: DatatableState = { }, }, ], -} satisfies DatatableStateNoESQL; +} satisfies DatatableConfigNoESQL; /** * Full config datatable and ad hoc dataView */ -export const fullConfigDatatableWithAdhocDataView: DatatableState = { +export const fullConfigDatatableWithAdhocDataView: DatatableConfig = { title: 'Multiple metrics, rows, split by with full config', type: 'data_table', data_source: { @@ -275,12 +275,12 @@ export const fullConfigDatatableWithAdhocDataView: DatatableState = { paging: 10, row_numbers: { visible: true }, }, -} satisfies DatatableStateNoESQL; +} satisfies DatatableConfigNoESQL; /** * Full config datatable and dataView */ -export const fullConfigDatatableWithDataView: DatatableState = { +export const fullConfigDatatableWithDataView: DatatableConfig = { title: 'Multiple metrics, rows, split by with full config', type: 'data_table', data_source: { @@ -440,12 +440,12 @@ export const fullConfigDatatableWithDataView: DatatableState = { }, paging: 10, }, -} satisfies DatatableStateNoESQL; +} satisfies DatatableConfigNoESQL; /** * Datatable sorted by a pivoted metric column (split_metrics_by) */ -export const sortedByPivotedMetricColumnDatatable: DatatableState = { +export const sortedByPivotedMetricColumnDatatable: DatatableConfig = { title: 'Sorted by a pivoted metric column', type: 'data_table', data_source: { @@ -611,12 +611,12 @@ export const sortedByPivotedMetricColumnDatatable: DatatableState = { direction: 'desc', }, }, -} satisfies DatatableStateNoESQL; +} satisfies DatatableConfigNoESQL; /** * Datatable sorted by a row column */ -export const sortedByRowDatatable: DatatableState = { +export const sortedByRowDatatable: DatatableConfig = { title: 'Sorted by row column', type: 'data_table', data_source: { @@ -781,4 +781,4 @@ export const sortedByRowDatatable: DatatableState = { direction: 'asc', }, }, -} satisfies DatatableStateNoESQL; +} satisfies DatatableConfigNoESQL; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_esql.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_esql.mock.ts index 302e77821ed4a..7fb345bf46939 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_esql.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/datatable/lens_api_config_esql.mock.ts @@ -7,12 +7,12 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { DatatableState, DatatableStateESQL } from '../../schema'; +import type { DatatableConfig, DatatableConfigESQL } from '../../schema'; /** * Basic ESQL datatable with single metric column */ -export const singleMetricESQLDatatable: DatatableState = { +export const singleMetricESQLDatatable: DatatableConfig = { title: 'Single metric', type: 'data_table', data_source: { @@ -26,12 +26,12 @@ export const singleMetricESQLDatatable: DatatableState = { column: 'bytes', }, ], -} satisfies DatatableStateESQL; +} satisfies DatatableConfigESQL; /** * ESQL datatable with multiple metrics, rows, and split_metrics_by columns */ -export const multipleMetricRowSplitESQLDatatable: DatatableState = { +export const multipleMetricRowSplitESQLDatatable: DatatableConfig = { title: 'Multiple metrics, rows, split by', type: 'data_table', data_source: { @@ -64,12 +64,12 @@ export const multipleMetricRowSplitESQLDatatable: DatatableState = { column: 'geo.dest', }, ], -} satisfies DatatableStateESQL; +} satisfies DatatableConfigESQL; /** * Full config ESQL datatable */ -export const fullConfigESQLDatatable: DatatableState = { +export const fullConfigESQLDatatable: DatatableConfig = { title: 'Full config', type: 'data_table', data_source: { @@ -157,12 +157,12 @@ export const fullConfigESQLDatatable: DatatableState = { }, paging: 10, }, -} satisfies DatatableStateESQL; +} satisfies DatatableConfigESQL; /** * ESQL datatable sorted by a pivoted metric column (split_metrics_by) */ -export const sortedByPivotedMetricColumnESQLDatatable: DatatableState = { +export const sortedByPivotedMetricColumnESQLDatatable: DatatableConfig = { title: 'Sorted by pivoted metric column', type: 'data_table', data_source: { @@ -256,12 +256,12 @@ export const sortedByPivotedMetricColumnESQLDatatable: DatatableState = { direction: 'desc', }, }, -} satisfies DatatableStateESQL; +} satisfies DatatableConfigESQL; /** * ESQL datatable sorted by a row column */ -export const sortedByRowColumnESQLDatatable: DatatableState = { +export const sortedByRowColumnESQLDatatable: DatatableConfig = { title: 'Sorted by row column', type: 'data_table', data_source: { @@ -354,4 +354,4 @@ export const sortedByRowColumnESQLDatatable: DatatableState = { direction: 'desc', }, }, -} satisfies DatatableStateESQL; +} satisfies DatatableConfigESQL; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/gauge.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/gauge.test.ts index 5eb25454e4713..ae4917aa7eb57 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/gauge.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/gauge.test.ts @@ -8,8 +8,9 @@ */ import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; -import { gaugeStateSchema } from '../../schema/charts/gauge'; -import type { GaugeState } from '../../schema/charts/gauge'; + +import { gaugeConfigSchema } from '../../schema/charts/gauge'; +import type { GaugeConfig } from '../../schema/charts/gauge'; import { AUTO_COLOR, NO_COLOR } from '../../schema/color'; import { LensConfigBuilder } from '../../config_builder'; import { validateAPIConverter, validateConverter } from '../validate'; @@ -32,48 +33,48 @@ import { describe('Gauge', () => { describe('validateConverter', () => { it('should convert a gauge chart with full config and absolute color mode', () => { - validateConverter(gaugeAttributes, gaugeStateSchema); + validateConverter(gaugeAttributes, gaugeConfigSchema); }); it('should convert a gauge chart with full config and percentage color mode', () => { - validateConverter(gaugeAttributesWithPercentageColorMode, gaugeStateSchema); + validateConverter(gaugeAttributesWithPercentageColorMode, gaugeConfigSchema); }); it('should convert a gauge chart with ESQL datasource', () => { - validateConverter(gaugeESQLAttributes, gaugeStateSchema); + validateConverter(gaugeESQLAttributes, gaugeConfigSchema); }); it('should convert a default color by value palette', () => { - validateConverter(defaultColorByValueAttributes, gaugeStateSchema); + validateConverter(defaultColorByValueAttributes, gaugeConfigSchema); }); it('should convert a selector color by value palette', () => { - validateConverter(selectorColorByValueAttributes, gaugeStateSchema); + validateConverter(selectorColorByValueAttributes, gaugeConfigSchema); }); }); describe('validateAPIConverter', () => { it('should convert a basic gauge chart with ad hoc dataView', () => { - validateAPIConverter(basicGaugeWithAdHocDataView, gaugeStateSchema); + validateAPIConverter(basicGaugeWithAdHocDataView, gaugeConfigSchema); }); it('should convert a basic gauge chart with dataView', () => { - validateAPIConverter(basicGaugeWithDataView, gaugeStateSchema); + validateAPIConverter(basicGaugeWithDataView, gaugeConfigSchema); }); it('should convert a ESQL-based gauge chart', () => { - validateAPIConverter(esqlGauge, gaugeStateSchema); + validateAPIConverter(esqlGauge, gaugeConfigSchema); }); it('should convert a comprehensive gauge chart with ad hoc data view', () => { - validateAPIConverter(comprehensiveGaugeWithAdHocDataView, gaugeStateSchema); + validateAPIConverter(comprehensiveGaugeWithAdHocDataView, gaugeConfigSchema); }); it('should convert a comprehensive gauge chart with data view', () => { - validateAPIConverter(comprehensiveGaugeWithDataView, gaugeStateSchema); + validateAPIConverter(comprehensiveGaugeWithDataView, gaugeConfigSchema); }); it('should convert a comprehensive ESQL-based gauge chart', () => { - validateAPIConverter(comprehensiveEsqlGauge, gaugeStateSchema); + validateAPIConverter(comprehensiveEsqlGauge, gaugeConfigSchema); }); }); @@ -92,12 +93,12 @@ describe('Gauge', () => { }, sampling: 1, ignore_global_filters: false, - } satisfies GaugeState; + } satisfies GaugeConfig; it('should emit AUTO_COLOR when no color is specified', () => { const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(baseGauge); - const apiOutput = builder.toAPIFormat(lensState) as GaugeState; + const apiOutput = builder.toAPIFormat(lensState) as GaugeConfig; expect(apiOutput.metric.color).toEqual(AUTO_COLOR); }); @@ -106,11 +107,11 @@ describe('Gauge', () => { const config = { ...baseGauge, metric: { ...baseGauge.metric, color: NO_COLOR }, - } satisfies GaugeState; + } satisfies GaugeConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as GaugeState; + const apiOutput = builder.toAPIFormat(lensState) as GaugeConfig; expect(apiOutput.metric.color).toEqual(NO_COLOR); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/lens_api_config.mock.ts index ef6aa94a68e94..a34695b47d1fb 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/gauge/lens_api_config.mock.ts @@ -11,12 +11,12 @@ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE, AS_CODE_DATA_VIEW_SPEC_TYPE, } from '@kbn/as-code-data-views-schema'; -import type { GaugeState } from '../../schema/charts/gauge'; +import type { GaugeConfig } from '../../schema/charts/gauge'; /** * Basic gauge chart with ad hoc dataView */ -export const basicGaugeWithAdHocDataView: GaugeState = { +export const basicGaugeWithAdHocDataView: GaugeConfig = { type: 'gauge', title: 'Test Gauge', data_source: { @@ -36,7 +36,7 @@ export const basicGaugeWithAdHocDataView: GaugeState = { /** * Basic gauge chart with existing dataView */ -export const basicGaugeWithDataView: GaugeState = { +export const basicGaugeWithDataView: GaugeConfig = { type: 'gauge', title: 'Test Gauge', description: 'A test gauge chart', @@ -56,7 +56,7 @@ export const basicGaugeWithDataView: GaugeState = { /** * ESQL-based gauge chart */ -export const esqlGauge: GaugeState = { +export const esqlGauge: GaugeConfig = { type: 'gauge', title: 'Test ESQL Gauge', description: 'A test gauge chart using ESQL', @@ -74,7 +74,7 @@ export const esqlGauge: GaugeState = { /** * Comprehensive gauge chart with ad hoc dataView */ -export const comprehensiveGaugeWithAdHocDataView: GaugeState = { +export const comprehensiveGaugeWithAdHocDataView: GaugeConfig = { type: 'gauge', title: 'Comprehensive Test Gauge', description: 'A comprehensive metric chart with all features', @@ -112,7 +112,7 @@ export const comprehensiveGaugeWithAdHocDataView: GaugeState = { /** * Comprehensive gauge chart with existing dataView */ -export const comprehensiveGaugeWithDataView: GaugeState = { +export const comprehensiveGaugeWithDataView: GaugeConfig = { type: 'gauge', title: 'Comprehensive Test Gauge', description: 'A comprehensive metric chart with all features', @@ -148,7 +148,7 @@ export const comprehensiveGaugeWithDataView: GaugeState = { /** * Comprehensive ESQL-based gauge chart */ -export const comprehensiveEsqlGauge: GaugeState = { +export const comprehensiveEsqlGauge: GaugeConfig = { type: 'gauge', title: 'Comprehensive Test Gauge', description: 'A comprehensive metric chart with all features', diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/heatmap/index.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/heatmap/index.test.ts index 05da0a7e3bc4b..a411f55274652 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/heatmap/index.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/heatmap/index.test.ts @@ -8,8 +8,9 @@ */ import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; -import { heatmapStateSchema } from '../../schema/charts/heatmap'; -import type { HeatmapState } from '../../schema/charts/heatmap'; + +import { heatmapConfigSchema } from '../../schema/charts/heatmap'; +import type { HeatmapConfig } from '../../schema/charts/heatmap'; import { AUTO_COLOR } from '../../schema/color'; import { LensConfigBuilder } from '../../config_builder'; import { validateConverter } from '../validate'; @@ -19,41 +20,41 @@ import * as esqlMocks from './esql.mocks'; describe('Heatmap', () => { describe('DSL', () => { it('should convert a simple heatmap', () => { - validateConverter(dslMocks.simple, heatmapStateSchema); + validateConverter(dslMocks.simple, heatmapConfigSchema); }); it('should convert a heatmap with x and y axes', () => { - validateConverter(dslMocks.withXAndYAxes, heatmapStateSchema); + validateConverter(dslMocks.withXAndYAxes, heatmapConfigSchema); }); it('should convert a heatmap with dynamic colors', () => { - validateConverter(dslMocks.withDynamicColors, heatmapStateSchema); + validateConverter(dslMocks.withDynamicColors, heatmapConfigSchema); }); it('should convert a heatmap with sort predicates', () => { - validateConverter(dslMocks.withSortPredicates, heatmapStateSchema); + validateConverter(dslMocks.withSortPredicates, heatmapConfigSchema); }); it('should convert a default color by value palette', () => { - validateConverter(dslMocks.defaultColorByValueAttributes, heatmapStateSchema); + validateConverter(dslMocks.defaultColorByValueAttributes, heatmapConfigSchema); }); it('should convert a selector color by value palette', () => { - validateConverter(dslMocks.selectorColorByValueAttributes, heatmapStateSchema); + validateConverter(dslMocks.selectorColorByValueAttributes, heatmapConfigSchema); }); }); describe('ESQL', () => { it('should convert a simple heatmap', () => { - validateConverter(esqlMocks.simple, heatmapStateSchema); + validateConverter(esqlMocks.simple, heatmapConfigSchema); }); it('should convert a heatmap with x and y axes', () => { - validateConverter(esqlMocks.withXAndYAxes, heatmapStateSchema); + validateConverter(esqlMocks.withXAndYAxes, heatmapConfigSchema); }); it('should convert a heatmap with sort predicates', () => { - validateConverter(esqlMocks.withSortPredicates, heatmapStateSchema); + validateConverter(esqlMocks.withSortPredicates, heatmapConfigSchema); }); }); @@ -80,12 +81,12 @@ describe('Heatmap', () => { }, sampling: 1, ignore_global_filters: false, - } satisfies HeatmapState; + } satisfies HeatmapConfig; it('should emit AUTO_COLOR when no color is specified', () => { const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(baseHeatmap); - const apiOutput = builder.toAPIFormat(lensState) as HeatmapState; + const apiOutput = builder.toAPIFormat(lensState) as HeatmapConfig; expect(apiOutput.metric.color).toEqual(AUTO_COLOR); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/legacy_metric.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/legacy_metric.test.ts index e8e651ca06953..0381f243dbe06 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/legacy_metric.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/legacy_metric.test.ts @@ -8,11 +8,11 @@ */ import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; -import { legacyMetricStateSchema } from '../../schema/charts/legacy_metric'; -import type { LegacyMetricState } from '../../schema/charts/legacy_metric'; + +import { legacyMetricConfigSchema } from '../../schema/charts/legacy_metric'; +import type { LensApiConfig, LegacyMetricConfig } from '../../schema'; import { AUTO_COLOR } from '../../schema/color'; import { LensConfigBuilder } from '../../config_builder'; -import type { LensApiState } from '../../schema'; import { validateConverter, validateAPIConverter } from '../validate'; import { customColorByValueAttributes, @@ -34,62 +34,62 @@ import { describe('Legacy Metric', () => { describe('validateConverter', () => { it('should convert a simple legacy metric', () => { - validateConverter(simpleLegacyMetricAttributes, legacyMetricStateSchema); + validateConverter(simpleLegacyMetricAttributes, legacyMetricConfigSchema); }); it('should convert a default color by value palette', () => { - validateConverter(defaultColorByValueAttributes, legacyMetricStateSchema); + validateConverter(defaultColorByValueAttributes, legacyMetricConfigSchema); }); it('should convert a selector color by value palette', () => { - validateConverter(selectorColorByValueAttributes, legacyMetricStateSchema); + validateConverter(selectorColorByValueAttributes, legacyMetricConfigSchema); }); it('should convert a custom metric with a color by value palette', () => { - validateConverter(customColorByValueAttributes, legacyMetricStateSchema); + validateConverter(customColorByValueAttributes, legacyMetricConfigSchema); }); }); describe('validateAPIConverter', () => { it('should convert abasic legacy metric chart with ad hoc dataView', () => { - validateAPIConverter(basicLegacyMetricWithAdHocDataView, legacyMetricStateSchema); + validateAPIConverter(basicLegacyMetricWithAdHocDataView, legacyMetricConfigSchema); }); it('should convert a basic legacy metric chart with dataView', () => { - validateAPIConverter(basicLegacyMetricWithDataView, legacyMetricStateSchema); + validateAPIConverter(basicLegacyMetricWithDataView, legacyMetricConfigSchema); }); it('should reject a ESQL-based legacy metric chart', () => { expect(() => - validateAPIConverter(esqlLegacyMetric as unknown as LensApiState, legacyMetricStateSchema) + validateAPIConverter(esqlLegacyMetric as unknown as LensApiConfig, legacyMetricConfigSchema) ).toThrow(); }); it('should convert a comprehensive legacy metric chart with ad hoc data view', () => { - validateAPIConverter(comprehensiveLegacyMetricWithAdHocDataView, legacyMetricStateSchema); + validateAPIConverter(comprehensiveLegacyMetricWithAdHocDataView, legacyMetricConfigSchema); }); it('should convert a comprehensive legacy metric chart with data view', () => { - validateAPIConverter(comprehensiveLegacyMetricWithDataView, legacyMetricStateSchema); + validateAPIConverter(comprehensiveLegacyMetricWithDataView, legacyMetricConfigSchema); }); it('should reject a comprehensive ESQL-based legacy metric chart', () => { expect(() => validateAPIConverter( - comprehensiveEsqlLegacyMetric as unknown as LensApiState, - legacyMetricStateSchema + comprehensiveEsqlLegacyMetric as unknown as LensApiConfig, + legacyMetricConfigSchema ) ).toThrow(); }); it('should convert a legacy metric chart with apply_color_to, but without color', () => { - validateAPIConverter(legacyMetricWithApplyColorToWithoutColor, legacyMetricStateSchema, [ + validateAPIConverter(legacyMetricWithApplyColorToWithoutColor, legacyMetricConfigSchema, [ 'metric.apply_color_to', ]); }); it('should convert a legacy metric chart with color, but without apply_color_to', () => { - validateAPIConverter(legacyMetricWithColorWithoutApplyColorTo, legacyMetricStateSchema, [ + validateAPIConverter(legacyMetricWithColorWithoutApplyColorTo, legacyMetricConfigSchema, [ 'metric.color', ]); }); @@ -112,11 +112,11 @@ describe('Legacy Metric', () => { }, sampling: 1, ignore_global_filters: false, - } satisfies LegacyMetricState; + } satisfies LegacyMetricConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as LegacyMetricState; + const apiOutput = builder.toAPIFormat(lensState) as LegacyMetricConfig; expect(apiOutput.metric.color).toEqual(AUTO_COLOR); expect(apiOutput.metric.apply_color_to).toBe('background'); @@ -137,11 +137,11 @@ describe('Legacy Metric', () => { }, sampling: 1, ignore_global_filters: false, - } satisfies LegacyMetricState; + } satisfies LegacyMetricConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as LegacyMetricState; + const apiOutput = builder.toAPIFormat(lensState) as LegacyMetricConfig; expect(apiOutput.metric.color).not.toBeDefined(); expect(apiOutput.metric.apply_color_to).not.toBeDefined(); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/lens_api_config.mock.ts index fdc1ab2f0fced..443d4c4a48e76 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/legacy_metric/lens_api_config.mock.ts @@ -11,12 +11,12 @@ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE, AS_CODE_DATA_VIEW_SPEC_TYPE, } from '@kbn/as-code-data-views-schema'; -import type { LegacyMetricState, LegacyMetricStateESQL } from '../../schema/charts/legacy_metric'; +import type { LegacyMetricConfig, LegacyMetricConfigESQL } from '../../schema/charts/legacy_metric'; /** * Basic legacy metric chart with ad hoc dataView */ -export const basicLegacyMetricWithAdHocDataView: LegacyMetricState = { +export const basicLegacyMetricWithAdHocDataView: LegacyMetricConfig = { type: 'legacy_metric', title: 'Test Metric', data_source: { @@ -36,7 +36,7 @@ export const basicLegacyMetricWithAdHocDataView: LegacyMetricState = { /** * Basic legacy metric chart with existing dataView */ -export const basicLegacyMetricWithDataView: LegacyMetricState = { +export const basicLegacyMetricWithDataView: LegacyMetricConfig = { type: 'legacy_metric', title: 'Test Metric', description: 'A test metric chart', @@ -56,7 +56,7 @@ export const basicLegacyMetricWithDataView: LegacyMetricState = { /** * ESQL-based legacy metric chart */ -export const esqlLegacyMetric: LegacyMetricStateESQL = { +export const esqlLegacyMetric: LegacyMetricConfigESQL = { type: 'legacy_metric', title: 'Test ESQL Metric', description: 'A test metric chart using ESQL', @@ -74,7 +74,7 @@ export const esqlLegacyMetric: LegacyMetricStateESQL = { /** * Comprehensive legacy metric chart with ad hoc dataView */ -export const comprehensiveLegacyMetricWithAdHocDataView: LegacyMetricState = { +export const comprehensiveLegacyMetricWithAdHocDataView: LegacyMetricConfig = { type: 'legacy_metric', title: 'Comprehensive Test Metric', description: 'A comprehensive metric chart with all features', @@ -108,7 +108,7 @@ export const comprehensiveLegacyMetricWithAdHocDataView: LegacyMetricState = { /** * Comprehensive legacy metric chart with existing dataView */ -export const comprehensiveLegacyMetricWithDataView: LegacyMetricState = { +export const comprehensiveLegacyMetricWithDataView: LegacyMetricConfig = { type: 'legacy_metric', title: 'Comprehensive Test Metric', description: 'A comprehensive metric chart with all features', @@ -141,7 +141,7 @@ export const comprehensiveLegacyMetricWithDataView: LegacyMetricState = { /** * Comprehensive ESQL-based legacy metric chart */ -export const comprehensiveEsqlLegacyMetric: LegacyMetricStateESQL = { +export const comprehensiveEsqlLegacyMetric: LegacyMetricConfigESQL = { type: 'legacy_metric', title: 'Test ESQL Metric', description: 'A test metric chart using ESQL', @@ -172,7 +172,7 @@ export const comprehensiveEsqlLegacyMetric: LegacyMetricStateESQL = { /** * Legacy metric chart with dataView and apply_color_to, but without a defined color */ -export const legacyMetricWithApplyColorToWithoutColor: LegacyMetricState = { +export const legacyMetricWithApplyColorToWithoutColor: LegacyMetricConfig = { type: 'legacy_metric', title: 'Comprehensive Test Metric', description: 'A comprehensive metric chart with all features', @@ -196,7 +196,7 @@ export const legacyMetricWithApplyColorToWithoutColor: LegacyMetricState = { /** * Legacy metric chart with dataView and color, but without a definedapply_color_to */ -export const legacyMetricWithColorWithoutApplyColorTo: LegacyMetricState = { +export const legacyMetricWithColorWithoutApplyColorTo: LegacyMetricConfig = { type: 'legacy_metric', title: 'Comprehensive Test Metric', description: 'A comprehensive metric chart with all features', diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/lens_api_config.mock.ts index deeab6bcd4a26..5e2dce7989ae8 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/lens_api_config.mock.ts @@ -8,8 +8,8 @@ */ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; -import type { MetricState } from '../../schema'; -import type { MetricStateNoESQL } from '../../schema/charts/metric'; +import type { MetricConfig } from '../../schema'; +import type { MetricConfigNoESQL } from '../../schema/charts/metric'; import { DEFAULT_PRIMARY_VALUE_ALIGNMENT } from '../../transforms/charts/metric/defaults'; export const breakdownMetricAPIAttributes = { @@ -39,7 +39,7 @@ export const breakdownMetricAPIAttributes = { fields: ['extension.keyword'], limit: 5, }, -} as MetricStateNoESQL; +} as MetricConfigNoESQL; export const complexMetricAPIAttributes = { type: 'metric', @@ -88,7 +88,7 @@ export const complexMetricAPIAttributes = { value: { alignment: DEFAULT_PRIMARY_VALUE_ALIGNMENT }, }, }, -} as MetricState; +} as MetricConfig; export const simpleMetricAPIAttributes = { type: 'metric', @@ -103,7 +103,7 @@ export const simpleMetricAPIAttributes = { empty_as_null: true, }, ], -} as MetricState; +} as MetricConfig; export const complexESQLMetricAPIAttributes = { type: 'metric', @@ -140,7 +140,7 @@ export const complexESQLMetricAPIAttributes = { breakdown_by: { column: 'extension.keyword', }, -} as MetricState; +} as MetricConfig; export const metricAPIWithTermsRankedBySecondary = { type: 'metric', @@ -176,4 +176,4 @@ export const metricAPIWithTermsRankedBySecondary = { direction: 'desc', }, }, -} as MetricState; +} as MetricConfig; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/metric.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/metric.test.ts index 3376355c157a9..fc07911b4bb0e 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/metric.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/metric/metric.test.ts @@ -8,8 +8,8 @@ */ import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; -import { metricStateSchema } from '../../schema/charts/metric'; -import type { MetricState } from '../../schema/charts/metric'; +import { metricConfigSchema } from '../../schema/charts/metric'; +import type { MetricConfig } from '../../schema/charts/metric'; import { AUTO_COLOR, NO_COLOR } from '../../schema/color'; import { LensConfigBuilder } from '../../config_builder'; import { dynamicColorsMetricAttributes } from './dynamic_colors.mock'; @@ -33,53 +33,53 @@ import { describe('Metric', () => { describe('validateConverter', () => { it('should convert a simple metric', () => { - validateConverter(simpleMetricAttributes, metricStateSchema); + validateConverter(simpleMetricAttributes, metricConfigSchema); }); it('should convert a complex metric', () => { - validateConverter(complexMetricAttributes, metricStateSchema); + validateConverter(complexMetricAttributes, metricConfigSchema); }); it('should convert a breakdown-by metric', () => { - validateConverter(breakdownMetricAttributes, metricStateSchema); + validateConverter(breakdownMetricAttributes, metricConfigSchema); }); it('should convert a default color by value palette', () => { - validateConverter(defaultColorByValueAttributes, metricStateSchema); + validateConverter(defaultColorByValueAttributes, metricConfigSchema); }); it('should convert a selector color by value palette', () => { - validateConverter(selectorColorByValueAttributes, metricStateSchema); + validateConverter(selectorColorByValueAttributes, metricConfigSchema); }); }); describe('validateAPIConverter', () => { it('should convert a simple metric', () => { - validateAPIConverter(simpleMetricAPIAttributes, metricStateSchema); + validateAPIConverter(simpleMetricAPIAttributes, metricConfigSchema); }); it('should convert a complex metric', () => { - validateAPIConverter(complexMetricAPIAttributes, metricStateSchema); + validateAPIConverter(complexMetricAPIAttributes, metricConfigSchema); }); it('should convert a breakdown-by metric', () => { - validateAPIConverter(breakdownMetricAPIAttributes, metricStateSchema); + validateAPIConverter(breakdownMetricAPIAttributes, metricConfigSchema); }); it('should convert a complex ESQL metric chart', () => { - validateAPIConverter(complexESQLMetricAPIAttributes, metricStateSchema); + validateAPIConverter(complexESQLMetricAPIAttributes, metricConfigSchema); }); it('should convert a metric with a terms agg ranked by secondary metric', () => { - validateAPIConverter(metricAPIWithTermsRankedBySecondary, metricStateSchema); + validateAPIConverter(metricAPIWithTermsRankedBySecondary, metricConfigSchema); }); }); it('should convert a breakdown-by metric with formula reference columns and rank_by in the terms bucket operation', () => { - validateConverter(breakdownMetricWithFormulaRefColumnsAttributes, metricStateSchema); + validateConverter(breakdownMetricWithFormulaRefColumnsAttributes, metricConfigSchema); }); it('should convert a dynamic colors metric', () => { - validateConverter(dynamicColorsMetricAttributes, metricStateSchema); + validateConverter(dynamicColorsMetricAttributes, metricConfigSchema); }); describe('color default application', () => { @@ -100,12 +100,12 @@ describe('Metric', () => { ], sampling: 1, ignore_global_filters: false, - } satisfies MetricState; + } satisfies MetricConfig; it('should emit AUTO_COLOR for primary metric when no color is specified', () => { const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(baseMetric); - const apiOutput = builder.toAPIFormat(lensState) as MetricState; + const apiOutput = builder.toAPIFormat(lensState) as MetricConfig; expect(apiOutput.metrics[0].color).toEqual(AUTO_COLOR); }); @@ -121,11 +121,11 @@ describe('Metric', () => { field: 'bytes', }, ], - } satisfies MetricState; + } satisfies MetricConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as MetricState; + const apiOutput = builder.toAPIFormat(lensState) as MetricConfig; expect(apiOutput.metrics[0].color).toEqual(AUTO_COLOR); expect(apiOutput.metrics[1].color).toEqual(NO_COLOR); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/lens_api_config.mock.ts index 5ebc6bdaa66ed..36100664381dc 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/lens_api_config.mock.ts @@ -7,12 +7,12 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { MosaicState } from '../../schema/charts/mosaic'; -import type { PieState } from '../../schema/charts/pie'; -import type { TreemapState } from '../../schema/charts/treemap'; -import type { WaffleState } from '../../schema/charts/waffle'; +import type { MosaicConfig } from '../../schema/charts/mosaic'; +import type { PieConfig } from '../../schema/charts/pie'; +import type { TreemapConfig } from '../../schema/charts/treemap'; +import type { WaffleConfig } from '../../schema/charts/waffle'; import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; -type PartitionConfig = PieState | MosaicState | TreemapState | WaffleState; +type PartitionConfig = PieConfig | MosaicConfig | TreemapConfig | WaffleConfig; export const esqlCharts: Array = [ { diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/partition.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/partition.test.ts index e473b7f27f8b8..a5fc7f3ed600b 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/partition.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/partition.test.ts @@ -7,16 +7,16 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import type { LensApiConfig } from '../../schema'; +import type { PieConfig } from '../../schema/charts/pie'; +import { mosaicConfigSchema } from '../../schema/charts/mosaic'; +import { partitionConfigSchema } from '../../schema/charts/partition'; +import { pieConfigSchema } from '../../schema/charts/pie'; +import type { TreemapConfig } from '../../schema/charts/treemap'; +import { treemapConfigSchema } from '../../schema/charts/treemap'; +import type { WaffleConfig } from '../../schema/charts/waffle'; +import { waffleConfigSchema } from '../../schema/charts/waffle'; import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; -import type { LensApiState } from '../../schema'; -import type { PieState } from '../../schema/charts/pie'; -import type { TreemapState } from '../../schema/charts/treemap'; -import type { WaffleState } from '../../schema/charts/waffle'; -import { mosaicStateSchema } from '../../schema/charts/mosaic'; -import { partitionStateSchema } from '../../schema/charts/partition'; -import { pieStateSchema } from '../../schema/charts/pie'; -import { treemapStateSchema } from '../../schema/charts/treemap'; -import { waffleStateSchema } from '../../schema/charts/waffle'; import { AUTO_COLOR, DEFAULT_CATEGORICAL_COLOR_MAPPING } from '../../schema/color'; import { validateAPIConverter, validateConverter } from '../validate'; import { esqlCharts } from './lens_api_config.mock'; @@ -40,55 +40,55 @@ import type { LensPartitionVisualizationState } from '@kbn/lens-common'; describe('Partition', () => { describe('validateConverter', () => { const datasets = [ - { name: 'pie basic', config: pieLegacyBasicState, schema: pieStateSchema }, - { name: 'treemap basic', config: treemapLegacyBasicState, schema: treemapStateSchema }, - { name: 'mosaic basic', config: mosaicLegacyBasicState, schema: mosaicStateSchema }, - { name: 'waffle basic', config: waffleLegacyBasicState, schema: waffleStateSchema }, + { name: 'pie basic', config: pieLegacyBasicState, schema: pieConfigSchema }, + { name: 'treemap basic', config: treemapLegacyBasicState, schema: treemapConfigSchema }, + { name: 'mosaic basic', config: mosaicLegacyBasicState, schema: mosaicConfigSchema }, + { name: 'waffle basic', config: waffleLegacyBasicState, schema: waffleConfigSchema }, { name: 'pie advanced with collapsed groups', config: pieLegacyAdvancedStateWithMultipleMetricsAndCollapsedGroups, - schema: pieStateSchema, + schema: pieConfigSchema, }, { name: 'treemap advanced with collapsed groups', config: treemapLegacyAdvancedStateWithMultipleMetricsAndCollapsedGroups, - schema: treemapStateSchema, + schema: treemapConfigSchema, }, { name: 'mosaic advanced with collapsed groups', config: mosaicLegacyAdvancedStateWithMultipleMetricsAndCollapsedGroups, - schema: mosaicStateSchema, + schema: mosaicConfigSchema, }, { name: 'waffle advanced with collapsed groups', config: waffleLegacyAdvancedStateWithCollapsedGroups, - schema: waffleStateSchema, + schema: waffleConfigSchema, }, { name: 'pie esql basic', config: pieLegacyESQLState, - schema: pieStateSchema, + schema: pieConfigSchema, }, { name: 'treemap esql basic', config: treemapLegacyESQLState, - schema: treemapStateSchema, + schema: treemapConfigSchema, }, { name: 'mosaic esql basic', config: mosaicLegacyESQLState, - schema: mosaicStateSchema, + schema: mosaicConfigSchema, }, { name: 'waffle esql basic', config: waffleLegacyESQLState, - schema: waffleStateSchema, + schema: waffleConfigSchema, }, ]; for (const { name, config, schema } of datasets) { it(`should convert a legacy ${name} chart`, () => { validateConverter(config, schema); - validateConverter(config, partitionStateSchema); + validateConverter(config, partitionConfigSchema); }); } }); @@ -96,7 +96,7 @@ describe('Partition', () => { describe('validateAPIConverter', () => { for (const config of esqlCharts) { it(`should convert an API ${config.title} chart`, () => { - validateAPIConverter(config as LensApiState, partitionStateSchema, [ + validateAPIConverter(config as LensApiConfig, partitionConfigSchema, [ 'sampling', 'ignore_global_filters', ]); @@ -110,7 +110,7 @@ describe('Partition', () => { (pieLegacyESQLState.state .visualization as LensPartitionVisualizationState)!.layers[0].collapseFns!.partition_value_accessor_group_by_0 = '' as unknown as 'min'; - const apiConfig = builder.toAPIFormat(pieLegacyESQLState) as PieState; + const apiConfig = builder.toAPIFormat(pieLegacyESQLState) as PieConfig; // The group should have color mapping (since empty string collapseFns means no collapse) expect(apiConfig.group_by?.[0].color).toHaveProperty('mode', 'categorical'); @@ -135,11 +135,11 @@ describe('Partition', () => { metrics: [{ operation: 'count', empty_as_null: false }], sampling: 1, ignore_global_filters: false, - } satisfies PieState; + } satisfies PieConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as PieState; + const apiOutput = builder.toAPIFormat(lensState) as PieConfig; expect(apiOutput.metrics[0].color).toEqual(AUTO_COLOR); }); @@ -159,11 +159,11 @@ describe('Partition', () => { ], sampling: 1, ignore_global_filters: false, - } satisfies PieState; + } satisfies PieConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as PieState; + const apiOutput = builder.toAPIFormat(lensState) as PieConfig; expect(apiOutput.group_by?.[0].color).toEqual(DEFAULT_CATEGORICAL_COLOR_MAPPING); }); @@ -176,11 +176,11 @@ describe('Partition', () => { metrics: [{ operation: 'count', empty_as_null: false }], sampling: 1, ignore_global_filters: false, - } satisfies TreemapState; + } satisfies TreemapConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as TreemapState; + const apiOutput = builder.toAPIFormat(lensState) as TreemapConfig; expect(apiOutput.metrics[0].color).toEqual(AUTO_COLOR); }); @@ -193,11 +193,11 @@ describe('Partition', () => { metrics: [{ operation: 'count', empty_as_null: false }], sampling: 1, ignore_global_filters: false, - } satisfies WaffleState; + } satisfies WaffleConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as WaffleState; + const apiOutput = builder.toAPIFormat(lensState) as WaffleConfig; expect(apiOutput.metrics[0].color).toEqual(AUTO_COLOR); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/lens_api_config.mock.ts index 2b99631c41cd2..4d2bce414a77b 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/lens_api_config.mock.ts @@ -11,7 +11,7 @@ import { AS_CODE_DATA_VIEW_REFERENCE_TYPE, AS_CODE_DATA_VIEW_SPEC_TYPE, } from '@kbn/as-code-data-views-schema'; -import type { RegionMapState } from '../../schema'; +import type { RegionMapConfig } from '../../schema'; /** * Basic region map chart with ad hoc dataView @@ -43,7 +43,7 @@ export const basicRegionMapWithAdHocDataView = { }, sampling: 1, ignore_global_filters: false, -} satisfies RegionMapState; +} satisfies RegionMapConfig; /** * Basic region map chart with existing dataView @@ -79,7 +79,7 @@ export const basicRegionMapWithDataView = { }, sampling: 1, ignore_global_filters: false, -} satisfies RegionMapState; +} satisfies RegionMapConfig; /** * ESQL-based region map chart @@ -103,7 +103,7 @@ export const basicEsqlRegionMap = { }, sampling: 1, ignore_global_filters: false, -} satisfies RegionMapState; +} satisfies RegionMapConfig; /** * Comprehensive region map chart with ad hoc dataView @@ -138,7 +138,7 @@ export const comprehensiveRegionMapWithAdHocDataView = { }, sampling: 1, ignore_global_filters: false, -} satisfies RegionMapState; +} satisfies RegionMapConfig; /** * Comprehensive region map chart with existing dataView @@ -172,7 +172,7 @@ export const comprehensiveRegionMapWithDataView = { }, sampling: 1, ignore_global_filters: false, -} satisfies RegionMapState; +} satisfies RegionMapConfig; /** * Comprehensive ESQL-based region map chart @@ -196,4 +196,4 @@ export const comprehensiveEsqlRegionMap = { }, sampling: 1, ignore_global_filters: false, -} satisfies RegionMapState; +} satisfies RegionMapConfig; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/region_map.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/region_map.test.ts index 9851497f75cfd..5fc61b337cfec 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/region_map.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/region_map/region_map.test.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { regionMapStateSchema } from '../../schema'; +import { regionMapConfigSchema } from '../../schema'; import { validateAPIConverter, validateConverter } from '../validate'; import { basicRegionMapWithAdHocDataView, @@ -28,44 +28,44 @@ import { describe('Region Map', () => { describe('validateConverter', () => { it('should convert a simple region map', () => { - validateConverter(regionMapAttributes, regionMapStateSchema); + validateConverter(regionMapAttributes, regionMapConfigSchema); }); it('should convert a region map with full config', () => { - validateConverter(regionMapAttributesWithEms, regionMapStateSchema); + validateConverter(regionMapAttributesWithEms, regionMapConfigSchema); }); it('should convert a region map with filters for region', () => { - validateConverter(regionMapAttributesWithFilterForRegion, regionMapStateSchema); + validateConverter(regionMapAttributesWithFilterForRegion, regionMapConfigSchema); }); it('should convert an esql region map', () => { - validateConverter(regionMapESQLAttributes, regionMapStateSchema); + validateConverter(regionMapESQLAttributes, regionMapConfigSchema); }); it('should convert an esql region map with full config', () => { - validateConverter(regionmapESQLAttributesWithEms, regionMapStateSchema); + validateConverter(regionmapESQLAttributesWithEms, regionMapConfigSchema); }); }); describe('validateAPIConverter', () => { it('should convert a basic regionMap chart with ad hoc dataView', () => { - validateAPIConverter(basicRegionMapWithAdHocDataView, regionMapStateSchema); + validateAPIConverter(basicRegionMapWithAdHocDataView, regionMapConfigSchema); }); it('should convert a basic regionMap chart with dataView', () => { - validateAPIConverter(basicRegionMapWithDataView, regionMapStateSchema); + validateAPIConverter(basicRegionMapWithDataView, regionMapConfigSchema); }); it('should convert a ESQL-based regionMap chart', () => { - validateAPIConverter(basicEsqlRegionMap, regionMapStateSchema); + validateAPIConverter(basicEsqlRegionMap, regionMapConfigSchema); }); it('should convert a comprehensive regionMap chart with ad hoc data view', () => { - validateAPIConverter(comprehensiveRegionMapWithAdHocDataView, regionMapStateSchema); + validateAPIConverter(comprehensiveRegionMapWithAdHocDataView, regionMapConfigSchema); }); it('should convert a comprehensive regionMap chart with data view', () => { - validateAPIConverter(comprehensiveRegionMapWithDataView, regionMapStateSchema); + validateAPIConverter(comprehensiveRegionMapWithDataView, regionMapConfigSchema); }); it('should convert a comprehensive ESQL-based regionMap chart', () => { - validateAPIConverter(comprehensiveEsqlRegionMap, regionMapStateSchema); + validateAPIConverter(comprehensiveEsqlRegionMap, regionMapConfigSchema); }); }); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/lens_api_config.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/lens_api_config.mock.ts index f1f311d784063..85ab38ff6bd05 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/lens_api_config.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/lens_api_config.mock.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { TagcloudState } from '../../schema'; +import type { TagcloudConfig } from '../../schema'; import { AS_CODE_DATA_VIEW_REFERENCE_TYPE, AS_CODE_DATA_VIEW_SPEC_TYPE, @@ -37,7 +37,7 @@ export const basicTagcloudWithAdHocDataView = { }, sampling: 1, ignore_global_filters: false, -} satisfies TagcloudState; +} satisfies TagcloudConfig; /** * Basic tagcloud chart with existing dataView @@ -62,7 +62,7 @@ export const basicTagcloudWithDataView = { }, sampling: 1, ignore_global_filters: false, -} satisfies TagcloudState; +} satisfies TagcloudConfig; /** * ESQL-based tagcloud chart @@ -82,7 +82,7 @@ export const basicEsqlTagcloud = { }, sampling: 1, ignore_global_filters: false, -} satisfies TagcloudState; +} satisfies TagcloudConfig; /** * Comprehensive tagcloud chart with ad hoc dataView @@ -148,7 +148,7 @@ export const comprehensiveTagcloudWithAdHocDataView = { }, sampling: 1, ignore_global_filters: false, -} satisfies TagcloudState; +} satisfies TagcloudConfig; /** * Comprehensive tagcloud chart with existing dataView @@ -213,7 +213,7 @@ export const comprehensiveTagcloudWithDataView = { }, sampling: 1, ignore_global_filters: false, -} satisfies TagcloudState; +} satisfies TagcloudConfig; /** * Comprehensive ESQL-based tagcloud chart @@ -246,4 +246,4 @@ export const comprehensiveEsqlTagcloud = { }, sampling: 1, ignore_global_filters: false, -} satisfies TagcloudState; +} satisfies TagcloudConfig; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/tagcloud.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/tagcloud.test.ts index 0570aed5e35e5..285746732a806 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/tagcloud.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/tagcloud/tagcloud.test.ts @@ -8,8 +8,8 @@ */ import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; -import { tagcloudStateSchema } from '../../schema'; -import type { TagcloudState } from '../../schema/charts/tagcloud'; +import { tagcloudConfigSchema } from '../../schema'; +import type { TagcloudConfig } from '../../schema'; import { DEFAULT_CATEGORICAL_COLOR_MAPPING } from '../../schema/color'; import { LensConfigBuilder } from '../../config_builder'; import { validateAPIConverter, validateConverter } from '../validate'; @@ -30,38 +30,38 @@ import { describe('Tagcloud', () => { describe('validateConverter', () => { it('should convert a simple tag cloud', () => { - validateConverter(tagcloudAttributes, tagcloudStateSchema); + validateConverter(tagcloudAttributes, tagcloudConfigSchema); }); it('should convert a tag cloud with full config', () => { - validateConverter(tagcloudAttributesWithFullConfig, tagcloudStateSchema); + validateConverter(tagcloudAttributesWithFullConfig, tagcloudConfigSchema); }); it('should convert an esql tagcloud', () => { - validateConverter(tagcloudESQLAttributes, tagcloudStateSchema); + validateConverter(tagcloudESQLAttributes, tagcloudConfigSchema); }); }); describe('validateAPIConverter', () => { it('should convert a basic tagcloud chart with ad hoc dataView', () => { - validateAPIConverter(basicTagcloudWithAdHocDataView, tagcloudStateSchema); + validateAPIConverter(basicTagcloudWithAdHocDataView, tagcloudConfigSchema); }); it('should convert a basic tagcloud chart with dataView', () => { - validateAPIConverter(basicTagcloudWithDataView, tagcloudStateSchema); + validateAPIConverter(basicTagcloudWithDataView, tagcloudConfigSchema); }); it('should convert a ESQL-based tagcloud chart', () => { - validateAPIConverter(basicEsqlTagcloud, tagcloudStateSchema); + validateAPIConverter(basicEsqlTagcloud, tagcloudConfigSchema); }); it('should convert a comprehensive tagcloud chart with ad hoc data view', () => { - validateAPIConverter(comprehensiveTagcloudWithAdHocDataView, tagcloudStateSchema); + validateAPIConverter(comprehensiveTagcloudWithAdHocDataView, tagcloudConfigSchema); }); it('should convert a comprehensive tagcloud chart with data view', () => { - validateAPIConverter(comprehensiveTagcloudWithDataView, tagcloudStateSchema); + validateAPIConverter(comprehensiveTagcloudWithDataView, tagcloudConfigSchema); }); it('should convert a comprehensive ESQL-based tagcloud chart', () => { - validateAPIConverter(comprehensiveEsqlTagcloud, tagcloudStateSchema); + validateAPIConverter(comprehensiveEsqlTagcloud, tagcloudConfigSchema); }); }); @@ -86,11 +86,11 @@ describe('Tagcloud', () => { }, sampling: 1, ignore_global_filters: false, - } satisfies TagcloudState; + } satisfies TagcloudConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as TagcloudState; + const apiOutput = builder.toAPIFormat(lensState) as TagcloudConfig; expect(apiOutput.tag_by.color).toEqual(DEFAULT_CATEGORICAL_COLOR_MAPPING); }); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/validate.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/validate.ts index 093a590468e1a..465b30c549308 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/validate.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/validate.ts @@ -13,8 +13,8 @@ import type { Type } from '@kbn/config-schema'; import { LensConfigBuilder } from '../config_builder'; import type { LensAttributes } from '../types'; -import type { LensApiState } from '../schema'; -import { lensApiStateSchema } from '../schema'; +import type { LensApiConfig } from '../schema'; +import { lensApiConfigSchema } from '../schema'; /** * Test harness to validate LensConfigBuilder conversions @@ -22,11 +22,11 @@ import { lensApiStateSchema } from '../schema'; * - Starts with LensAttributes * - Converts to API format * - Validates against the provided schema - * - Validates against the general lensApiStateSchema + * - Validates against the general lensApiConfigSchema * - Converts back to LensAttributes * - Converts new LensAttributes to API format * - Validates against the provided schema - * - Validates against the general lensApiStateSchema + * - Validates against the general lensApiConfigSchema */ export function validateConverter(attributes: LensAttributes, schema: Type) { const builder = new LensConfigBuilder(undefined, true); @@ -37,7 +37,7 @@ export function validateConverter(attributes: LensAttributes, schema: Type) }).not.toThrow(); expect(() => { - lensApiStateSchema.validate(newApiConfig); + lensApiConfigSchema.validate(newApiConfig); }).not.toThrow(); const newLensAttributes = builder.fromAPIFormat(newApiConfig); @@ -49,7 +49,7 @@ export function validateConverter(attributes: LensAttributes, schema: Type) }).not.toThrow(); expect(() => { - lensApiStateSchema.validate(newApiConfig2); + lensApiConfigSchema.validate(newApiConfig2); }).not.toThrow(); expect(newApiConfig).toEqual(newApiConfig2); @@ -60,17 +60,17 @@ export function validateConverter(attributes: LensAttributes, schema: Type) * * - Starts with LensAPI config format * - Validates against the provided schema - * - Validates against the general lensApiStateSchema + * - Validates against the general lensApiConfigSchema * - Converts to LensAttributes * - Converts LensAttributes back to API format * - Validates against the provided schema - * - Validates against the general lensApiStateSchema + * - Validates against the general lensApiConfigSchema * - Excludes specified fields from the API config * - Checks that the new API config includes the filtered API config * - Note: the excluded fields are expected to be omitted during the conversion to LensStateConfig, so they are not included in the new API config */ export function validateAPIConverter( - apiConfig: LensApiState, + apiConfig: LensApiConfig, schema: Type, excludedFields?: string[] ) { @@ -81,7 +81,7 @@ export function validateAPIConverter( }).not.toThrow(); expect(() => { - lensApiStateSchema.validate(apiConfig); + lensApiConfigSchema.validate(apiConfig); }).not.toThrow(); const lensStateConfig = builder.fromAPIFormat(apiConfig); @@ -93,7 +93,7 @@ export function validateAPIConverter( }).not.toThrow(); expect(() => { - lensApiStateSchema.validate(newApiConfig); + lensApiConfigSchema.validate(newApiConfig); }).not.toThrow(); const filteredApiConfig = structuredClone(apiConfig); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/basicXY.mock.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/basicXY.mock.ts index 1228841464c12..652cc03363c87 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/basicXY.mock.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/basicXY.mock.ts @@ -17,7 +17,7 @@ import type { AvgIndexPatternColumn, } from '@kbn/lens-common'; import type { LensAttributes } from '../../types'; -import type { LensApiState } from '../../schema'; +import type { LensApiConfig } from '../../schema'; import { LENS_ITEM_LATEST_VERSION } from '@kbn/lens-common/content_management/constants'; import { AS_CODE_DATA_VIEW_REFERENCE_TYPE } from '@kbn/as-code-data-views-schema'; @@ -1073,7 +1073,7 @@ export const xyWithFormulaRefColumnsAndRankByTermsBucketOperationAttributes: Len version: LENS_ITEM_LATEST_VERSION, }; -export const apiXYWithNoYTitleAndInsideLegend: LensApiState = { +export const apiXYWithNoYTitleAndInsideLegend: LensApiConfig = { title: '', type: 'xy', legend: { @@ -1151,7 +1151,7 @@ export const apiXYWithNoYTitleAndInsideLegend: LensApiState = { }, }; -export const apiXYWithTopListWithTruncationLegend: LensApiState = { +export const apiXYWithTopListWithTruncationLegend: LensApiConfig = { title: '', type: 'xy', legend: { @@ -1231,7 +1231,7 @@ export const apiXYWithTopListWithTruncationLegend: LensApiState = { }, }; -export const apiXYWithNoTitleAndCustomOutsideLegend: LensApiState = { +export const apiXYWithNoTitleAndCustomOutsideLegend: LensApiConfig = { title: '', type: 'xy', legend: { diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/xy.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/xy.test.ts index 7c1c133c8eb58..314537d5df522 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/xy.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/xy/xy.test.ts @@ -8,8 +8,8 @@ */ import type { XYVisualizationState } from '@kbn/lens-common'; -import { xyStateSchema } from '../../schema/charts/xy'; -import type { XYState } from '../../schema/charts/xy'; +import { xyConfigSchema } from '../../schema/charts/xy'; +import type { XYConfig } from '../../schema/charts/xy'; import { AUTO_COLOR, DEFAULT_CATEGORICAL_COLOR_MAPPING } from '../../schema/color'; import { LensConfigBuilder } from '../../config_builder'; import type { LensAttributes } from '../../types'; @@ -65,64 +65,64 @@ describe('XY', () => { describe('Data only', () => { for (const type of ['bar', 'line', 'area'] as const) { it(`should convert a minimal ${type} chart with one data layer`, () => { - validateConverter(setSeriesType(minimalAttributesXY, type), xyStateSchema); + validateConverter(setSeriesType(minimalAttributesXY, type), xyConfigSchema); }); } it(`should convert a full xy chart with one data layer`, () => { - validateConverter(fullBasicXY, xyStateSchema); + validateConverter(fullBasicXY, xyConfigSchema); }); it(`should convert a xy chart with multiple metrics`, () => { - validateConverter(multipleMetricsXY, xyStateSchema); + validateConverter(multipleMetricsXY, xyConfigSchema); }); it(`should convert a xy chart with multiple metrics and a breakdown`, () => { - validateConverter(breakdownXY, xyStateSchema); + validateConverter(breakdownXY, xyConfigSchema); }); it('should convert a bar chart with 2 layers', () => { - validateConverter(barWithTwoLayersAttributes, xyStateSchema); + validateConverter(barWithTwoLayersAttributes, xyConfigSchema); }); it('should convert a mixed chart with 3 layers', () => { - validateConverter(mixedChartAttributes, xyStateSchema); + validateConverter(mixedChartAttributes, xyConfigSchema); }); it('should convert a chart with formula ref columns and rank_by in the terms bucket operation', () => { validateConverter( xyWithFormulaRefColumnsAndRankByTermsBucketOperationAttributes, - xyStateSchema + xyConfigSchema ); }); it('should convert an esql xy with collapse by breakdown', () => { - validateConverter(esqlXYWithCollapseByBreakdown, xyStateSchema); + validateConverter(esqlXYWithCollapseByBreakdown, xyConfigSchema); }); }); describe('Reference lines', () => { for (const type of ['bar', 'line', 'area'] as const) { it(`should work for a reference line with a ${type} chart`, () => { - validateConverter(setSeriesType(referenceLineXY, type), xyStateSchema); + validateConverter(setSeriesType(referenceLineXY, type), xyConfigSchema); }); } it('should work for both horizontal and vertical reference lines', () => { - validateConverter(dualReferenceLineXY, xyStateSchema); + validateConverter(dualReferenceLineXY, xyConfigSchema); }); }); describe('Annotations', () => { for (const type of ['bar', 'line', 'area'] as const) { it(`should work for an annotation with a ${type} chart`, () => { - validateConverter(setSeriesType(annotationXY, type), xyStateSchema); + validateConverter(setSeriesType(annotationXY, type), xyConfigSchema); }); } for (const type of ['bar', 'line', 'area'] as const) { it(`should work for a by-reference annotation with a ${type} chart`, () => { - validateConverter(setSeriesType(byRefAnnotationXY, type), xyStateSchema); + validateConverter(setSeriesType(byRefAnnotationXY, type), xyConfigSchema); }); } }); @@ -130,13 +130,16 @@ describe('XY', () => { describe('ES|QL panels', () => { for (const type of ['bar', 'line', 'area'] as const) { it(`should work for an annotation with a ${type} chart`, () => { - validateConverter(setSeriesType(esqlChart, type), xyStateSchema); + validateConverter(setSeriesType(esqlChart, type), xyConfigSchema); }); } for (const type of ['bar', 'line', 'area'] as const) { it(`should work for an ES|QL ${type} chart with breakdown and color mapping`, () => { - validateConverter(setSeriesType(esqlChartWithBreakdownColorMapping, type), xyStateSchema); + validateConverter( + setSeriesType(esqlChartWithBreakdownColorMapping, type), + xyConfigSchema + ); }); } @@ -196,7 +199,7 @@ describe('XY', () => { }, }; - validateConverter(esqlChartWithDateColumn, xyStateSchema); + validateConverter(esqlChartWithDateColumn, xyConfigSchema); }); it('should detect linear scale for ES|QL chart with numeric column', () => { @@ -254,11 +257,11 @@ describe('XY', () => { }, }; - validateConverter(esqlChartWithNumericColumn, xyStateSchema); + validateConverter(esqlChartWithNumericColumn, xyConfigSchema); }); it('should default to ordinal scale for form-based chart', () => { - validateConverter(minimalAttributesXY, xyStateSchema); + validateConverter(minimalAttributesXY, xyConfigSchema); }); }); }); @@ -295,7 +298,7 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); }); @@ -320,7 +323,7 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); }); @@ -346,7 +349,7 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); } ); @@ -386,7 +389,7 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); } ); @@ -539,21 +542,21 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); } ); it('should correctly transform no title and inside legend - bug 248611', () => { - validateAPIConverter(apiXYWithNoYTitleAndInsideLegend, xyStateSchema); + validateAPIConverter(apiXYWithNoYTitleAndInsideLegend, xyConfigSchema); }); it('should correctly transform top list layout', () => { - validateAPIConverter(apiXYWithTopListWithTruncationLegend, xyStateSchema); + validateAPIConverter(apiXYWithTopListWithTruncationLegend, xyConfigSchema); }); it('should correctly transform with custom position legend - bug 248611', () => { - validateAPIConverter(apiXYWithNoTitleAndCustomOutsideLegend, xyStateSchema); + validateAPIConverter(apiXYWithNoTitleAndCustomOutsideLegend, xyConfigSchema); }); it('should convert API with by-reference annotation layer', () => { @@ -575,7 +578,7 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); }); @@ -605,7 +608,7 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); }); @@ -633,7 +636,7 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); }); @@ -655,7 +658,7 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); }); @@ -683,7 +686,7 @@ describe('XY', () => { }, ], }, - xyStateSchema + xyConfigSchema ); }); }); @@ -703,11 +706,11 @@ describe('XY', () => { y: [{ operation: 'count', empty_as_null: false }], }, ], - } satisfies XYState; + } satisfies XYConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as XYState; + const apiOutput = builder.toAPIFormat(lensState) as XYConfig; const dataLayer = apiOutput.layers[0]; expect('y' in dataLayer && dataLayer.y[0].color).toEqual(AUTO_COLOR); @@ -730,11 +733,11 @@ describe('XY', () => { breakdown_by: { column: 'product' }, }, ], - } satisfies XYState; + } satisfies XYConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as XYState; + const apiOutput = builder.toAPIFormat(lensState) as XYConfig; const dataLayer = apiOutput.layers[0]; expect('breakdown_by' in dataLayer && dataLayer.breakdown_by?.color).toEqual( @@ -759,11 +762,11 @@ describe('XY', () => { breakdown_by: { column: 'product' }, }, ], - } satisfies XYState; + } satisfies XYConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as XYState; + const apiOutput = builder.toAPIFormat(lensState) as XYConfig; const dataLayer = apiOutput.layers[0]; expect('breakdown_by' in dataLayer && dataLayer.breakdown_by?.color).toEqual( @@ -802,11 +805,11 @@ describe('XY', () => { ], }, ], - } satisfies XYState; + } satisfies XYConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as XYState; + const apiOutput = builder.toAPIFormat(lensState) as XYConfig; const refLineLayer = apiOutput.layers.find((l) => 'thresholds' in l); expect(refLineLayer).toBeDefined(); @@ -849,11 +852,11 @@ describe('XY', () => { ], }, ], - } satisfies XYState; + } satisfies XYConfig; const builder = new LensConfigBuilder(); const lensState = builder.fromAPIFormat(config); - const apiOutput = builder.toAPIFormat(lensState) as XYState; + const apiOutput = builder.toAPIFormat(lensState) as XYConfig; const annotationLayer = apiOutput.layers.find((l) => 'events' in l); expect(annotationLayer).toBeDefined(); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable.ts index b101f3e140198..33ea6db7f1209 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ import type { DatatableVisualizationState, TypedLensSerializedState } from '@kbn/lens-common'; -import type { DatatableState, DatatableStateNoESQL } from '../../schema'; +import type { DatatableConfig, DatatableConfigNoESQL } from '../../schema'; import type { LensAttributes } from '../../types'; import { DEFAULT_LAYER_ID } from '../../constants'; import { buildDatasourceStates, buildReferences, getAdhocDataviews } from '../utils'; @@ -34,10 +34,10 @@ type DatatableAttributesWithoutFiltersAndQuery = Omit - buildFormBasedLayer(cfg as DatatableStateNoESQL); + buildFormBasedLayer(cfg as DatatableConfigNoESQL); const { layers, usedDataviews } = buildDatasourceStates(config, _buildDataLayer, getValueColumns); @@ -64,7 +64,7 @@ export function fromAPItoLensState( }; } -export function fromLensStateToAPI(config: LensAttributes): DatatableState { +export function fromLensStateToAPI(config: LensAttributes): DatatableConfig { const { state } = config; const visualization = state.visualization as DatatableVisualizationState; const layers = getDatasourceLayers(state); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/columns.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/columns.ts index 4e73f958f018d..9985d462ad91f 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/columns.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/columns.ts @@ -13,7 +13,11 @@ import type { ColumnState, } from '@kbn/lens-common'; import type { PaletteOutput } from '@kbn/coloring'; -import type { DatatableState, DatatableStateESQL, DatatableStateNoESQL } from '../../../../schema'; +import type { + DatatableConfig, + DatatableConfigESQL, + DatatableConfigNoESQL, +} from '../../../../schema'; import { isFormBasedLayer, operationFromColumn } from '../../../utils'; import { getValueApiColumn } from '../../../columns/esql_column'; import { @@ -26,7 +30,7 @@ import { isMetricColumnESQL, isMetricColumnNoESQL, colorModeToApplyColorTo } fro import { stripUndefined } from '../../utils'; type APIMetricRowCommonProps = Partial< - Pick[number], 'visible' | 'alignment' | 'width'> + Pick[number], 'visible' | 'alignment' | 'width'> >; function buildCommonMetricRowProps(column: ColumnState): APIMetricRowCommonProps { @@ -44,7 +48,7 @@ function buildCommonMetricRowProps(column: ColumnState): APIMetricRowCommonProps */ function buildColorProps( column: ColumnState -): Partial[number], 'apply_color_to' | 'color'>> { +): Partial[number], 'apply_color_to' | 'color'>> { const { colorMode, palette, colorMapping } = column; if (!colorMode || colorMode === 'none') return {}; @@ -72,7 +76,7 @@ function buildColorProps( type APIMetricProps = APIMetricRowCommonProps & Partial< - Pick[number], 'apply_color_to' | 'color' | 'summary'> + Pick[number], 'apply_color_to' | 'color' | 'summary'> >; function buildMetricsAPI(column: ColumnState): APIMetricProps { @@ -88,7 +92,7 @@ function buildMetricsAPI(column: ColumnState): APIMetricProps { function buildRowCommonProps( column: ColumnState -): Pick[number], 'collapse_by' | 'click_filter'> { +): Pick[number], 'collapse_by' | 'click_filter'> { const { collapseFn, oneClickFilter } = column; return { ...buildCommonMetricRowProps(column), @@ -100,7 +104,7 @@ function buildRowCommonProps( type APIRowPropsNoESQL = APIMetricRowCommonProps & Partial< Pick< - NonNullable[number], + NonNullable[number], 'apply_color_to' | 'color' | 'collapse_by' | 'click_filter' > >; @@ -124,7 +128,7 @@ function buildRowsAPINoESQL(column: ColumnState): APIRowPropsNoESQL { type APIRowPropsESQL = APIMetricRowCommonProps & Partial< Pick< - NonNullable[number], + NonNullable[number], 'apply_color_to' | 'color' | 'collapse_by' | 'click_filter' > >; @@ -137,11 +141,11 @@ function buildRowsAPIESQL(column: ColumnState): APIRowPropsESQL { } type DatatableColumnsNoESQLAndMapping = Pick< - DatatableStateNoESQL, + DatatableConfigNoESQL, 'metrics' | 'rows' | 'split_metrics_by' > & { columnIdMapping: ColumnIdMapping }; type DatatableColumnsESQLAndMapping = Pick< - DatatableStateESQL, + DatatableConfigESQL, 'metrics' | 'rows' | 'split_metrics_by' > & { columnIdMapping: ColumnIdMapping }; @@ -180,9 +184,9 @@ export function convertDatatableColumnsToAPI( const columnStateMap = new Map(columns.map((col) => [col.columnId, col])); if (isFormBasedLayer(layer)) { - const metrics: DatatableStateNoESQL['metrics'] = []; - const rows: NonNullable = []; - const splitMetricsBy: NonNullable = []; + const metrics: DatatableConfigNoESQL['metrics'] = []; + const rows: NonNullable = []; + const splitMetricsBy: NonNullable = []; // Use columnOrder from the layer to preserve the correct row ordering/ aggregation nesting const orderedColumnIds = layer.columnOrder; @@ -239,9 +243,9 @@ export function convertDatatableColumnsToAPI( }; } - const metrics: DatatableStateESQL['metrics'] = []; - const rows: NonNullable = []; - const splitMetricsBy: NonNullable = []; + const metrics: DatatableConfigESQL['metrics'] = []; + const rows: NonNullable = []; + const splitMetricsBy: NonNullable = []; // Preserve ES|QL column order based on the datasource layer columns const orderedColumnIds = layer.columns.map(({ columnId }) => columnId); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/index.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/index.ts index 94abfbd29e913..c35fd3d9065f4 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/index.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/index.ts @@ -9,7 +9,7 @@ import type { FormBasedLayer, DatatableVisualizationState, TextBasedLayer } from '@kbn/lens-common'; import type { SavedObjectReference } from '@kbn/core/server'; import type { DataViewSpec } from '@kbn/data-views-plugin/common'; -import type { DatatableState } from '../../../../schema'; +import type { DatatableConfig } from '../../../../schema'; import { buildDataSourceStateESQL, buildDataSourceStateNoESQL, @@ -26,7 +26,7 @@ export function buildVisualizationAPI( adHocDataViews: Record, references: SavedObjectReference[], adhocReferences?: SavedObjectReference[] -): DatatableState { +): DatatableConfig { if (isTextBasedLayer(layer)) { const dataSource = buildDataSourceStateESQL(layer); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/styling.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/styling.ts index fbd7e55ef8797..c199a9b786c12 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/styling.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_api/styling.ts @@ -10,11 +10,11 @@ import type { DatatableVisualizationState, RowHeightMode } from '@kbn/lens-common'; import { LENS_ROW_HEIGHT_MODE, LENS_DATAGRID_DENSITY } from '@kbn/lens-common'; import { parseTransposeId } from '@kbn/transpose-utils'; -import type { DatatableState } from '../../../../schema'; +import type { DatatableConfig } from '../../../../schema'; import type { ColumnIdMapping } from './columns'; import { stripUndefined } from '../../utils'; -type DatatableStyling = NonNullable; +type DatatableStyling = NonNullable; type HeightAPI = NonNullable['height']>; type ValueHeightAPI = HeightAPI['value']; type HeaderHeightAPI = HeightAPI['header']; @@ -141,7 +141,7 @@ function parseSortingToAPI( export function convertStylingToAPIFormat( visualization: DatatableVisualizationState, columnIdMapping: ColumnIdMapping -): Pick { +): Pick { const { paging, sorting } = visualization; const densityAPI = parseDensityToAPI(visualization); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/columns.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/columns.ts index 3c109b735a0c3..e1087355a26a4 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/columns.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/columns.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ import type { ColumnState } from '@kbn/lens-common'; -import type { DatatableState } from '../../../../schema'; +import type { DatatableConfig } from '../../../../schema'; import { fromColorMappingAPIToLensState, fromColorByValueAPIToLensState, @@ -24,8 +24,8 @@ import { function buildColorProps( config: - | NonNullable[number] - | NonNullable[number] + | NonNullable[number] + | NonNullable[number] ): Partial> { if (!config.apply_color_to) return {}; const colorMode = applyColorToToColorMode(config.apply_color_to); @@ -47,8 +47,8 @@ function buildColorProps( function buildCommonMetricRowState( config: - | NonNullable[number] - | NonNullable[number] + | NonNullable[number] + | NonNullable[number] ): Pick< ColumnState, 'hidden' | 'alignment' | 'colorMode' | 'isTransposed' | 'palette' | 'colorMapping' | 'width' @@ -62,7 +62,7 @@ function buildCommonMetricRowState( }; } -export function buildMetricsState(metrics: DatatableState['metrics']): ColumnState[] { +export function buildMetricsState(metrics: DatatableConfig['metrics']): ColumnState[] { if (!metrics) return []; return metrics.map((metric, index) => { @@ -82,7 +82,7 @@ export function buildMetricsState(metrics: DatatableState['metrics']): ColumnSta }); } -export function buildRowsState(rows: DatatableState['rows']): ColumnState[] { +export function buildRowsState(rows: DatatableConfig['rows']): ColumnState[] { if (!rows) return []; return rows.map((row, index) => { @@ -98,7 +98,7 @@ export function buildRowsState(rows: DatatableState['rows']): ColumnState[] { } export function buildSplitMetricsByState( - splitMetrics: DatatableState['split_metrics_by'] + splitMetrics: DatatableConfig['split_metrics_by'] ): ColumnState[] { if (!splitMetrics) return []; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.test.ts index 5ff05c6170c2c..93f5e58772686 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.test.ts @@ -7,13 +7,13 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { DatatableState, DatatableStateESQL } from '../../../../schema'; +import type { DatatableConfig, DatatableConfigESQL } from '../../../../schema'; import { buildVisualizationState, getValueColumns } from '.'; describe('Datatable ES|QL column ordering', () => { describe('buildVisualizationState', () => { it('should order visualization columns as rows, split_metrics_by, then metrics', () => { - const config: DatatableState = { + const config: DatatableConfig = { type: 'data_table', data_source: { type: 'esql', @@ -39,7 +39,7 @@ describe('Datatable ES|QL column ordering', () => { }); it('should mark row columns as isMetric: false and metric columns as isMetric: true', () => { - const config: DatatableState = { + const config: DatatableConfig = { type: 'data_table', data_source: { type: 'esql', @@ -68,7 +68,7 @@ describe('Datatable ES|QL column ordering', () => { metrics: [{ column: 'bytes' }, { column: 'requests' }], rows: [{ column: 'host' }], split_metrics_by: [{ column: 'region' }], - } as unknown as DatatableStateESQL; + } as unknown as DatatableConfigESQL; const result = getValueColumns(config); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.ts index 17f78a8b43fb7..708ce38ee42c9 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/index.ts @@ -12,7 +12,11 @@ import type { FormBasedPersistedState, PersistedIndexPatternLayer, } from '@kbn/lens-common'; -import type { DatatableState, DatatableStateESQL, DatatableStateNoESQL } from '../../../../schema'; +import type { + DatatableConfig, + DatatableConfigESQL, + DatatableConfigNoESQL, +} from '../../../../schema'; import { DEFAULT_LAYER_ID } from '../../../../constants'; import { fromMetricAPItoLensState } from '../../../columns/metric'; import { getValueColumn } from '../../../columns/esql_column'; @@ -29,7 +33,7 @@ import { buildStylingState } from './styling'; import { processMetricColumnsWithReferences } from '../../utils'; export function buildFormBasedLayer( - config: DatatableStateNoESQL + config: DatatableConfigNoESQL ): FormBasedPersistedState['layers'] { const layers: Record = generateLayer( DEFAULT_LAYER_ID, @@ -74,7 +78,7 @@ export function buildFormBasedLayer( return layers; } -export function getValueColumns(config: DatatableStateESQL) { +export function getValueColumns(config: DatatableConfigESQL) { return [ ...(config.rows ?? []).map((row, index) => getValueColumn( @@ -97,7 +101,7 @@ export function getValueColumns(config: DatatableStateESQL) { ]; } -export function buildVisualizationState(config: DatatableState): DatatableVisualizationState { +export function buildVisualizationState(config: DatatableConfig): DatatableVisualizationState { const metrics = buildMetricsState(config.metrics); const rows = buildRowsState(config.rows); const splitMetrics = buildSplitMetricsByState(config.split_metrics_by); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/styling.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/styling.ts index 948305e651cdb..c2d06da98d030 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/styling.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/datatable/to_state/styling.ts @@ -9,13 +9,13 @@ import type { DatatableVisualizationState } from '@kbn/lens-common'; import { LENS_DATAGRID_DENSITY } from '@kbn/lens-common'; import { getTransposeId, TRANSPOSE_SEPARATOR } from '@kbn/transpose-utils'; -import type { DatatableState } from '../../../../schema'; +import type { DatatableConfig } from '../../../../schema'; import { stripUndefined } from '../../utils'; import { getAccessorName } from '../helpers'; import { METRIC_ACCESSOR_PREFIX, ROW_ACCESSOR_PREFIX } from '../constants'; function getSortingColumnId( - sortBy: NonNullable['sort_by']> + sortBy: NonNullable['sort_by']> ): string | undefined { switch (sortBy.column_type) { case 'metric': @@ -31,7 +31,7 @@ function getSortingColumnId( } } -function buildSortingState(config: DatatableState): Pick { +function buildSortingState(config: DatatableConfig): Pick { if (!config.styling?.sort_by) { return {}; } @@ -50,7 +50,7 @@ function buildSortingState(config: DatatableState): Pick { +function buildPagingState(config: DatatableConfig): Pick { if (!config.styling?.paging) { return {}; } @@ -92,7 +92,7 @@ function buildPagingState(config: DatatableState): Pick { if (config.styling?.row_numbers == null) { return {}; @@ -101,7 +101,7 @@ function buildShowRowNumbers( } export function buildStylingState( - config: DatatableState + config: DatatableConfig ): Pick< DatatableVisualizationState, | 'headerRowHeight' diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/gauge.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/gauge.ts index 83a8c9b84b94d..984e9c36e7d56 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/gauge.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/gauge.ts @@ -17,7 +17,7 @@ import type { import type { DataViewSpec } from '@kbn/data-views-plugin/common'; import type { SavedObjectReference } from '@kbn/core/types'; import type { CustomPaletteParams, PaletteOutput } from '@kbn/coloring'; -import type { GaugeState, LensApiState } from '../../schema'; +import type { GaugeConfig, LensApiConfig } from '../../schema'; import { AUTO_COLOR, NO_COLOR, @@ -47,7 +47,7 @@ import { getSharedChartLensStateToAPI, stripUndefined, } from './utils'; -import type { GaugeStateESQL, GaugeStateNoESQL } from '../../schema/charts/gauge'; +import type { GaugeConfigESQL, GaugeConfigNoESQL } from '../../schema/charts/gauge'; import { fromMetricAPItoLensState } from '../columns/metric'; import type { LensApiAllMetricOperations } from '../../schema/metric_ops'; import { getValueApiColumn, getValueColumn } from '../columns/esql_column'; @@ -59,7 +59,7 @@ function getAccessorName(type: 'metric' | 'max' | 'min' | 'goal') { return `${ACCESSOR}_${type}`; } -function convertColorToLensState(color: GaugeState['metric']['color']): { +function convertColorToLensState(color: GaugeConfig['metric']['color']): { colorMode: GaugeVisualizationState['colorMode']; palette?: PaletteOutput; } { @@ -77,7 +77,7 @@ function convertColorToLensState(color: GaugeState['metric']['color']): { }; } -function buildVisualizationState(config: GaugeState): GaugeVisualizationState { +function buildVisualizationState(config: GaugeConfig): GaugeVisualizationState { const layer = config; return { @@ -115,7 +115,7 @@ function reverseBuildVisualizationState( adHocDataViews: Record, references: SavedObjectReference[], adhocReferences?: SavedObjectReference[] -): GaugeState { +): GaugeConfig { const metricAccessor = getMetricAccessor(visualization); if (metricAccessor == null) { throw new Error('Metric accessor is missing in the visualization state'); @@ -133,7 +133,7 @@ function reverseBuildVisualizationState( throw new Error('Unsupported DataSource type'); } - const props: DeepPartial> = { + const props: DeepPartial> = { ...generateApiLayer(layer), styling: stripUndefined({ shape: @@ -185,7 +185,7 @@ function reverseBuildVisualizationState( } : {}), }, - } as GaugeState; + } as GaugeConfig; if (props.metric) { props.metric.title = { @@ -219,12 +219,12 @@ function reverseBuildVisualizationState( return { type: 'gauge', - data_source: dataSource satisfies GaugeState['data_source'], + data_source: dataSource satisfies GaugeConfig['data_source'], ...props, - } as GaugeState; + } as GaugeConfig; } -function buildFormBasedLayer(layer: GaugeStateNoESQL): FormBasedPersistedState['layers'] { +function buildFormBasedLayer(layer: GaugeConfigNoESQL): FormBasedPersistedState['layers'] { const columns = fromMetricAPItoLensState(layer.metric); const layers: Record = generateLayer(DEFAULT_LAYER_ID, layer); @@ -257,7 +257,7 @@ function buildFormBasedLayer(layer: GaugeStateNoESQL): FormBasedPersistedState[' return layers; } -function getValueColumns(layer: GaugeStateESQL) { +function getValueColumns(layer: GaugeConfigESQL) { return [ getValueColumn(getAccessorName('metric'), layer.metric, 'number'), ...(layer.metric.max @@ -281,8 +281,9 @@ type GaugeAttributesWithoutFiltersAndQuery = Omit & { state: Omit; }; -export function fromAPItoLensState(config: GaugeState): GaugeAttributesWithoutFiltersAndQuery { - const _buildDataLayer = (cfg: unknown, i: number) => buildFormBasedLayer(cfg as GaugeStateNoESQL); +export function fromAPItoLensState(config: GaugeConfig): GaugeAttributesWithoutFiltersAndQuery { + const _buildDataLayer = (cfg: unknown, i: number) => + buildFormBasedLayer(cfg as GaugeConfigNoESQL); const { layers, usedDataviews } = buildDatasourceStates(config, _buildDataLayer, getValueColumns); @@ -311,7 +312,7 @@ export function fromAPItoLensState(config: GaugeState): GaugeAttributesWithoutFi export function fromLensStateToAPI( config: LensAttributes -): Extract { +): Extract { const { state } = config; const visualization = state.visualization as GaugeVisualizationState; const layers = getDatasourceLayers(state); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/from_api.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/from_api.ts index 1433b055ce263..8e0d6a980783c 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/from_api.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/from_api.ts @@ -23,7 +23,7 @@ import type { import { DEFAULT_LAYER_ID } from '../../../constants'; import { legendSizeCompat } from '../legend_sizes'; import { getSharedChartAPIToLensState, stripUndefined } from '../utils'; -import type { HeatmapState } from '../../../schema'; +import type { HeatmapConfig } from '../../../schema'; import { fromColorByValueAPIToLensState, isAutoColor } from '../../coloring'; import { addLayerColumn, @@ -32,7 +32,7 @@ import { generateLayer, getAdhocDataviews, } from '../../utils'; -import type { HeatmapStateESQL, HeatmapStateNoESQL } from '../../../schema/charts/heatmap'; +import type { HeatmapConfigESQL, HeatmapConfigNoESQL } from '../../../schema/charts/heatmap'; import { fromMetricAPItoLensState } from '../../columns/metric'; import { fromBucketLensApiToLensState } from '../../columns/buckets'; import type { LensApiBucketOperations } from '../../../schema/bucket_ops'; @@ -45,7 +45,7 @@ function getAccessorName(type: 'x' | 'y' | 'value') { return `${ACCESSOR}_${type}`; } -function buildVisualizationState(config: HeatmapState): HeatmapVisualizationState { +function buildVisualizationState(config: HeatmapConfig): HeatmapVisualizationState { const layer = config; const valueAccessor = getAccessorName('value'); const basePalette = @@ -95,7 +95,7 @@ function buildVisualizationState(config: HeatmapState): HeatmapVisualizationStat }; } -function buildFormBasedLayer(layer: HeatmapStateNoESQL): FormBasedPersistedState['layers'] { +function buildFormBasedLayer(layer: HeatmapConfigNoESQL): FormBasedPersistedState['layers'] { const metricColumns = fromMetricAPItoLensState(layer.metric); const layers: Record = generateLayer(DEFAULT_LAYER_ID, layer); @@ -125,7 +125,7 @@ function buildFormBasedLayer(layer: HeatmapStateNoESQL): FormBasedPersistedState return layers; } -function getValueColumns(layer: HeatmapStateESQL) { +function getValueColumns(layer: HeatmapConfigESQL) { return [ getValueColumn(getAccessorName('value'), layer.metric, 'number'), ...(layer.x ? [getValueColumn(getAccessorName('x'), layer.x)] : []), @@ -142,8 +142,8 @@ type HeatmapAttributesWithoutFiltersAndQuery = Omit state: Omit; }; -export function fromAPItoLensState(config: HeatmapState): HeatmapAttributesWithoutFiltersAndQuery { - const _buildDataLayer = (cfg: unknown) => buildFormBasedLayer(cfg as HeatmapStateNoESQL); +export function fromAPItoLensState(config: HeatmapConfig): HeatmapAttributesWithoutFiltersAndQuery { + const _buildDataLayer = (cfg: unknown) => buildFormBasedLayer(cfg as HeatmapConfigNoESQL); const { layers, usedDataviews } = buildDatasourceStates(config, _buildDataLayer, getValueColumns); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/to_api.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/to_api.ts index a77f86baacdd4..179ccb1cab7c0 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/to_api.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/heatmap/to_api.ts @@ -23,7 +23,7 @@ import { getScaleTypeFromColumnType, stripUndefined, } from '../utils'; -import type { HeatmapState } from '../../../schema'; +import type { HeatmapConfig } from '../../../schema'; import { AUTO_COLOR, fromColorByValueLensStateToAPI } from '../../coloring'; import { type LensAttributes } from '../../../types'; import { @@ -33,17 +33,17 @@ import { isTextBasedLayer, operationFromColumn, } from '../../utils'; -import type { HeatmapStateESQL, HeatmapStateNoESQL } from '../../../schema/charts/heatmap'; +import type { HeatmapConfigESQL, HeatmapConfigNoESQL } from '../../../schema/charts/heatmap'; import { getValueApiColumn } from '../../columns/esql_column'; import type { LensApiAllMetricOperations } from '../../../schema/metric_ops'; import { legendSizeCompat } from '../legend_sizes'; import { axisLabelOrientationCompat } from '../common'; import type { XScaleSchemaType } from '../../../schema/charts/shared'; -function getLegendProps(legend: HeatmapVisualizationState['legend']): HeatmapState['legend'] { +function getLegendProps(legend: HeatmapVisualizationState['legend']): HeatmapConfig['legend'] { return { visibility: legend.isVisible ? 'visible' : 'hidden', - ...stripUndefined({ + ...stripUndefined({ truncate_after_lines: getLegendTruncateAfterLines(legend), size: legendSizeCompat.toAPI(legend.legendSize), }), @@ -53,7 +53,7 @@ function getLegendProps(legend: HeatmapVisualizationState['legend']): HeatmapSta function getGridConfigProps( gridConfig: HeatmapVisualizationState['gridConfig'], xAxisScale?: XScaleSchemaType -): HeatmapState['axis'] { +): HeatmapConfig['axis'] { return { x: { labels: { @@ -88,7 +88,7 @@ function reverseBuildVisualizationState( adHocDataViews: Record, references: Reference[], adhocReferences?: Reference[] -): HeatmapState { +): HeatmapConfig { const valueAccessor = visualization.valueAccessor; if (valueAccessor == null) { throw new Error('Value accessor is missing in the visualization state'); @@ -110,13 +110,13 @@ function reverseBuildVisualizationState( labels: { visible: visualization.gridConfig.isCellLabelVisible }, }, }, - } satisfies Partial; + } satisfies Partial; const paletteProps = { color: visualization.palette ? fromColorByValueLensStateToAPI(visualization.palette) : AUTO_COLOR, - } satisfies Partial; + } satisfies Partial; if (isTextBasedLayer(layer)) { if (!visualization.xAccessor) { @@ -134,7 +134,7 @@ function reverseBuildVisualizationState( }, x: getValueApiColumn(visualization.xAccessor, layer), ...(visualization.yAccessor && { y: getValueApiColumn(visualization.yAccessor, layer) }), - } satisfies HeatmapStateESQL; + } satisfies HeatmapConfigESQL; } const dataSource = buildDataSourceStateNoESQL( @@ -154,10 +154,10 @@ function reverseBuildVisualizationState( } as LensApiAllMetricOperations, x: operationFromColumn(visualization.xAccessor!, layer), y: visualization.yAccessor && operationFromColumn(visualization.yAccessor, layer), - } as HeatmapStateNoESQL; + } as HeatmapConfigNoESQL; } -export function fromLensStateToAPI(config: LensAttributes): HeatmapState { +export function fromLensStateToAPI(config: LensAttributes): HeatmapConfig { const { state } = config; const visualization = state.visualization as HeatmapVisualizationState; const layers = getDatasourceLayers(state); @@ -177,5 +177,5 @@ export function fromLensStateToAPI(config: LensAttributes): HeatmapState { config.references, config.state.internalReferences ), - } satisfies HeatmapState; + } satisfies HeatmapConfig; } diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/legacy_metric.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/legacy_metric.ts index 74dd53ef79f12..5bc1a981f2d5f 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/legacy_metric.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/legacy_metric.ts @@ -28,13 +28,13 @@ import { operationFromColumn, } from '../utils'; import { getValueApiColumn, getValueColumn } from '../columns/esql_column'; -import type { LensApiState, LegacyMetricState } from '../../schema'; +import type { LensApiConfig, LegacyMetricConfig } from '../../schema'; import { fromMetricAPItoLensState } from '../columns/metric'; import type { DeepMutable, DeepPartial } from '../utils'; import { generateLayer } from '../utils'; import type { - LegacyMetricStateESQL, - LegacyMetricStateNoESQL, + LegacyMetricConfigESQL, + LegacyMetricConfigNoESQL, } from '../../schema/charts/legacy_metric'; import { getSharedChartLensStateToAPI, @@ -54,7 +54,7 @@ import { stripUndefined } from './utils'; const ACCESSOR = 'legacy_metric_accessor'; -function buildVisualizationState(config: LegacyMetricState): LegacyMetricVisualizationState { +function buildVisualizationState(config: LegacyMetricConfig): LegacyMetricVisualizationState { const layer = config; return { @@ -83,7 +83,7 @@ function reverseBuildVisualizationState( adHocDataViews: Record, references: SavedObjectReference[], adhocReferences?: SavedObjectReference[] -): LegacyMetricState { +): LegacyMetricConfig { if (visualization.accessor == null) { throw new Error('Metric accessor is missing in the visualization state'); } @@ -100,16 +100,16 @@ function reverseBuildVisualizationState( throw new Error('Unsupported DataSource type'); } - const props: DeepPartial> = { + const props: DeepPartial> = { ...generateApiLayer(layer), metric: isEsqlTableTypeDataSource(dataSource) ? getValueApiColumn(visualization.accessor, layer as TextBasedLayer) : operationFromColumn(visualization.accessor, layer as FormBasedLayer), - } as LegacyMetricState; + } as LegacyMetricConfig; if (props.metric) { if (visualization.size) { - props.metric.size = visualization.size as LegacyMetricState['metric']['size']; + props.metric.size = visualization.size as LegacyMetricConfig['metric']['size']; } if (visualization.titlePosition || visualization.textAlign) { @@ -138,12 +138,12 @@ function reverseBuildVisualizationState( return { type: 'legacy_metric', - data_source: dataSource satisfies LegacyMetricState['data_source'], + data_source: dataSource satisfies LegacyMetricConfig['data_source'], ...props, - } as LegacyMetricState; + } as LegacyMetricConfig; } -function buildFormBasedLayer(layer: LegacyMetricStateNoESQL): FormBasedPersistedState['layers'] { +function buildFormBasedLayer(layer: LegacyMetricConfigNoESQL): FormBasedPersistedState['layers'] { const columns = fromMetricAPItoLensState(layer.metric); const layers: Record = generateLayer(DEFAULT_LAYER_ID, layer); @@ -154,7 +154,7 @@ function buildFormBasedLayer(layer: LegacyMetricStateNoESQL): FormBasedPersisted return layers; } -function getValueColumns(layer: LegacyMetricStateESQL) { +function getValueColumns(layer: LegacyMetricConfigESQL) { return [getValueColumn(ACCESSOR, layer.metric, 'number')]; } @@ -168,10 +168,10 @@ type LegacyMetricAttributesWithoutFiltersAndQuery = Omit - buildFormBasedLayer(cfg as LegacyMetricStateNoESQL); + buildFormBasedLayer(cfg as LegacyMetricConfigNoESQL); const { layers, usedDataviews } = buildDatasourceStates(config, _buildDataLayer, getValueColumns); @@ -200,7 +200,7 @@ export function fromAPItoLensState( export function fromLensStateToAPI( config: LensAttributes -): Extract { +): Extract { const { state } = config; const visualization = state.visualization as LegacyMetricVisualizationState; const layers = getDatasourceLayers(state); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/metric.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/metric.ts index dba186bd324c8..0e159e487eee1 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/metric.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/metric.ts @@ -43,14 +43,13 @@ import { } from '../utils'; import { fromBucketLensApiToLensState } from '../columns/buckets'; import { getValueApiColumn, getValueColumn } from '../columns/esql_column'; -import type { MetricState } from '../../schema'; +import type { MetricConfig } from '../../schema'; import { fromMetricAPItoLensState } from '../columns/metric'; import type { LensApiBucketOperations } from '../../schema/bucket_ops'; import { generateLayer } from '../utils'; import type { - MetricStateESQL, - MetricStateNoESQL, - MetricStyling, + MetricConfigESQL, + MetricConfigNoESQL, PrimaryMetricType, SecondaryMetricType, } from '../../schema/charts/metric'; @@ -77,13 +76,14 @@ import { isAPIColumnOfBucketType, isAPIColumnOfMetricType } from '../columns/uti type MetricApiCompareType = Extract, { compare: any }>['compare']; -type WritableMetricStateWithoutDataset = DeepWriteable>; +type WritableMetricConfigWithoutDataset = DeepWriteable>; const ACCESSOR = 'metric_accessor'; const HISTOGRAM_COLUMN_NAME = 'x_date_histogram'; const TRENDLINE_LAYER_ID = 'layer_0_trendline'; const LENS_METRIC_COMPARE_TO_REVERSED = false; +type MetricStyling = NonNullable; type MetricIconName = NonNullable['name']>; const iconCompat = getReversibleMappings([ @@ -138,11 +138,11 @@ function fromCompareAPIToLensState(compareToConfig: MetricApiCompareType): { }; } -function isSecondaryMetric(metric: MetricState['metrics'][number]): metric is SecondaryMetricType { +function isSecondaryMetric(metric: MetricConfig['metrics'][number]): metric is SecondaryMetricType { return metric.type === 'secondary'; } -function isPrimaryMetric(metric: MetricState['metrics'][number]): metric is PrimaryMetricType { +function isPrimaryMetric(metric: MetricConfig['metrics'][number]): metric is PrimaryMetricType { return metric.type === 'primary'; } @@ -229,7 +229,7 @@ function convertStylingToAPIFormat( }); } -function buildVisualizationState(config: MetricState): MetricVisualizationState { +function buildVisualizationState(config: MetricConfig): MetricVisualizationState { const layer = config; const [primaryMetric, secondaryMetric] = layer.metrics; @@ -331,7 +331,7 @@ function buildFromTextBasedLayer( layer: TextBasedLayer, metricAccessor: string, visualization: MetricVisualizationState -): WritableMetricStateWithoutDataset { +): WritableMetricConfigWithoutDataset { return enrichConfigurationWithVisualizationProperties( { type: 'metric', @@ -358,7 +358,7 @@ function buildFromTextBasedLayer( ...getValueApiColumn(visualization.secondaryMetricAccessor, layer), } : undefined, - ].filter(nonNullable) as MetricState['metrics'], + ].filter(nonNullable) as MetricConfig['metrics'], ...(visualization.breakdownByAccessor ? { breakdown_by: { @@ -376,7 +376,7 @@ function buildFromFormBasedLayer( layer: PersistedIndexPatternLayer, metricAccessor: string, visualization: MetricVisualizationState -): WritableMetricStateWithoutDataset { +): WritableMetricConfigWithoutDataset { const metric = operationFromColumn(metricAccessor, layer); if (!metric || !isAPIColumnOfMetricType(metric)) { throw Error('The primary metric must refer to a metric operation.'); @@ -435,7 +435,7 @@ function buildFromFormBasedLayer( { type: 'metric', ...generateApiLayer(layer), - metrics: metrics as MetricState['metrics'], + metrics: metrics as MetricConfig['metrics'], ...(breakdown_by ? { breakdown_by: { @@ -450,9 +450,9 @@ function buildFromFormBasedLayer( } function enrichConfigurationWithVisualizationProperties( - state: WritableMetricStateWithoutDataset, + state: WritableMetricConfigWithoutDataset, visualization: MetricVisualizationState -): WritableMetricStateWithoutDataset { +): WritableMetricConfigWithoutDataset { const [primaryMetric, secondaryMetric] = state.metrics; if (isSecondaryMetric(primaryMetric)) { @@ -525,7 +525,7 @@ function reverseBuildVisualizationState( adHocDataViews: Record, references: SavedObjectReference[], adhocReferences?: SavedObjectReference[] -): MetricState { +): MetricConfig { const metricAccessor = getMetricAccessor(visualization); if (metricAccessor == null) { throw new Error('Metric accessor is missing in the visualization state'); @@ -544,14 +544,14 @@ function reverseBuildVisualizationState( } return { - data_source: dataSource satisfies MetricState['data_source'], + data_source: dataSource satisfies MetricConfig['data_source'], ...(isTextBasedLayer(layer) ? buildFromTextBasedLayer(layer, metricAccessor, visualization) : buildFromFormBasedLayer(layer, metricAccessor, visualization)), - } as MetricState; + } as MetricConfig; } -function buildFormBasedLayer(layer: MetricStateNoESQL): FormBasedPersistedState['layers'] { +function buildFormBasedLayer(layer: MetricConfigNoESQL): FormBasedPersistedState['layers'] { const [primaryMetric, secondaryMetric] = layer.metrics ?? []; if (!isAPIColumnOfMetricType(primaryMetric) || isSecondaryMetric(primaryMetric)) { throw Error('The primary metric must refer to a metric operation.'); @@ -621,7 +621,7 @@ function buildFormBasedLayer(layer: MetricStateNoESQL): FormBasedPersistedState[ return layers; } -function getValueColumns(layer: MetricStateESQL) { +function getValueColumns(layer: MetricConfigESQL) { const [primaryMetric, secondaryMetric] = layer.metrics ?? []; if (isSecondaryMetric(primaryMetric)) { throw Error('The primary metric must refer to a metric operation.'); @@ -652,9 +652,9 @@ export type MetricAttributesWithoutFiltersAndQuery = Omit; }; -export function fromAPItoLensState(config: MetricState): MetricAttributesWithoutFiltersAndQuery { +export function fromAPItoLensState(config: MetricConfig): MetricAttributesWithoutFiltersAndQuery { const _buildDataLayer = (cfg: unknown, i: number) => - buildFormBasedLayer(cfg as MetricStateNoESQL); + buildFormBasedLayer(cfg as MetricConfigNoESQL); const { layers, usedDataviews } = buildDatasourceStates(config, _buildDataLayer, getValueColumns); @@ -681,7 +681,7 @@ export function fromAPItoLensState(config: MetricState): MetricAttributesWithout }; } -export function fromLensStateToAPI(config: LensAttributes): MetricState { +export function fromLensStateToAPI(config: LensAttributes): MetricConfig { const { state } = config; const visualization = state.visualization as MetricVisualizationState; const layers = getDatasourceLayers(state); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/partition.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/partition.ts index 977ce61eb9b3c..9d634210f859a 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/partition.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/partition.ts @@ -18,9 +18,9 @@ import type { SavedObjectReference } from '@kbn/core/server'; import type { PaletteOutput } from '@kbn/coloring'; import type { $Values } from 'utility-types'; import type { - PartitionState, - PartitionStateESQL, - PartitionStateNoESQL, + PartitionConfig, + PartitionConfigESQL, + PartitionConfigNoESQL, } from '../../schema/charts/partition'; import { type LensAttributes } from '../../types'; import type { DataSourceStateLayer } from '../utils'; @@ -48,10 +48,10 @@ import { addLayerColumn, groupIsNotCollapsed, isEsqlTableTypeDataSource } from ' import { fromMetricAPItoLensState } from '../columns/metric'; import { fromBucketLensApiToLensState } from '../columns/buckets'; import { DEFAULT_LAYER_ID } from '../../constants'; -import type { PieState } from '../../schema/charts/pie'; -import type { WaffleState } from '../../schema/charts/waffle'; -import type { MosaicState } from '../../schema/charts/mosaic'; -import type { TreemapState } from '../../schema/charts/treemap'; +import type { PieConfig } from '../../schema/charts/pie'; +import type { WaffleConfig } from '../../schema/charts/waffle'; +import type { MosaicConfig } from '../../schema/charts/mosaic'; +import type { TreemapConfig } from '../../schema/charts/treemap'; import type { StaticColorType } from '../../schema/color'; import type { CollapseBySchema } from '../../schema/shared'; import { getValueApiColumn, getValueColumn } from '../columns/esql_column'; @@ -64,9 +64,9 @@ import { isLegacyColorPalette, } from '../coloring'; -type PieStyling = NonNullable>>; +type PieStyling = NonNullable>>; type PartitionStyling = NonNullable< - NonNullable['styling']>> + NonNullable['styling']>> >; type PartitionLens = Extract< TypedLensSerializedState['attributes'], @@ -84,7 +84,7 @@ function getAccessorName(type: 'group_by' | 'metric' | 'group_breakdown_by', ind return `${ACCESSOR}_${type}_${index}`; } -function isAPIPartitionLayer(layer: unknown): layer is PartitionState { +function isAPIPartitionLayer(layer: unknown): layer is PartitionConfig { return ( typeof layer === 'object' && layer !== null && @@ -94,30 +94,30 @@ function isAPIPartitionLayer(layer: unknown): layer is PartitionState { ); } -function isESQLPartitionLayer(layer: PartitionState): layer is PartitionStateESQL { +function isESQLPartitionLayer(layer: PartitionConfig): layer is PartitionConfigESQL { return isEsqlTableTypeDataSource(layer.data_source); } -function isAPIPieChartLayer(layer: PartitionState): layer is PieState { +function isAPIPieChartLayer(layer: PartitionConfig): layer is PieConfig { return layer.type === 'pie'; } -function isAPIWaffleChartLayer(layer: PartitionState): layer is WaffleState { +function isAPIWaffleChartLayer(layer: PartitionConfig): layer is WaffleConfig { return layer.type === 'waffle'; } -function isAPIMosaicChartLayer(layer: PartitionState): layer is MosaicState { +function isAPIMosaicChartLayer(layer: PartitionConfig): layer is MosaicConfig { return layer.type === 'mosaic'; } -function getPartitionMetricsAsArray(config: PartitionState) { +function getPartitionMetricsAsArray(config: PartitionConfig) { if (isAPIMosaicChartLayer(config)) { return [config.metric]; } return config.metrics; } -function isAPITreemapChartLayer(layer: PartitionState): layer is TreemapState { +function isAPITreemapChartLayer(layer: PartitionConfig): layer is TreemapConfig { return layer.type === 'treemap'; } @@ -212,7 +212,7 @@ function convertAPICategoryDisplayOption( } function convertAPILegendDisplayOption( - option: PartitionState + option: PartitionConfig ): Pick< PartitionLens['state']['visualization']['layers'][0], 'legendDisplay' | 'nestedLegend' | 'legendMaxLines' | 'legendSize' | 'truncateLegend' @@ -232,7 +232,7 @@ function convertAPILegendDisplayOption( return { legendDisplay: legend?.visibility === 'visible' ? 'show' : 'hide', ...legendOptions }; } -function convertAPIStaticColorToLensState(config: PartitionState) { +function convertAPIStaticColorToLensState(config: PartitionConfig) { if (isAPIMosaicChartLayer(config)) { return undefined; } @@ -263,7 +263,7 @@ function convertCollapseAPItoCollapseFns

[getAccessorName(prop, index), collapse_by]); } -function computeSharedPartitionLayerState(config: PartitionState) { +function computeSharedPartitionLayerState(config: PartitionConfig) { const groupColouring = config.group_by?.find(({ color }) => color != null)?.color; const hasColorMapping = groupColouring != null && !('type' in groupColouring); return { @@ -302,8 +302,8 @@ function getEmptySizeRatioFromDonutHoleOption( } type PartitionMetricItem = - | Exclude['metrics'][number] - | MosaicState['metric']; + | Exclude['metrics'][number] + | MosaicConfig['metric']; function hasStaticColorAssignment( metric: T @@ -311,7 +311,7 @@ function hasStaticColorAssignment( return 'color' in metric && metric.color != null && metric.color.type === 'static'; } -function shouldAllowMultipleMetrics(config: PartitionState): boolean { +function shouldAllowMultipleMetrics(config: PartitionConfig): boolean { const metricsArray = getPartitionMetricsAsArray(config); return ( metricsArray.length > 1 || @@ -321,7 +321,7 @@ function shouldAllowMultipleMetrics(config: PartitionState): boolean { } function buildVisualizationState( - config: PartitionState + config: PartitionConfig ): PartitionLensWithoutQueryAndFilters['state']['visualization'] { const metrics = getPartitionMetricsAsArray(config).map((_, index) => getAccessorName('metric', index) @@ -410,7 +410,7 @@ function buildVisualizationState( throw new Error('Unsupported partition chart type'); } -export function fromAPItoLensState(config: PartitionState): PartitionLensWithoutQueryAndFilters { +export function fromAPItoLensState(config: PartitionConfig): PartitionLensWithoutQueryAndFilters { const { layers, usedDataviews } = buildDatasourceStates( config, buildFormBasedPartitionLayer, @@ -434,7 +434,7 @@ export function fromAPItoLensState(config: PartitionState): PartitionLensWithout }; } -export function fromLensStateToAPI(config: LensAttributes): PartitionState { +export function fromLensStateToAPI(config: LensAttributes): PartitionConfig { const { state } = config; const visualizationState = state.visualization as LensPartitionVisualizationState; const layers = getDatasourceLayers(state); @@ -454,7 +454,7 @@ export function fromLensStateToAPI(config: LensAttributes): PartitionState { function fromLensStateToSharedPartitionAPI( visualization: PartitionLens['state']['visualization'] -): Pick | undefined { +): Pick | undefined { const layerState = visualization.layers[0]; const legend = stripUndefined({ visibility: @@ -481,12 +481,12 @@ function fromLensStateToAPIDataset( adHocDataViews: Record, references: SavedObjectReference[], adhocReferences: SavedObjectReference[] -): Pick { +): Pick { const layerId = visualization.layers[0].layerId; if (layer) { if (isTextBasedLayer(layer)) { - return { data_source: buildDataSourceStateESQL(layer) as PartitionStateESQL['data_source'] }; + return { data_source: buildDataSourceStateESQL(layer) as PartitionConfigESQL['data_source'] }; } if (isFormBasedLayer(layer)) { return { @@ -496,7 +496,7 @@ function fromLensStateToAPIDataset( adHocDataViews, references, adhocReferences - ) as PartitionState['data_source'], + ) as PartitionConfig['data_source'], }; } } @@ -577,7 +577,7 @@ function convertLensStateToAPIGrouping( color: index === groupIndexForColorMapping ? colorMapping : undefined, collapse_by: vizLayer.collapseFns?.[id] || undefined, // handle gracefully empty strings }) as NonNullable< - Extract['group_breakdown_by'] + Extract['group_breakdown_by'] >[0] ); } @@ -589,7 +589,7 @@ function convertLensStateToAPIGrouping( color: index === groupIndexForColorMapping ? colorMapping : undefined, collapse_by: vizLayer.collapseFns?.[id] || undefined, // handle gracefully empty strings }) as NonNullable< - Extract['group_breakdown_by'] + Extract['group_breakdown_by'] >[0] ); } @@ -598,7 +598,7 @@ function convertLensStateToAPIGrouping( function fromLensStateToAPIGroups( visualization: LensPartitionVisualizationState, layer: DataSourceStateLayer -): PartitionState['group_by'] { +): PartitionConfig['group_by'] { const vizLayer = visualization.layers[0]; const groupByAccessors = getGroups(vizLayer); @@ -616,7 +616,7 @@ function fromLensStateToAPIGroups( function fromLensStateToAPISecondaryGroups( visualization: LensPartitionVisualizationState, layer: DataSourceStateLayer -): Extract | {} { +): Extract | {} { if (!isStateMosaicChart(visualization)) { return {}; } @@ -721,7 +721,7 @@ function buildVisualizationAPI( adHocDataViews: Record, references: SavedObjectReference[], adhocReferences: SavedObjectReference[] -): PartitionState { +): PartitionConfig { const metricsArray = fromLensStateToAPIMetrics(visualization, layer); const metricsField = isStateMosaicChart(visualization) ? { metric: metricsArray[0] } @@ -734,5 +734,5 @@ function buildVisualizationAPI( ...fromLensStateToAPIDataset(visualization, layer, adHocDataViews, references, adhocReferences), ...fromLensStateToSharedPartitionAPI(visualization), styling: fromLensStateToChartSpecificStylingAPI(visualization), - }) as PartitionState; + }) as PartitionConfig; } diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/region_map.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/region_map.ts index a241d1aa8a618..4d63bbbc24f47 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/region_map.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/region_map.ts @@ -18,11 +18,11 @@ import type { import type { DataViewSpec } from '@kbn/data-views-plugin/common'; import type { SavedObjectReference } from '@kbn/core/types'; import type { - LensApiState, - RegionMapState, + LensApiConfig, + RegionMapConfig, LensApiBucketOperations, - RegionMapStateESQL, - RegionMapStateNoESQL, + RegionMapConfigESQL, + RegionMapConfigNoESQL, LensApiFieldMetricOrFormulaOperation, } from '../../schema'; import type { LensAttributes } from '../../types'; @@ -53,7 +53,7 @@ function getAccessorName(type: 'metric' | 'region') { return `${ACCESSOR}_${type}`; } -function buildVisualizationState(config: RegionMapState): ChoroplethChartState { +function buildVisualizationState(config: RegionMapConfig): ChoroplethChartState { const layer = config; return { @@ -72,7 +72,7 @@ function getRegionMapDataset( references: SavedObjectReference[], adhocReferences: SavedObjectReference[] = [], layerId: string -): RegionMapState['data_source'] { +): RegionMapConfig['data_source'] { const dataSource = buildDataSourceState( layer, layerId, @@ -91,7 +91,7 @@ function getRegionMapDataset( function getRegionMapMetric( layer: Omit | TextBasedLayer, visualization: ChoroplethChartState -): RegionMapState['metric'] { +): RegionMapConfig['metric'] { if (visualization.valueAccessor == null) { throw new Error('Metric accessor is missing in the visualization state'); } @@ -107,7 +107,7 @@ function getRegionMapMetric( function getRegionMapRegion( layer: Omit | TextBasedLayer, visualization: ChoroplethChartState -): RegionMapState['region'] { +): RegionMapConfig['region'] { if (visualization.regionAccessor == null) { throw new Error('Region accessor is missing in the visualization state'); } @@ -129,7 +129,7 @@ function reverseBuildVisualizationState( adHocDataViews: Record, references: SavedObjectReference[], adhocReferences?: SavedObjectReference[] -): RegionMapState { +): RegionMapConfig { const dataSource = getRegionMapDataset( layer, adHocDataViews, @@ -146,10 +146,10 @@ function reverseBuildVisualizationState( ...generateApiLayer(layer), metric, region, - } as RegionMapState; + } as RegionMapConfig; } -function buildFormBasedLayer(layer: RegionMapStateNoESQL): FormBasedPersistedState['layers'] { +function buildFormBasedLayer(layer: RegionMapConfigNoESQL): FormBasedPersistedState['layers'] { const columns = fromMetricAPItoLensState(layer.metric); const layers: Record = generateLayer(DEFAULT_LAYER_ID, layer); @@ -165,7 +165,7 @@ function buildFormBasedLayer(layer: RegionMapStateNoESQL): FormBasedPersistedSta return layers; } -function getValueColumns(layer: RegionMapStateESQL) { +function getValueColumns(layer: RegionMapConfigESQL) { return [ getValueColumn(getAccessorName('metric'), layer.metric, 'number'), getValueColumn(getAccessorName('region'), layer.region), @@ -182,10 +182,10 @@ type RegionMapAttributesWithoutFiltersAndQuery = Omit - buildFormBasedLayer(cfg as RegionMapStateNoESQL); + buildFormBasedLayer(cfg as RegionMapConfigNoESQL); const { layers, usedDataviews } = buildDatasourceStates(config, _buildDataLayer, getValueColumns); @@ -214,7 +214,7 @@ export function fromAPItoLensState( export function fromLensStateToAPI( config: LensAttributes -): Extract { +): Extract { const { state } = config; const visualization = state.visualization as ChoroplethChartState; const layers = getDatasourceLayers(state); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/tagcloud.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/tagcloud.ts index e409974b2680e..90c58d7a35a7f 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/tagcloud.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/tagcloud.ts @@ -19,12 +19,12 @@ import { LENS_TAGCLOUD_DEFAULT_STATE, TAGCLOUD_ORIENTATION } from '@kbn/lens-com import type { DataViewSpec } from '@kbn/data-views-plugin/common'; import type { SavedObjectReference } from '@kbn/core/types'; import type { - LensApiState, - TagcloudState, + LensApiConfig, + TagcloudConfig, LensApiAllMetricOrFormulaOperations, LensApiBucketOperations, - TagcloudStateESQL, - TagcloudStateNoESQL, + TagcloudConfigESQL, + TagcloudConfigNoESQL, } from '../../schema'; import type { LensAttributes } from '../../types'; import { DEFAULT_LAYER_ID } from '../../constants'; @@ -60,7 +60,7 @@ function getAccessorName(type: 'metric' | 'tag') { return `${ACCESSOR}_${type}`; } -function buildVisualizationState(config: TagcloudState): LensTagCloudState { +function buildVisualizationState(config: TagcloudConfig): LensTagCloudState { const layer = config; return { @@ -87,7 +87,7 @@ function getTagcloudDataset( references: SavedObjectReference[], adhocReferences: SavedObjectReference[] = [], layerId: string -): TagcloudState['data_source'] { +): TagcloudConfig['data_source'] { const dataSource = buildDataSourceState( layer, layerId, @@ -106,7 +106,7 @@ function getTagcloudDataset( function getTagcloudMetric( layer: Omit | TextBasedLayer, visualization: LensTagCloudState -): TagcloudState['metric'] { +): TagcloudConfig['metric'] { if (visualization.valueAccessor == null) { throw new Error('Metric accessor is missing in the visualization state'); } @@ -124,7 +124,7 @@ function getTagcloudMetric( function getTagcloudTagBy( layer: Omit | TextBasedLayer, visualization: LensTagCloudState -): TagcloudState['tag_by'] { +): TagcloudConfig['tag_by'] { if (visualization.tagAccessor == null) { throw new Error('Tag accessor is missing in the visualization state'); } @@ -148,7 +148,7 @@ function reverseBuildVisualizationState( adHocDataViews: Record, references: SavedObjectReference[], adhocReferences?: SavedObjectReference[] -): TagcloudState { +): TagcloudConfig { const dataSource = getTagcloudDataset( layer, adHocDataViews, @@ -178,10 +178,10 @@ function reverseBuildVisualizationState( }, caption: { visible: visualization.showLabel }, }), - } as TagcloudState; + } as TagcloudConfig; } -function buildFormBasedLayer(layer: TagcloudStateNoESQL): FormBasedPersistedState['layers'] { +function buildFormBasedLayer(layer: TagcloudConfigNoESQL): FormBasedPersistedState['layers'] { const columns = fromMetricAPItoLensState(layer.metric); const layers: Record = generateLayer(DEFAULT_LAYER_ID, layer); @@ -197,7 +197,7 @@ function buildFormBasedLayer(layer: TagcloudStateNoESQL): FormBasedPersistedStat return layers; } -function getValueColumns(layer: TagcloudStateESQL) { +function getValueColumns(layer: TagcloudConfigESQL) { return [ getValueColumn(getAccessorName('metric'), layer.metric, 'number'), getValueColumn(getAccessorName('tag'), layer.tag_by), @@ -214,10 +214,10 @@ type TagcloudAttributesWithoutFiltersAndQuery = Omit - buildFormBasedLayer(cfg as TagcloudStateNoESQL); + buildFormBasedLayer(cfg as TagcloudConfigNoESQL); const { layers, usedDataviews } = buildDatasourceStates(config, _buildDataLayer, getValueColumns); @@ -246,7 +246,7 @@ export function fromAPItoLensState( export function fromLensStateToAPI( config: LensAttributes -): Extract { +): Extract { const { state } = config; const visualization = state.visualization as LensTagCloudState; const layers = getDatasourceLayers(state); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/utils.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/utils.ts index f6f5a7539610b..065f4046d0470 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/utils.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/utils.ts @@ -21,7 +21,7 @@ import type { } from '@kbn/lens-common'; import type { LensAttributes } from '../../types'; -import type { LensApiState } from '../../schema'; +import type { LensApiConfig } from '../../schema'; import type { legendTruncateAfterLinesSchema } from '../../schema/shared'; import { buildReferences, getAdhocDataviews, isTextBasedLayer, nonNullable } from '../utils'; import { LENS_LAYER_SUFFIX } from '../constants'; @@ -31,7 +31,7 @@ import type { XScaleSchemaType } from '../../schema/charts/shared'; export function getSharedChartLensStateToAPI( config: Pick -): Pick { +): Pick { return { // @TODO: need to make this optional in LensDocument type title: config.title ?? '', diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy.ts index a40c0ee088260..dec067fb33b3d 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy.ts @@ -9,7 +9,7 @@ import type { TypedLensSerializedState, XYPersistedState } from '@kbn/lens-common'; import type { SavedObjectReference } from '@kbn/core/server'; -import type { XYState } from '../../schema'; +import type { XYConfig } from '../../schema'; import { getSharedChartLensStateToAPI, getSharedChartAPIToLensState, @@ -29,7 +29,7 @@ type XYLensWithoutQueryAndFilters = Omit & { state: Omit & { visualization: XYPersistedState }; }; -export function fromAPItoLensState(config: XYState): XYLensWithoutQueryAndFilters { +export function fromAPItoLensState(config: XYConfig): XYLensWithoutQueryAndFilters { // convert layers and produce references from them const { layers, usedDataviews } = buildDatasourceStates( config, @@ -78,7 +78,7 @@ export function fromAPItoLensState(config: XYState): XYLensWithoutQueryAndFilter }; } -export function fromLensStateToAPI(config: LensAttributes): XYState { +export function fromLensStateToAPI(config: LensAttributes): XYConfig { const { state } = config; const visualizationState = state.visualization as XYPersistedState; const layers = getDatasourceLayers(state); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/appearances.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/appearances.test.ts index 1801b8094c563..66d683c487af9 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/appearances.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/appearances.test.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { type XYStyling } from '../../../schema/charts/xy'; +import type { XYConfig } from '../../../schema/charts/xy'; import { convertStylingToAPIFormat, convertStylingToStateFormat, @@ -27,7 +27,7 @@ const allLayersPresent: LayerPresence = { hasBars: true, hasLines: true, hasArea describe('XY Appearances Transforms', () => { it('should return empty state when given empty API config', () => { - const apiConfig: XYStyling = {}; + const apiConfig: XYConfig['styling'] = {}; const result = convertStylingToStateFormat(apiConfig); expect(result).toEqual({}); }); @@ -168,7 +168,7 @@ describe('XY Appearances Transforms', () => { }); it('should preserve complex config through API -> State -> API', () => { - const original: XYStyling = { + const original: XYConfig['styling'] = { overlays: { partial_buckets: { visible: true }, current_time_marker: { visible: true }, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/appearances.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/appearances.ts index 01551756f5717..4efed404021cb 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/appearances.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/appearances.ts @@ -10,7 +10,7 @@ import type { XYVisualizationState as XYVisualizationState } from '@kbn/lens-common'; import type { XYCurveType, FittingFunction, EndValue } from '@kbn/expression-xy-plugin/common'; import type { $Values } from 'utility-types'; -import type { XYStyling } from '../../../schema/charts/xy'; +import type { XYConfig } from '../../../schema/charts/xy'; import type { XYApiLineInterpolation } from '../../../schema/charts/xy'; import { getReversibleMappings, stripUndefined } from '../utils'; import { @@ -23,6 +23,7 @@ import { DEFAULT_POINTS_VISIBILITY, } from './defaults'; +type XYStyling = NonNullable; type XYLensAppearanceState = Pick< XYVisualizationState, | 'valueLabels' diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/chart.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/chart.ts index c819a4d5cff79..3b0428e8bf396 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/chart.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/chart.ts @@ -10,7 +10,7 @@ import type { AxisExtentConfig, YScaleType } from '@kbn/expression-xy-plugin/common'; import type { SavedObjectReference } from '@kbn/core/server'; import type { XYPersistedState, XYDataLayerConfig } from '@kbn/lens-common'; -import type { XYState, XYStateNoESQL, XYStateESQL, XYLayer } from '../../../schema'; +import type { XYConfig, XYConfigNoESQL, XYConfigESQL, XYLayer } from '../../../schema'; import type { DataSourceStateLayer } from '../../utils'; import { convertLegendToAPIFormat, convertLegendToStateFormat } from './legend'; import { buildXYLayer } from './state_layers'; @@ -73,7 +73,7 @@ function convertAPIDomainToStateFormat( } function convertAxisSettingsToStateFormat( - axis: XYState['axis'] + axis: XYConfig['axis'] ): Pick< XYPersistedState, | 'xTitle' @@ -171,7 +171,7 @@ function getLayerPresence(dataLayers: XYDataLayerConfig[]): LayerPresence { type LayerToDataView = Record; export function buildVisualizationState( - config: XYState, + config: XYConfig, usedDataViews: LayerToDataView, annotationGroupReferences: SavedObjectReference[] ): XYPersistedState { @@ -195,11 +195,11 @@ export function buildVisualizationState( }; } -function areAllLayersEsql(apiLayers: XYLayer[]): apiLayers is XYStateESQL['layers'] { +function areAllLayersEsql(apiLayers: XYLayer[]): apiLayers is XYConfigESQL['layers'] { return apiLayers.length > 0 && apiLayers.every(isAPIesqlXYLayer); } -function areAllLayersNoEsql(apiLayers: XYLayer[]): apiLayers is XYStateNoESQL['layers'] { +function areAllLayersNoEsql(apiLayers: XYLayer[]): apiLayers is XYConfigNoESQL['layers'] { return apiLayers.length > 0 && apiLayers.every((l) => !isAPIesqlXYLayer(l)); } @@ -209,7 +209,7 @@ export function buildVisualizationAPI( adHocDataViews: Record, references: SavedObjectReference[], internalReferences: SavedObjectReference[] -): XYState { +): XYConfig { const dataLayers = config.layers.filter(isLensStateDataLayer); if (!dataLayers.length) { throw new Error('At least one data layer is required to build the XY API state'); @@ -362,7 +362,7 @@ function convertAxisSettingsToAPIFormat( config: XYPersistedState, layers: Record, usedModes: Set -): NonNullable { +): NonNullable { let xAxisScale: XScaleSchemaType | undefined; const firstLayer = config.layers[0]; const dataSourceLayer = layers[firstLayer.layerId]; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/legend.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/legend.test.ts index 24e0e1d2e19b4..34a929b312c65 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/legend.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/legend.test.ts @@ -7,12 +7,12 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { XYState } from '../../../schema'; +import type { XYConfig } from '../../../schema'; import { convertLegendToAPIFormat, convertLegendToStateFormat } from './legend'; import type { XYVisualizationState } from '@kbn/lens-common'; describe('XY Legend Transforms', () => { - type ApiLegend = NonNullable; + type ApiLegend = NonNullable; type StateLegend = XYVisualizationState['legend']; const roundTripLegend = (stateLegend: StateLegend) => { diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/legend.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/legend.ts index 1bd840a7f2b98..c4251febc49d0 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/legend.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/legend.ts @@ -9,7 +9,7 @@ import { LegendLayout, type XYLegendValue } from '@kbn/chart-expressions-common'; import type { XYVisualizationState } from '@kbn/lens-common'; -import type { XYState } from '../../../schema'; +import type { XYConfig } from '../../../schema'; import { legendSizeCompat } from '../legend_sizes'; import { getReversibleMappings, stripUndefined } from '../utils'; import type { @@ -45,7 +45,7 @@ const legendStatisticCompat = getReversibleMappings | {} { +): Pick | {} { const visibility = !legend.isVisible ? 'hidden' : legend.showSingleSeries ? 'auto' : 'visible'; const statistics = legend.legendStats?.length ? legend.legendStats.map((stat) => legendStatisticCompat.toAPI(stat)) diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/state_layers.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/state_layers.ts index 0148a71378e8c..67f15d4c8bbd2 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/state_layers.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/state_layers.ts @@ -24,7 +24,7 @@ import type { DataLayerType, ReferenceLineLayerType, AnnotationLayerByValueType, - XYState, + XYConfig, } from '../../../schema/charts/xy'; import { addLayerColumn, generateLayer } from '../../utils'; import { @@ -78,7 +78,7 @@ export function getValueColumns( ]; } -function buildDataLayer(config: XYState, layer: DataLayerType, i: number): XYDataLayerConfig { +function buildDataLayer(config: XYConfig, layer: DataLayerType, i: number): XYDataLayerConfig { const seriesTypeLabel = ( layer.type.includes('percentage') ? `${layer.type}_stacked` : layer.type ) as SeriesType; @@ -219,7 +219,7 @@ function buildReferenceLineLayer( } export function buildXYLayer( - config: XYState, + config: XYConfig, layer: unknown, i: number, dataViewId: string, diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/types.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/types.ts index 57306de91b9b7..4f6d3aa00ffbe 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/types.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/xy/types.ts @@ -7,9 +7,9 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { XYState } from '../../../schema'; +import type { XYConfig } from '../../../schema'; -type Legend = NonNullable; +type Legend = NonNullable; type StripLegendInternals = Omit; diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.test.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.test.ts index 8e0b0e1a3f3fc..f6ad66f89f8a3 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.test.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.test.ts @@ -28,7 +28,7 @@ import type { } from '@kbn/lens-common'; import type { TextBasedLayer } from '@kbn/lens-common'; import { AS_CODE_DATA_VIEW_SPEC_TYPE } from '@kbn/as-code-data-views-schema'; -import type { LensApiState, MetricState } from '../schema'; +import type { LensApiConfig, MetricConfig } from '../schema'; import type { AggregateQuery, Filter, Query } from '@kbn/es-query'; import type { LensAttributes } from '../types'; @@ -460,7 +460,7 @@ describe('generateLayer', () => { type: 'metric', sampling: 0.5, ignore_global_filters: true, - } as MetricState; + } as MetricConfig; const result = generateLayer('layer_1', options); @@ -479,7 +479,7 @@ describe('generateLayer', () => { test('generates layer with default values', () => { const options = { type: 'metric', - } as MetricState; + } as MetricConfig; const result = generateLayer('layer_0', options); @@ -498,7 +498,7 @@ describe('generateLayer', () => { describe('filtersAndQueryToLensState', () => { test('converts API filters and query to Lens state format', () => { - const apiState: LensApiState = { + const apiState: LensApiConfig = { type: 'metric', title: 'test metric', data_source: { @@ -551,7 +551,7 @@ describe('filtersAndQueryToLensState', () => { }); test('handles missing filters and query gracefully', () => { - const apiState: LensApiState = { + const apiState: LensApiConfig = { type: 'metric', title: 'test metric', data_source: { @@ -583,7 +583,7 @@ describe('filtersAndQueryToLensState', () => { }); test('extracts filter data view references when applicable', () => { - const apiState: LensApiState = { + const apiState: LensApiConfig = { type: 'metric', title: 'test metric', data_source: { diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.ts index b15fffa1cce8e..a7429d8dbbfaa 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/utils.ts @@ -33,7 +33,7 @@ import { } from '@kbn/as-code-data-views-schema'; import type { AsCodeDataViewReference } from '@kbn/as-code-data-views-schema'; import type { LensAttributes } from '../types'; -import type { LensApiAllOperations, LensApiState, NarrowByType } from '../schema'; +import type { LensApiAllOperations, LensApiConfig, NarrowByType } from '../schema'; import { fromBucketLensStateToAPI } from './columns/buckets'; import { getMetricApiColumnFromLensState } from './columns/metric'; import type { AnyLensStateColumn, APIAdHocDataView, APIDataView } from './columns/types'; @@ -119,7 +119,7 @@ export function isFormBasedLayer( } export function isTextBasedLayer( - layer: LensApiState | DataSourceStateLayer + layer: LensApiConfig | DataSourceStateLayer ): layer is TextBasedLayer { return 'index' in layer && 'query' in layer; } @@ -329,7 +329,7 @@ function buildDatasourceStatesLayer( i: number, xAxisScale?: XScaleSchemaType ) => TextBasedLayerColumn[], // ValueBasedLayerColumn[] - fullConfig: LensApiState + fullConfig: LensApiConfig ): [LensDatasourceId, DataSourceStateLayer | undefined] { function buildESQLLayer( config: unknown, @@ -354,7 +354,7 @@ function buildDatasourceStatesLayer( } /** - * Builds lens config datasource states from LensApiState + * Builds lens config datasource states from LensApiConfig * * @param config lens api state * @param dataviews list to which dataviews are added @@ -365,7 +365,7 @@ function buildDatasourceStatesLayer( * */ export const buildDatasourceStates = ( - config: LensApiState, + config: LensApiConfig, buildDataLayers: ( config: unknown, i: number, @@ -619,7 +619,7 @@ export const filtersAndQueryToApiFormat = ( }; }; -function extraQueryFromAPIState(state: LensApiState): { esql: string } | Query | undefined { +function extraQueryFromAPIState(state: LensApiConfig): { esql: string } | Query | undefined { if ('data_source' in state && state.data_source.type === 'esql') { return { esql: state.data_source.query }; } @@ -643,7 +643,7 @@ function extraQueryFromAPIState(state: LensApiState): { esql: string } | Query | } export const filtersAndQueryToLensState = ( - state: LensApiState, + state: LensApiConfig, references: SavedObjectReference[] ) => { const query = extraQueryFromAPIState(state); diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/utils.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/utils.ts index 129ff089f6666..fe8bc92ff3ed3 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/utils.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/utils.ts @@ -37,7 +37,7 @@ import type { LensDataviewDataset, LensESQLDataset, } from './types'; -import type { LensApiState, LensApiStateESQL, LensApiStateNoESQL } from './schema'; +import type { LensApiConfig, LensApiConfigESQL, LensApiConfigNoESQL } from './schema'; import type { DataSourceType } from './schema/data_source'; type DataSourceStateLayer = @@ -350,7 +350,7 @@ export function isDataViewDataset(dataset: LensDataset): dataset is LensDataview return 'index' in dataset; } -export function isLensAPIFormat(config: unknown): config is LensApiState { +export function isLensAPIFormat(config: unknown): config is LensApiConfig { return typeof config === 'object' && config !== null && 'type' in config; } @@ -376,7 +376,7 @@ export function groupIsNotCollapsed(def: { return def.collapse_by == null; } -export function isLensESQLConfig(config: LensApiState): config is LensApiStateESQL { +export function isLensESQLConfig(config: LensApiConfig): config is LensApiConfigESQL { if (config.type === 'xy') return config.layers.some( (layer) => 'data_source' in layer && layer.data_source?.type === 'esql' @@ -384,6 +384,6 @@ export function isLensESQLConfig(config: LensApiState): config is LensApiStateES return config.data_source?.type === 'esql'; } -export function isLensDSLConfig(config: LensApiState): config is LensApiStateNoESQL { +export function isLensDSLConfig(config: LensApiConfig): config is LensApiConfigNoESQL { return !isLensESQLConfig(config); } diff --git a/src/platform/packages/shared/kbn-lens-embeddable-utils/index.ts b/src/platform/packages/shared/kbn-lens-embeddable-utils/index.ts index f13816c2141cd..1c40407138119 100644 --- a/src/platform/packages/shared/kbn-lens-embeddable-utils/index.ts +++ b/src/platform/packages/shared/kbn-lens-embeddable-utils/index.ts @@ -7,38 +7,6 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -export { LensConfigBuilder } from './config_builder'; -export type { - DataViewsCommon, - LensAttributes, - ChartType, - TimeRange, - LensLayerQuery, - LensDataviewDataset, - LensDatatableDataset, - LensESQLDataset, - LensDataset, - LensBaseConfig, - LensConfig, - LensConfigOptions, - LensReferenceLineLayer, - LensAnnotationLayer, - LensGaugeConfig, - LensHeatmapConfig, - LensMetricConfig, - LensMosaicConfig, - LensPieConfig, - LensRegionMapConfig, - LensTableConfig, - LensTagCloudConfig, - LensTreeMapConfig, - LensXYConfig, - LensSeriesLayer, - LensBaseLayer, - LensXYConfigBase, - LensBreakdownConfig, -} from './config_builder'; -export { isLensESQLConfig, isLensDSLConfig } from './config_builder/utils'; +export * from './config_builder'; -export { lensApiStateSchema, lensApiStateSchemaNoESQL } from './config_builder'; -export type { LensApiSchemaType } from './config_builder'; +export { stripUndefined } from './config_builder/transforms/charts/utils'; diff --git a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_chart_layers.ts b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_chart_layers.ts index ef0a391afa231..5a2c5992e368c 100644 --- a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_chart_layers.ts +++ b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_chart_layers.ts @@ -8,7 +8,7 @@ */ import { useMemo } from 'react'; -import type { LensSeriesLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensSeriesLayer } from '@kbn/lens-embeddable-utils'; import type { Dimension, ParsedMetricItem } from '../../../types'; import { createMetricAggregation, diff --git a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_lens_props.test.ts b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_lens_props.test.ts index f8d86df7fc391..2cfcbf1fb3943 100644 --- a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_lens_props.test.ts +++ b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_lens_props.test.ts @@ -11,8 +11,7 @@ import { renderHook, act, waitFor } from '@testing-library/react'; import React from 'react'; import { useLensProps } from './use_lens_props'; import { useChartLayers } from './use_chart_layers'; -import type { LensSeriesLayer } from '@kbn/lens-embeddable-utils/config_builder'; -import { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder'; +import { LensConfigBuilder, type LensSeriesLayer } from '@kbn/lens-embeddable-utils'; import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks'; import type { UnifiedHistogramServices } from '@kbn/unified-histogram'; import { getFetchParamsMock, getFetch$Mock } from '@kbn/unified-histogram/__mocks__/fetch_params'; @@ -20,7 +19,7 @@ import type { TimeRange } from '@kbn/data-plugin/common'; import type { UnifiedHistogramFetch$ } from '@kbn/unified-histogram/types'; jest.mock('./use_chart_layers'); -jest.mock('@kbn/lens-embeddable-utils/config_builder'); +jest.mock('@kbn/lens-embeddable-utils'); const LensConfigBuilderMock = LensConfigBuilder as jest.MockedClass; const useChartLayersMock = useChartLayers as jest.MockedFunction; diff --git a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_lens_props.ts b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_lens_props.ts index bb6f41ff19161..3e6f1fd51eddf 100644 --- a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_lens_props.ts +++ b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/hooks/use_lens_props.ts @@ -7,8 +7,14 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { LensAttributes, LensConfig } from '@kbn/lens-embeddable-utils/config_builder'; -import { LensConfigBuilder, type LensSeriesLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import { + LensConfigBuilder, + type LensAttributes, + type LensConfig, + type LensESQLDataset, + type LensSeriesLayer, + type LensYBoundsConfig, +} from '@kbn/lens-embeddable-utils'; import { useCallback, useEffect, useRef, useState } from 'react'; import type { EmbeddableComponentProps } from '@kbn/lens-plugin/public'; import useLatest from 'react-use/lib/useLatest'; @@ -28,10 +34,6 @@ import { } from 'rxjs'; import type { TimeRange } from '@kbn/data-plugin/common'; import { useEuiTheme } from '@elastic/eui'; -import type { - LensYBoundsConfig, - LensESQLDataset, -} from '@kbn/lens-embeddable-utils/config_builder/types'; import type { UnifiedMetricsGridProps } from '../../../types'; export type LensProps = Pick< diff --git a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/index.tsx b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/index.tsx index bf0c522ab53cf..18aca9e539225 100644 --- a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/index.tsx +++ b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/chart/index.tsx @@ -9,10 +9,9 @@ import { EuiFlexGroup, EuiFlexItem, EuiLoadingChart, useEuiTheme } from '@elastic/eui'; import { css } from '@emotion/react'; -import type { LensSeriesLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensSeriesLayer, LensYBoundsConfig } from '@kbn/lens-embeddable-utils'; import { useBoolean } from '@kbn/react-hooks'; import React, { useRef } from 'react'; -import type { LensYBoundsConfig } from '@kbn/lens-embeddable-utils/config_builder/types'; import type { EmbeddableComponentProps } from '@kbn/lens-plugin/public'; import { useLensProps } from './hooks/use_lens_props'; import type { LensWrapperProps } from './lens_wrapper'; diff --git a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/traces/error_rate.tsx b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/traces/error_rate.tsx index ccf6f8a50ff2d..5699c21497795 100644 --- a/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/traces/error_rate.tsx +++ b/src/platform/packages/shared/kbn-unified-chart-section-viewer/src/components/observability/traces/error_rate.tsx @@ -8,8 +8,7 @@ */ import React, { useMemo } from 'react'; -import type { LensSeriesLayer } from '@kbn/lens-embeddable-utils/config_builder'; -import type { LensYBoundsConfig } from '@kbn/lens-embeddable-utils/config_builder/types'; +import type { LensYBoundsConfig, LensSeriesLayer } from '@kbn/lens-embeddable-utils'; import { useTraceMetricsContext } from './context/trace_metrics_context'; import { Chart } from '../../chart'; import { ACTION_OPEN_IN_DISCOVER } from '../../../common/constants'; diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_app/hooks/use_observability_ai_assistant_context.tsx b/src/platform/plugins/shared/dashboard/public/dashboard_app/hooks/use_observability_ai_assistant_context.tsx index 7d1bfbbbd8bb6..d70ff1338b879 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_app/hooks/use_observability_ai_assistant_context.tsx +++ b/src/platform/plugins/shared/dashboard/public/dashboard_app/hooks/use_observability_ai_assistant_context.tsx @@ -8,10 +8,10 @@ */ import { getESQLQueryColumns } from '@kbn/esql-utils'; -import type { LensDataset } from '@kbn/lens-embeddable-utils/config_builder'; import { LensConfigBuilder, type LensConfig, + type LensDataset, type LensGaugeConfig, type LensHeatmapConfig, type LensMetricConfig, @@ -22,7 +22,7 @@ import { type LensTagCloudConfig, type LensTreeMapConfig, type LensXYConfig, -} from '@kbn/lens-embeddable-utils/config_builder'; +} from '@kbn/lens-embeddable-utils'; import type { LensEmbeddableInput } from '@kbn/lens-plugin/public'; import { useEffect } from 'react'; import { LENS_EMBEDDABLE_TYPE } from '@kbn/lens-common'; diff --git a/src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/similar_errors_occurrences_chart/index.tsx b/src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/similar_errors_occurrences_chart/index.tsx index d42b278699d24..3fb7831036594 100644 --- a/src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/similar_errors_occurrences_chart/index.tsx +++ b/src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/similar_errors_occurrences_chart/index.tsx @@ -12,11 +12,11 @@ import { i18n } from '@kbn/i18n'; import { from, stats, sort } from '@kbn/esql-composer'; import { LensConfigBuilder, - type LensXYConfig, - type LensSeriesLayer, type LensAnnotationLayer, -} from '@kbn/lens-embeddable-utils/config_builder'; -import type { LensAttributes } from '@kbn/lens-embeddable-utils/config_builder'; + type LensAttributes, + type LensSeriesLayer, + type LensXYConfig, +} from '@kbn/lens-embeddable-utils'; import { EuiCallOut, EuiLoadingChart, EuiFlexGroup, EuiFlexItem, useEuiTheme } from '@elastic/eui'; import { EmbeddableRenderer } from '@kbn/embeddable-plugin/public'; import { fieldConstants } from '@kbn/discover-utils'; diff --git a/src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/similar_errors_occurrences_chart/similar_errors_occurrences_chart.test.tsx b/src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/similar_errors_occurrences_chart/similar_errors_occurrences_chart.test.tsx index 614cf7b096ab7..7fcc0745d1e34 100644 --- a/src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/similar_errors_occurrences_chart/similar_errors_occurrences_chart.test.tsx +++ b/src/platform/plugins/shared/unified_doc_viewer/public/components/doc_viewer_logs_overview/sub_components/similar_errors/similar_errors_occurrences_chart/similar_errors_occurrences_chart.test.tsx @@ -14,7 +14,7 @@ import { where } from '@kbn/esql-composer'; import { setUnifiedDocViewerServices } from '../../../../../plugin'; import { mockUnifiedDocViewerServices } from '../../../../../__mocks__'; import { merge } from 'lodash'; -import { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder'; +import { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; const mockUseDataSourcesContext = jest.fn(() => ({ indexes: { logs: 'logs-*', apm: {} }, @@ -65,7 +65,7 @@ setUnifiedDocViewerServices( }) ); -jest.mock('@kbn/lens-embeddable-utils/config_builder', () => { +jest.mock('@kbn/lens-embeddable-utils', () => { return { LensConfigBuilder: jest.fn().mockImplementation(() => ({ build: mockBuild, diff --git a/x-pack/examples/lens_config_builder_example/public/app.tsx b/x-pack/examples/lens_config_builder_example/public/app.tsx index 1922a5caed5dc..6fb3f21082868 100644 --- a/x-pack/examples/lens_config_builder_example/public/app.tsx +++ b/x-pack/examples/lens_config_builder_example/public/app.tsx @@ -23,13 +23,13 @@ import type { CoreStart } from '@kbn/core/public'; import type { LensEmbeddableInput } from '@kbn/lens-plugin/public'; import type { ActionExecutionContext } from '@kbn/ui-actions-plugin/public'; -import { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder'; +import { + LensConfigBuilder, + lensApiConfigSchema, + type LensApiConfig, +} from '@kbn/lens-embeddable-utils'; import type { DataViewsContract } from '@kbn/data-views-plugin/public'; import type { TypedLensByValueInput } from '@kbn/lens-plugin/public'; -import { - type LensApiState, - lensApiStateSchema, -} from '@kbn/lens-embeddable-utils/config_builder/schema'; import type { StartDependencies } from './plugin'; export const App = (props: { @@ -47,7 +47,7 @@ export const App = (props: { props.plugins.data.search.session.start() ); - const [lensConfig, setLensConfig] = useState({ + const [lensConfig, setLensConfig] = useState({ type: 'metric', title: 'Total Sales', data_source: { @@ -69,7 +69,7 @@ export const App = (props: { }, ignore_global_filters: true, sampling: 1, - } satisfies LensApiState); + } satisfies LensApiConfig); const [lensConfigString, setLensConfigString] = useState(JSON.stringify(lensConfig)); const LensComponent = props.plugins.lens.EmbeddableComponent; @@ -80,7 +80,7 @@ export const App = (props: { const configBuilder = new LensConfigBuilder(props.dataViews); // eslint-disable-next-line no-console console.log('lensConfig', lensConfig); - const validatedConfig = lensApiStateSchema.validate(lensConfig); + const validatedConfig = lensApiConfigSchema.validate(lensConfig); // eslint-disable-next-line no-console console.log('validatedConfig', validatedConfig); const lensState = configBuilder.fromAPIFormat(validatedConfig); diff --git a/x-pack/examples/lens_embeddable_inline_editing_example/public/app.tsx b/x-pack/examples/lens_embeddable_inline_editing_example/public/app.tsx index 9e09d08a23a06..e9235d2f84a93 100644 --- a/x-pack/examples/lens_embeddable_inline_editing_example/public/app.tsx +++ b/x-pack/examples/lens_embeddable_inline_editing_example/public/app.tsx @@ -21,7 +21,7 @@ import { EuiTitle, } from '@elastic/eui'; import type { CoreStart } from '@kbn/core/public'; -import { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder/config_builder'; +import { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; import type { DataView } from '@kbn/data-views-plugin/public'; import type { LensPublicStart } from '@kbn/lens-plugin/public'; import type { StartDependencies } from './plugin'; diff --git a/x-pack/examples/lens_embeddable_inline_editing_example/public/embeddable.tsx b/x-pack/examples/lens_embeddable_inline_editing_example/public/embeddable.tsx index 9d90a3586063d..433470dca2046 100644 --- a/x-pack/examples/lens_embeddable_inline_editing_example/public/embeddable.tsx +++ b/x-pack/examples/lens_embeddable_inline_editing_example/public/embeddable.tsx @@ -21,7 +21,7 @@ import { EuiButtonIcon, EuiTitle, } from '@elastic/eui'; -import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder/config_builder'; +import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; import type { StartDependencies } from './plugin'; import { getConfigOptions } from './utils'; diff --git a/x-pack/examples/lens_embeddable_inline_editing_example/public/utils.ts b/x-pack/examples/lens_embeddable_inline_editing_example/public/utils.ts index f0069a543d368..e1113f04a2f98 100644 --- a/x-pack/examples/lens_embeddable_inline_editing_example/public/utils.ts +++ b/x-pack/examples/lens_embeddable_inline_editing_example/public/utils.ts @@ -5,10 +5,7 @@ * 2.0. */ import type { DataView } from '@kbn/data-views-plugin/public'; -import type { - LensConfig, - LensConfigOptions, -} from '@kbn/lens-embeddable-utils/config_builder/types'; +import type { LensConfig, LensConfigOptions } from '@kbn/lens-embeddable-utils'; export const getConfigOptions = (dataView: DataView, isESQL?: boolean) => { const index = dataView.getIndexPattern(); diff --git a/x-pack/platform/packages/shared/agent-builder/agent-builder-genai-utils/tools/visualization/chart_type_registry.ts b/x-pack/platform/packages/shared/agent-builder/agent-builder-genai-utils/tools/visualization/chart_type_registry.ts index 2d9d4d2980544..d6c85860fa1e7 100644 --- a/x-pack/platform/packages/shared/agent-builder/agent-builder-genai-utils/tools/visualization/chart_type_registry.ts +++ b/x-pack/platform/packages/shared/agent-builder/agent-builder-genai-utils/tools/visualization/chart_type_registry.ts @@ -6,17 +6,19 @@ */ import { SupportedChartType } from '@kbn/agent-builder-common/tools/tool_result'; -import { esqlMetricState } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/metric'; -import { gaugeStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/gauge'; -import { tagcloudStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/tagcloud'; -import { xyStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/xy'; -import { regionMapStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/region_map'; -import { heatmapStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/heatmap'; -import { datatableStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/datatable'; -import { pieStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/pie'; -import { treemapStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/treemap'; -import { waffleStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/waffle'; -import { mosaicStateSchemaESQL } from '@kbn/lens-embeddable-utils/config_builder/schema/charts/mosaic'; +import { + metricConfigSchemaESQL, + gaugeConfigSchemaESQL, + tagcloudConfigSchemaESQL, + xyConfigSchemaESQL, + regionMapConfigSchemaESQL, + heatmapConfigSchemaESQL, + datatableConfigSchemaESQL, + pieConfigSchemaESQL, + treemapConfigSchemaESQL, + waffleConfigSchemaESQL, + mosaicConfigSchemaESQL, +} from '@kbn/lens-embeddable-utils'; interface ChartTypeRegistryEntry { schema: { validate: (config: unknown) => any; getSchema: () => any }; @@ -37,7 +39,7 @@ interface ChartTypeRegistryEntry { */ export const chartTypeRegistry: Record = { [SupportedChartType.Metric]: { - schema: esqlMetricState, + schema: metricConfigSchemaESQL, guidance: { description: 'For displaying single numeric values, KPIs, or metrics with optional trend lines. Best for showing key performance indicators, counts, sums, averages, or other aggregate statistics.', @@ -46,7 +48,7 @@ export const chartTypeRegistry: Record +const toLensApiConfig = (attributes: LensAttributes): LensApiConfig => new LensConfigBuilder().toAPIFormat(attributes); const extractChartType = (attributes: LensAttributes): string => { diff --git a/x-pack/platform/plugins/shared/agent_builder_platform/server/sml_types/visualization.test.ts b/x-pack/platform/plugins/shared/agent_builder_platform/server/sml_types/visualization.test.ts index 6bddacb253075..ff74345262d12 100644 --- a/x-pack/platform/plugins/shared/agent_builder_platform/server/sml_types/visualization.test.ts +++ b/x-pack/platform/plugins/shared/agent_builder_platform/server/sml_types/visualization.test.ts @@ -9,7 +9,7 @@ import { loggingSystemMock } from '@kbn/core-logging-server-mocks'; import type { SmlListItem } from '@kbn/agent-builder-plugin/server'; import { visualizationSmlType } from './visualization'; -jest.mock('@kbn/lens-embeddable-utils/config_builder', () => ({ +jest.mock('@kbn/lens-embeddable-utils', () => ({ LensConfigBuilder: jest.fn().mockImplementation(() => ({ toAPIFormat: jest.fn().mockReturnValue({ type: 'lnsXY', layers: [] }), })), @@ -372,7 +372,7 @@ describe('visualizationSmlType', () => { }); it('uses LensConfigBuilder to convert attributes', async () => { - const { LensConfigBuilder } = jest.requireMock('@kbn/lens-embeddable-utils/config_builder'); + const { LensConfigBuilder } = jest.requireMock('@kbn/lens-embeddable-utils'); const toAPIFormatMock = jest.fn().mockReturnValue({ type: 'lnsPie', layers: [{ id: 'layer1' }], diff --git a/x-pack/platform/plugins/shared/agent_builder_platform/server/sml_types/visualization.ts b/x-pack/platform/plugins/shared/agent_builder_platform/server/sml_types/visualization.ts index e5b525abe4365..20f822a4005de 100644 --- a/x-pack/platform/plugins/shared/agent_builder_platform/server/sml_types/visualization.ts +++ b/x-pack/platform/plugins/shared/agent_builder_platform/server/sml_types/visualization.ts @@ -6,11 +6,11 @@ */ import type { SmlTypeDefinition } from '@kbn/agent-builder-plugin/server'; -import type { LensAttributes } from '@kbn/lens-embeddable-utils/config_builder'; import { LensConfigBuilder, - type LensApiSchemaType, -} from '@kbn/lens-embeddable-utils/config_builder'; + type LensApiConfig, + type LensAttributes, +} from '@kbn/lens-embeddable-utils'; const VISUALIZATION_SML_TYPE = 'visualization'; @@ -43,7 +43,7 @@ const toLensAttributes = ( references: references ?? attributes.references ?? [], }); -const toLensApiConfig = (attributes: LensAttributes): LensApiSchemaType => +const toLensApiConfig = (attributes: LensAttributes): LensApiConfig => new LensConfigBuilder().toAPIFormat(attributes); export const visualizationSmlType: SmlTypeDefinition = { diff --git a/x-pack/platform/plugins/shared/cases/public/components/markdown_editor/plugins/lens/plugin.tsx b/x-pack/platform/plugins/shared/cases/public/components/markdown_editor/plugins/lens/plugin.tsx index 7997cf90221bf..e8325132ced6b 100644 --- a/x-pack/platform/plugins/shared/cases/public/components/markdown_editor/plugins/lens/plugin.tsx +++ b/x-pack/platform/plugins/shared/cases/public/components/markdown_editor/plugins/lens/plugin.tsx @@ -31,8 +31,7 @@ import type { EmbeddablePackageState } from '@kbn/embeddable-plugin/public'; import { SavedObjectFinder } from '@kbn/saved-objects-finder-plugin/public'; import type { SavedObjectCommon } from '@kbn/saved-objects-finder-plugin/common'; import type { TimeRange } from '@kbn/data-plugin/common'; -import { isLensAPIFormat } from '@kbn/lens-embeddable-utils/config_builder/utils'; -import { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; +import { isLensAPIFormat, LensConfigBuilder } from '@kbn/lens-embeddable-utils'; import { useKibana } from '../../../../common/lib/kibana'; import { DRAFT_COMMENT_STORAGE_ID, ID } from './constants'; import { CommentEditorContext } from '../../context'; diff --git a/x-pack/platform/plugins/shared/lens/common/transforms/helpers.ts b/x-pack/platform/plugins/shared/lens/common/transforms/helpers.ts index f28b0216be759..a40bc761f168f 100644 --- a/x-pack/platform/plugins/shared/lens/common/transforms/helpers.ts +++ b/x-pack/platform/plugins/shared/lens/common/transforms/helpers.ts @@ -8,7 +8,7 @@ import type { SerializedDrilldowns } from '@kbn/embeddable-plugin/server'; import type { SerializedTitles } from '@kbn/presentation-publishing'; import type { LensSerializedState } from '@kbn/lens-common'; -import { stripUndefined } from '@kbn/lens-embeddable-utils/config_builder/transforms/charts/utils'; +import { stripUndefined } from '@kbn/lens-embeddable-utils'; /** * Keys that should be persisted at the panel level. diff --git a/x-pack/platform/plugins/shared/lens/common/transforms/transform_in.ts b/x-pack/platform/plugins/shared/lens/common/transforms/transform_in.ts index 7bfbea5c541fc..23911775d1d28 100644 --- a/x-pack/platform/plugins/shared/lens/common/transforms/transform_in.ts +++ b/x-pack/platform/plugins/shared/lens/common/transforms/transform_in.ts @@ -8,8 +8,8 @@ import { isLensAPIFormat, isLensLegacyFormat, -} from '@kbn/lens-embeddable-utils/config_builder/utils'; -import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; + type LensConfigBuilder, +} from '@kbn/lens-embeddable-utils'; import type { DrilldownTransforms } from '@kbn/embeddable-plugin/common'; import { DOC_TYPE } from '../constants'; import { extractLensReferences } from '../references'; diff --git a/x-pack/platform/plugins/shared/lens/public/lazy_builder.ts b/x-pack/platform/plugins/shared/lens/public/lazy_builder.ts index 4ebe8a53591b7..9e02591e7a56c 100644 --- a/x-pack/platform/plugins/shared/lens/public/lazy_builder.ts +++ b/x-pack/platform/plugins/shared/lens/public/lazy_builder.ts @@ -7,7 +7,7 @@ import type { Class } from 'utility-types'; -import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; import { createGetterSetter } from '@kbn/kibana-utils-plugin/public'; import { getLensFeatureFlags } from './get_feature_flags'; diff --git a/x-pack/platform/plugins/shared/lens/public/persistence/lens_client.ts b/x-pack/platform/plugins/shared/lens/public/persistence/lens_client.ts index f81545642ecbf..d35f4f00eb304 100644 --- a/x-pack/platform/plugins/shared/lens/public/persistence/lens_client.ts +++ b/x-pack/platform/plugins/shared/lens/public/persistence/lens_client.ts @@ -8,8 +8,7 @@ import type { HttpStart } from '@kbn/core/public'; import { buildPath } from '@kbn/core-http-browser'; import type { Reference } from '@kbn/content-management-utils'; -import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder'; -import type { LensApiState } from '@kbn/lens-embeddable-utils/config_builder/schema'; +import type { LensApiConfig, LensConfigBuilder } from '@kbn/lens-embeddable-utils'; import type { LensSavedObjectAttributes } from '@kbn/lens-common'; import { LENS_INTERNAL_VIS_API_PATH, LENS_INTERNAL_API_VERSION } from '../../common/constants'; @@ -66,7 +65,7 @@ export class LensClient { const chartType = this.builder?.getType(data); if (this.builder?.isEnabled && this.builder?.isSupported(chartType)) { - const config = data as LensApiState; + const config = data as LensApiConfig; return { item: { ...this.builder.fromAPIFormat(config), @@ -130,7 +129,7 @@ export class LensClient { ); if (useApiFormat && this.builder) { - const config = data as LensApiState; + const config = data as LensApiConfig; return { item: { ...rest, @@ -195,7 +194,7 @@ export class LensClient { ); if (useApiFormat && this.builder) { - const config = data as LensApiState; + const config = data as LensApiConfig; return { item: { ...rest, @@ -255,7 +254,7 @@ export class LensClient { const chartType = this.builder?.getType(data); if (this.builder?.isEnabled && this.builder?.isSupported(chartType)) { - const config = data as LensApiState; + const config = data as LensApiConfig; return { id, ...this.builder.fromAPIFormat(config), diff --git a/x-pack/platform/plugins/shared/lens/public/react_embeddable/helper.ts b/x-pack/platform/plugins/shared/lens/public/react_embeddable/helper.ts index 07a1c044a644d..31498f1ef245e 100644 --- a/x-pack/platform/plugins/shared/lens/public/react_embeddable/helper.ts +++ b/x-pack/platform/plugins/shared/lens/public/react_embeddable/helper.ts @@ -38,7 +38,7 @@ import { isObject } from 'lodash'; import { BehaviorSubject } from 'rxjs'; import { LENS_ITEM_LATEST_VERSION } from '@kbn/lens-common/content_management/constants'; -import { isLensAPIFormat } from '@kbn/lens-embeddable-utils/config_builder/utils'; +import { isLensAPIFormat } from '@kbn/lens-embeddable-utils'; import type { StrippedLensState } from '../../common/transforms/helpers'; import { isFlattenedAPIConfig, unflattenAPIConfig } from '../../common/transforms/utils'; diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/common.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/common.ts index 431ae88ce8060..2706ecb114999 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/common.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/common.ts @@ -6,7 +6,7 @@ */ import { schema } from '@kbn/config-schema'; -import { lensApiStateSchema } from '@kbn/lens-embeddable-utils'; +import { lensApiConfigSchema } from '@kbn/lens-embeddable-utils'; import { lensCommonSavedObjectSchemaV2, lensItemDataSchemaV2, @@ -38,7 +38,7 @@ export const lensItemMetaSchema = schema.object( export const lensResponseItemSchema = schema.object( { id: lensSavedObjectSchemaV2.getPropSchemas().id, - data: schema.oneOf([lensApiStateSchema, lensItemDataSchemaV2]), + data: schema.oneOf([lensApiConfigSchema, lensItemDataSchemaV2]), meta: lensItemMetaSchema, }, { unknowns: 'forbid', meta: { id: 'visualizationResponse' } } diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/create.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/create.ts index c95f5e38138d8..4a5c7cafacf20 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/create.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/create.ts @@ -6,7 +6,7 @@ */ import { schema } from '@kbn/config-schema'; -import { lensApiStateSchema } from '@kbn/lens-embeddable-utils/config_builder'; +import { lensApiConfigSchema } from '@kbn/lens-embeddable-utils'; import { lensCMCreateOptionsSchema, lensItemDataSchemaV2 } from '../../../../../content_management'; import { lensItemDataSchemaV0 } from '../../../../../content_management/v0'; @@ -22,7 +22,7 @@ export const lensCreateRequestQuerySchema = schema.object( ); export const lensCreateRequestBodySchema = schema.oneOf([ - lensApiStateSchema, + lensApiConfigSchema, lensItemDataSchemaV2, lensItemDataSchemaV1, lensItemDataSchemaV0, // Temporarily permit passing old v0 SO attributes on create diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/update.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/update.ts index 32f5eaf4f433b..f1b299c18ccb0 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/update.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/schema/update.ts @@ -8,7 +8,7 @@ import { omit } from 'lodash'; import { schema } from '@kbn/config-schema'; -import { lensApiStateSchema } from '@kbn/lens-embeddable-utils/config_builder'; +import { lensApiConfigSchema } from '@kbn/lens-embeddable-utils'; import { lensCMUpdateOptionsSchema, lensItemDataSchemaV2 } from '../../../../../content_management'; import { lensItemDataSchemaV0 } from '../../../../../content_management/v0'; @@ -34,7 +34,7 @@ export const lensUpdateRequestQuerySchema = schema.object( ); export const lensUpdateRequestBodySchema = schema.oneOf([ - lensApiStateSchema, + lensApiConfigSchema, lensItemDataSchemaV2, lensItemDataSchemaV1, lensItemDataSchemaV0, // Temporarily permit passing old v0 SO attributes on create diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/update.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/update.ts index b663425c820a3..787b9205efefa 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/update.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/update.ts @@ -7,7 +7,7 @@ import { boomify, isBoom } from '@hapi/boom'; -import { isLensLegacyAttributes } from '@kbn/lens-embeddable-utils/config_builder/utils'; +import { isLensLegacyAttributes } from '@kbn/lens-embeddable-utils'; import { LENS_CONTENT_TYPE } from '@kbn/lens-common/content_management/constants'; import { LENS_INTERNAL_VIS_API_PATH, diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/utils.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/utils.ts index 123d10cbfdf85..45012022f6523 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/utils.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/internal/visualizations/utils.ts @@ -6,7 +6,7 @@ */ import { LENS_UNKNOWN_VIS } from '@kbn/lens-common'; -import type { LensConfigBuilder, LensApiSchemaType } from '@kbn/lens-embeddable-utils'; +import type { LensConfigBuilder, LensApiConfig } from '@kbn/lens-embeddable-utils'; import type { LensSavedObject, LensUpdateIn } from '../../../../content_management'; import type { @@ -27,7 +27,7 @@ export function getLensInternalRequestConfig( const useApiFormat = builder.isEnabled && builder.isSupported(chartType); if (useApiFormat) { - const config = request as LensApiSchemaType; + const config = request as LensApiConfig; const attributes = builder.fromAPIFormat(config); return { diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/common.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/common.ts index c13c4867beeaa..daca9d289894f 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/common.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/common.ts @@ -6,7 +6,7 @@ */ import { schema } from '@kbn/config-schema'; -import { lensApiStateSchemaNoESQL } from '@kbn/lens-embeddable-utils'; +import { lensApiConfigSchemaNoESQL } from '@kbn/lens-embeddable-utils'; import { asCodeMetaSchema } from '@kbn/as-code-shared-schemas'; import { lensCommonSavedObjectSchemaV2 } from '../../../../content_management'; @@ -19,7 +19,7 @@ const savedObjectProps = lensCommonSavedObjectSchemaV2.getPropSchemas(); export const lensResponseItemSchema = schema.object( { id: savedObjectProps.id, - data: lensApiStateSchemaNoESQL, + data: lensApiConfigSchemaNoESQL, meta: asCodeMetaSchema, }, { unknowns: 'forbid', meta: { id: 'lensResponseItem', title: 'Visualization Response' } } diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/create.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/create.ts index 7fc1f58cbd74b..5022241276652 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/create.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/create.ts @@ -6,7 +6,7 @@ */ import { schema } from '@kbn/config-schema'; -import { lensApiStateSchemaNoESQL } from '@kbn/lens-embeddable-utils/config_builder'; +import { lensApiConfigSchemaNoESQL } from '@kbn/lens-embeddable-utils'; import { lensCMCreateOptionsSchema } from '../../../../content_management'; import { pickFromObjectSchema } from '../../../../utils'; @@ -19,6 +19,6 @@ export const lensCreateRequestQuerySchema = schema.object( { unknowns: 'forbid' } ); -export const lensCreateRequestBodySchema = lensApiStateSchemaNoESQL; +export const lensCreateRequestBodySchema = lensApiConfigSchemaNoESQL; export const lensCreateResponseBodySchema = lensResponseItemSchema; diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/update.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/update.ts index 88b00c88c4066..f5306879074ff 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/update.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/schema/update.ts @@ -6,7 +6,7 @@ */ import { schema } from '@kbn/config-schema'; -import { lensApiStateSchemaNoESQL } from '@kbn/lens-embeddable-utils/config_builder'; +import { lensApiConfigSchemaNoESQL } from '@kbn/lens-embeddable-utils'; import { lensResponseItemSchema } from './common'; @@ -21,6 +21,6 @@ export const lensUpdateRequestParamsSchema = schema.object( { unknowns: 'forbid' } ); -export const lensUpdateRequestBodySchema = lensApiStateSchemaNoESQL; +export const lensUpdateRequestBodySchema = lensApiConfigSchemaNoESQL; export const lensUpdateResponseBodySchema = lensResponseItemSchema; diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/search.test.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/search.test.ts index d8046bd3fcb22..2cf49e1b3240c 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/search.test.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/search.test.ts @@ -9,7 +9,7 @@ import type { Logger, RequestHandlerContext } from '@kbn/core/server'; import { httpServerMock } from '@kbn/core/server/mocks'; import type { VersionedRouter } from '@kbn/core-http-server'; import type { ContentManagementServerSetup } from '@kbn/content-management-plugin/server'; -import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; import { registerLensVisualizationsSearchAPIRoute } from './search'; import { LENS_VIS_API_PATH, LENS_API_VERSION } from '../../../../common/constants'; diff --git a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/update.ts b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/update.ts index 41903a3c4f173..80967321bfc67 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/update.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/update.ts @@ -7,7 +7,7 @@ import { boomify, isBoom } from '@hapi/boom'; -import { isLensLegacyAttributes } from '@kbn/lens-embeddable-utils/config_builder/utils'; +import { isLensLegacyAttributes } from '@kbn/lens-embeddable-utils'; import { LENS_CONTENT_TYPE } from '@kbn/lens-common/content_management/constants'; import { diff --git a/x-pack/platform/plugins/shared/lens/server/api/types.ts b/x-pack/platform/plugins/shared/lens/server/api/types.ts index 7d92a6cbc4d1f..ec130e53c3cc9 100644 --- a/x-pack/platform/plugins/shared/lens/server/api/types.ts +++ b/x-pack/platform/plugins/shared/lens/server/api/types.ts @@ -8,7 +8,7 @@ import type { HttpServiceSetup, Logger, RequestHandlerContext } from '@kbn/core/server'; import type { ContentManagementServerSetup } from '@kbn/content-management-plugin/server'; import type { VersionedRouter } from '@kbn/core-http-server'; -import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; export type * from './routes/types'; diff --git a/x-pack/platform/plugins/shared/lens/server/plugin.tsx b/x-pack/platform/plugins/shared/lens/server/plugin.tsx index 72df9ca39dee3..d44ec6940d3ec 100644 --- a/x-pack/platform/plugins/shared/lens/server/plugin.tsx +++ b/x-pack/platform/plugins/shared/lens/server/plugin.tsx @@ -29,7 +29,7 @@ import type { import type { EmbeddableRegistryDefinition, EmbeddableSetup } from '@kbn/embeddable-plugin/server'; import { DataViewPersistableStateService } from '@kbn/data-views-plugin/common'; import type { SharePluginSetup } from '@kbn/share-plugin/server'; -import { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder'; +import { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; import { LENS_CONTENT_TYPE, LENS_ITEM_LATEST_VERSION, diff --git a/x-pack/platform/plugins/shared/lens/server/transforms.ts b/x-pack/platform/plugins/shared/lens/server/transforms.ts index 62f542fbd5c4b..9345ddd649d37 100644 --- a/x-pack/platform/plugins/shared/lens/server/transforms.ts +++ b/x-pack/platform/plugins/shared/lens/server/transforms.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { type LensConfigBuilder } from '@kbn/lens-embeddable-utils'; +import { extendLensApiConfigSchema, type LensConfigBuilder } from '@kbn/lens-embeddable-utils'; import type { LensByRefSerializedAPIConfig } from '@kbn/lens-common-2'; import { schema } from '@kbn/config-schema'; @@ -24,7 +24,6 @@ import { } from '@kbn/ui-actions-plugin/common/trigger_ids'; import { BY_REF_SCHEMA_META, BY_VALUE_SCHEMA_META } from '@kbn/presentation-publishing-schemas'; import { LENS_EMBEDDABLE_TYPE } from '@kbn/lens-common'; -import { extendLensApiStateSchema } from '@kbn/lens-embeddable-utils/config_builder/schema'; import { getTransformIn } from '../common/transforms/transform_in'; import { getTransformOut } from '../common/transforms/transform_out'; import type { LensTransforms } from '../common/transforms/types'; @@ -83,7 +82,7 @@ const getSharedPanelSchema = (getDrilldownsSchema: GetDrilldownsSchemaFnType) => }); export const getLensByValuePanelSchema = (getDrilldownsSchema: GetDrilldownsSchemaFnType) => - extendLensApiStateSchema(getSharedPanelSchema(getDrilldownsSchema), { + extendLensApiConfigSchema(getSharedPanelSchema(getDrilldownsSchema), { meta: BY_VALUE_SCHEMA_META, }); diff --git a/x-pack/solutions/observability/plugins/infra/public/components/asset_details/charts/chart.tsx b/x-pack/solutions/observability/plugins/infra/public/components/asset_details/charts/chart.tsx index 1e4b54078aa82..5ee03ea266e1b 100644 --- a/x-pack/solutions/observability/plugins/infra/public/components/asset_details/charts/chart.tsx +++ b/x-pack/solutions/observability/plugins/infra/public/components/asset_details/charts/chart.tsx @@ -5,7 +5,7 @@ * 2.0. */ import React, { useCallback } from 'react'; -import type { LensConfig } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensConfig } from '@kbn/lens-embeddable-utils'; import type { TimeRange } from '@kbn/es-query'; import useAsync from 'react-use/lib/useAsync'; import type { DataView } from '@kbn/data-views-plugin/public'; diff --git a/x-pack/solutions/observability/plugins/infra/public/components/asset_details/components/kpis/kpi.tsx b/x-pack/solutions/observability/plugins/infra/public/components/asset_details/components/kpis/kpi.tsx index 6143133b561e5..9a64f4a5a8bd3 100644 --- a/x-pack/solutions/observability/plugins/infra/public/components/asset_details/components/kpis/kpi.tsx +++ b/x-pack/solutions/observability/plugins/infra/public/components/asset_details/components/kpis/kpi.tsx @@ -6,7 +6,7 @@ */ import React, { useMemo } from 'react'; import type { Filter, Query, TimeRange } from '@kbn/es-query'; -import type { LensConfig } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensConfig } from '@kbn/lens-embeddable-utils'; import { METRICS_TOOLTIP, KPI_CHART_HEIGHT } from '../../../../common/visualizations'; import { LensChart, TooltipContent } from '../../../lens'; diff --git a/x-pack/solutions/observability/plugins/infra/public/components/lens/types.ts b/x-pack/solutions/observability/plugins/infra/public/components/lens/types.ts index d024b3bb5503b..8432949e88e47 100644 --- a/x-pack/solutions/observability/plugins/infra/public/components/lens/types.ts +++ b/x-pack/solutions/observability/plugins/infra/public/components/lens/types.ts @@ -6,7 +6,7 @@ */ import type { TimeRange } from '@kbn/es-query'; -import type { LensAttributes } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensAttributes } from '@kbn/lens-embeddable-utils'; import type { LensEmbeddableInput, TypedLensByValueInput } from '@kbn/lens-plugin/public'; import type { Action } from '@kbn/ui-actions-plugin/public'; diff --git a/x-pack/solutions/observability/plugins/infra/public/hooks/use_lens_attributes.test.ts b/x-pack/solutions/observability/plugins/infra/public/hooks/use_lens_attributes.test.ts index 6eb42a98d5a8b..e80a81aa85e63 100644 --- a/x-pack/solutions/observability/plugins/infra/public/hooks/use_lens_attributes.test.ts +++ b/x-pack/solutions/observability/plugins/infra/public/hooks/use_lens_attributes.test.ts @@ -15,14 +15,12 @@ import type { InfraClientStartDeps } from '../types'; import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks'; import { lensPluginMock } from '@kbn/lens-plugin/public/mocks'; import { FilterStateStore } from '@kbn/es-query'; -import type { LensBaseLayer, LensConfig } from '@kbn/lens-embeddable-utils/config_builder'; - -import { LensConfigBuilder } from '@kbn/lens-embeddable-utils/config_builder'; +import { LensConfigBuilder, type LensBaseLayer, type LensConfig } from '@kbn/lens-embeddable-utils'; jest.mock('@kbn/kibana-react-plugin/public'); const useKibanaMock = useKibana as jest.MockedFunction; -jest.mock('@kbn/lens-embeddable-utils/config_builder'); +jest.mock('@kbn/lens-embeddable-utils'); const LensConfigBuilderMock = LensConfigBuilder as jest.MockedClass; const normalizedLoad1m: LensBaseLayer = { diff --git a/x-pack/solutions/observability/plugins/infra/public/hooks/use_lens_attributes.ts b/x-pack/solutions/observability/plugins/infra/public/hooks/use_lens_attributes.ts index 7291ff6f3704e..8cabaf7343510 100644 --- a/x-pack/solutions/observability/plugins/infra/public/hooks/use_lens_attributes.ts +++ b/x-pack/solutions/observability/plugins/infra/public/hooks/use_lens_attributes.ts @@ -14,7 +14,7 @@ import { type LensAttributes, type LensConfig, LensConfigBuilder, -} from '@kbn/lens-embeddable-utils/config_builder'; +} from '@kbn/lens-embeddable-utils'; import { useKibanaContextForPlugin } from './use_kibana'; diff --git a/x-pack/solutions/observability/plugins/infra/public/pages/metrics/hosts/components/tabs/metrics/chart.tsx b/x-pack/solutions/observability/plugins/infra/public/pages/metrics/hosts/components/tabs/metrics/chart.tsx index 22874c3c8467d..8ec7a5609a952 100644 --- a/x-pack/solutions/observability/plugins/infra/public/pages/metrics/hosts/components/tabs/metrics/chart.tsx +++ b/x-pack/solutions/observability/plugins/infra/public/pages/metrics/hosts/components/tabs/metrics/chart.tsx @@ -5,7 +5,7 @@ * 2.0. */ import React from 'react'; -import type { LensConfig } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensConfig } from '@kbn/lens-embeddable-utils'; import type { DataView } from '@kbn/data-views-plugin/public'; import useAsync from 'react-use/lib/useAsync'; import { EuiPanel } from '@elastic/eui'; diff --git a/x-pack/solutions/observability/plugins/infra/public/pages/metrics/hosts/hooks/use_metrics_charts.test.ts b/x-pack/solutions/observability/plugins/infra/public/pages/metrics/hosts/hooks/use_metrics_charts.test.ts index 13feec5791096..582df441be897 100644 --- a/x-pack/solutions/observability/plugins/infra/public/pages/metrics/hosts/hooks/use_metrics_charts.test.ts +++ b/x-pack/solutions/observability/plugins/infra/public/pages/metrics/hosts/hooks/use_metrics_charts.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { LensSeriesLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensSeriesLayer } from '@kbn/lens-embeddable-utils'; import { waitFor, renderHook } from '@testing-library/react'; import { PAGE_SIZE_OPTIONS } from '../constants'; import { useMetricsCharts } from './use_metrics_charts'; diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/cpu.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/cpu.ts index 283f139d31a7a..4886caa79357c 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/cpu.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/cpu.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; import { CPU_USAGE_LABEL } from '../../../shared/charts/constants'; export const dockerContainerCpuUsage: LensBaseLayer = { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/disk.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/disk.ts index ba0050bad97aa..9acfafa94b2bf 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/disk.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/disk.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; import { DISK_READ_IOPS_LABEL, DISK_WRITE_IOPS_LABEL } from '../../../shared/charts/constants'; export const dockerContainerDiskIORead: LensBaseLayer = { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/memory.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/memory.ts index 827f06e4fdb0d..eac3b55b43da3 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/memory.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/memory.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; import { MEMORY_USAGE_LABEL } from '../../../shared/charts/constants'; export const dockerContainerMemoryUsage: LensBaseLayer = { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/network.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/network.ts index 6c6600fc6463f..1d1d6408411c0 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/network.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/container/metrics/formulas/network.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; import { RX_LABEL, TX_LABEL } from '../../../shared/charts/constants'; export const dockerContainerNetworkRx: LensBaseLayer = { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/host/metrics/formulas/host_count.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/host/metrics/formulas/host_count.ts index c62b9c9e17a8e..63e6ed493468b 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/host/metrics/formulas/host_count.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/host/metrics/formulas/host_count.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; export const hostCount: LensBaseLayer = { label: i18n.translate('xpack.metricsData.assetDetails.formulas.hostCount.hostsLabel', { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/host/metrics/formulas/log_rate.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/host/metrics/formulas/log_rate.ts index 6947afbc2e262..183be93df2af4 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/host/metrics/formulas/log_rate.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/host/metrics/formulas/log_rate.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; export const logRate: LensBaseLayer = { label: i18n.translate('xpack.metricsData.assetDetails.formulas.logRate', { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/cpu.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/cpu.ts index baa061613128b..d66447394a6d4 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/cpu.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/cpu.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; export const nodeCpuCapacity: LensBaseLayer = { label: i18n.translate('xpack.metricsData.assetDetails.formulas.kubernetes.capacity', { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/disk.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/disk.ts index e518b01556b5d..07a3547225635 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/disk.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/disk.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; export const nodeDiskCapacity: LensBaseLayer = { label: i18n.translate('xpack.metricsData.assetDetails.formulas.kubernetes.capacity', { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/memory.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/memory.ts index 63ad88faef781..64e44bded1e9c 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/memory.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/memory.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; export const nodeMemoryCapacity: LensBaseLayer = { label: i18n.translate('xpack.metricsData.assetDetails.formulas.kubernetes.capacity', { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/pod_capacity.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/pod_capacity.ts index 903df978bd996..801928f6954b2 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/pod_capacity.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/kubernetes/node/metrics/formulas/pod_capacity.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; export const nodePodCapacity: LensBaseLayer = { label: i18n.translate('xpack.metricsData.assetDetails.formulas.kubernetes.capacity', { diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/shared/metrics/metrics_catalog.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/shared/metrics/metrics_catalog.ts index b1d6f9e73530b..81745567e2362 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/shared/metrics/metrics_catalog.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/shared/metrics/metrics_catalog.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensBaseLayer } from '@kbn/lens-embeddable-utils'; import type { DataSchemaFormat } from './types'; import type { AggregationConfig, diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/shared/metrics/types.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/shared/metrics/types.ts index b5576e2a9a964..914d2f89eb961 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/shared/metrics/types.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/shared/metrics/types.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { ChartType, LensBaseLayer } from '@kbn/lens-embeddable-utils/config_builder'; +import type { ChartType, LensBaseLayer } from '@kbn/lens-embeddable-utils'; import type { InventoryTsvbType, LensConfigWithId, diff --git a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/types.ts b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/types.ts index 07119b87bee36..3ec8c4a0cb547 100644 --- a/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/types.ts +++ b/x-pack/solutions/observability/plugins/metrics_data_access/common/inventory_models/types.ts @@ -7,7 +7,7 @@ import * as rt from 'io-ts'; import type { estypes } from '@elastic/elasticsearch'; -import type { LensConfig } from '@kbn/lens-embeddable-utils/config_builder'; +import type { LensConfig } from '@kbn/lens-embeddable-utils'; import type { AggregationConfigMap, ChartsConfigMap, diff --git a/x-pack/solutions/observability/plugins/observability_ai_assistant_app/public/functions/lens.tsx b/x-pack/solutions/observability/plugins/observability_ai_assistant_app/public/functions/lens.tsx index b16c254e29a2f..139c42cb5a8bc 100644 --- a/x-pack/solutions/observability/plugins/observability_ai_assistant_app/public/functions/lens.tsx +++ b/x-pack/solutions/observability/plugins/observability_ai_assistant_app/public/functions/lens.tsx @@ -7,8 +7,7 @@ import { EuiButton, EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner } from '@elastic/eui'; import type { DataViewsServicePublic } from '@kbn/data-views-plugin/public/types'; import { i18n } from '@kbn/i18n'; -import type { LensSeriesLayer } from '@kbn/lens-embeddable-utils'; -import { LensConfigBuilder } from '@kbn/lens-embeddable-utils'; +import { LensConfigBuilder, type LensSeriesLayer } from '@kbn/lens-embeddable-utils'; import type { LensByValueInput, LensPublicStart } from '@kbn/lens-plugin/public'; import React, { useState } from 'react'; import type { AsyncState } from 'react-use/lib/useAsync';