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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import type { TypeOf } from '@kbn/config-schema';
import { schema } from '@kbn/config-schema';
import { DEFAULT_HEADER_ROW_HEIGHT_LINES, DEFAULT_ROW_HEIGHT_LINES } from '@kbn/lens-common';
import { esqlColumnSchema, genericOperationOptionsSchema } from '../metric_ops';
import { bucketOperationDefinitionSchema } from '../bucket_ops';
import { esqlColumnOperationWithLabelAndFormatSchema, esqlColumnSchema } from '../metric_ops';
import { applyColorToSchema, colorByValueSchema, colorMappingSchema } from '../color';
import { datasetSchema, datasetEsqlTableSchema } from '../dataset';
import {
Expand All @@ -25,6 +24,7 @@ import {
mergeAllBucketsWithChartDimensionSchema,
} from './shared';
import { horizontalAlignmentSchema } from '../alignments';
import { bucketOperationDefinitionSchema } from '../bucket_ops';

/**
* Sorting configuration for the datatable. Only one column can be sorted at a time.
Expand Down Expand Up @@ -154,6 +154,7 @@ const datatableStateSharedOptionsSchema = {
},
{
meta: {
id: 'datatableDensity',
description: 'Density configuration for the datatable',
},
}
Expand Down Expand Up @@ -204,7 +205,7 @@ const datatableStateCommonOptionsSchema = {
),
};

const datatableStateRowsOptionsNoESQLSchema = schema.object({
const datatableStateRowsOptionsNoESQLSchema = {
...datatableStateCommonOptionsSchema,
/**
* Alignment of the rows
Expand Down Expand Up @@ -234,9 +235,10 @@ const datatableStateRowsOptionsNoESQLSchema = schema.object({
* number of columns specified in the columns parameter.
*/
collapse_by: schema.maybe(collapseBySchema),
});
};

const datatableStateRowsOptionsESQLSchema = datatableStateRowsOptionsNoESQLSchema.extends({
const datatableStateRowsOptionsESQLSchema = {
...datatableStateRowsOptionsNoESQLSchema,
/**
* Color configuration
*/
Expand All @@ -248,9 +250,9 @@ const datatableStateRowsOptionsESQLSchema = datatableStateRowsOptionsNoESQLSchem
},
})
),
});
};

const datatableStateMetricsOptionsSchema = schema.object({
const datatableStateMetricsOptionsSchema = {
...datatableStateCommonOptionsSchema,
/**
* Color configuration
Expand Down Expand Up @@ -293,7 +295,7 @@ const datatableStateMetricsOptionsSchema = schema.object({
{ meta: { description: 'Summary row configuration' } }
)
),
});
};

interface SortByValidationInput {
metrics: Array<{}>;
Expand Down Expand Up @@ -399,6 +401,7 @@ export const datatableStateSchemaNoESQL = schema.object(
{
validate: validateSortBy,
meta: {
id: 'datatableNoESQL',
description: 'Datatable state configuration for standard queries',
},
}
Expand All @@ -415,13 +418,9 @@ export const datatableStateSchemaESQL = schema.object(
* Metric columns configuration, must define operation.
*/
metrics: schema.arrayOf(
schema.allOf([
schema.object({
...genericOperationOptionsSchema,
}),
datatableStateMetricsOptionsSchema,
esqlColumnSchema,
]),
esqlColumnOperationWithLabelAndFormatSchema.extends(datatableStateMetricsOptionsSchema, {
meta: { id: 'datatableESQLMetric' },
}),
{
minSize: 1,
maxSize: 1000,
Expand All @@ -432,7 +431,7 @@ export const datatableStateSchemaESQL = schema.object(
* Row configuration, optional operations.
*/
rows: schema.maybe(
schema.arrayOf(schema.allOf([datatableStateRowsOptionsESQLSchema, esqlColumnSchema]), {
schema.arrayOf(esqlColumnSchema.extends(datatableStateRowsOptionsESQLSchema), {
minSize: 1,
maxSize: 50,
meta: { description: 'Array of operations to split the datatable rows by' },
Expand All @@ -452,6 +451,7 @@ export const datatableStateSchemaESQL = schema.object(
{
validate: validateSortBy,
meta: {
id: 'datatableESQL',
description: 'Datatable state configuration for ES|QL queries',
},
}
Expand All @@ -460,7 +460,10 @@ export const datatableStateSchemaESQL = schema.object(
export const datatableStateSchema = schema.oneOf(
[datatableStateSchemaNoESQL, datatableStateSchemaESQL],
{
meta: { description: 'Datatable chart configuration: DSL or ES|QL query based' },
meta: {
description: 'Datatable chart configuration: DSL or ES|QL query based',
id: 'datatableChartSchema',
},
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import type { TypeOf } from '@kbn/config-schema';
import { schema } from '@kbn/config-schema';
import {
esqlColumnOperationWithLabelAndFormatSchema,
esqlColumnSchema,
genericOperationOptionsSchema,
metricOperationDefinitionSchema,
} from '../metric_ops';
import { colorByValueSchema } from '../color';
Expand All @@ -23,19 +23,25 @@ const gaugeStateSharedOptionsSchema = {
shape: schema.maybe(
schema.oneOf(
[
schema.object({
type: schema.literal('bullet'),
direction: schema.oneOf([schema.literal('horizontal'), schema.literal('vertical')], {
defaultValue: 'horizontal',
}),
}),
schema.object({
type: schema.oneOf([
schema.literal('circle'),
schema.literal('semiCircle'),
schema.literal('arc'),
]),
}),
schema.object(
{
type: schema.literal('bullet'),
direction: schema.oneOf([schema.literal('horizontal'), schema.literal('vertical')], {
defaultValue: 'horizontal',
}),
},
{ meta: { id: 'gaugeShapeBullet', description: 'Bullet gauge shape' } }
),
schema.object(
{
type: schema.oneOf([
schema.literal('circle'),
schema.literal('semiCircle'),
schema.literal('arc'),
]),
},
{ meta: { id: 'gaugeShapeCircular', description: 'Circular gauge shape' } }
),
],
{ defaultValue: { type: 'bullet', direction: 'horizontal' } }
)
Expand Down Expand Up @@ -107,44 +113,46 @@ const gaugeStateMetricOptionsSchema = {
),
};

export const gaugeStateSchemaNoESQL = schema.object({
type: schema.literal('gauge'),
...sharedPanelInfoSchema,
...dslOnlyPanelInfoSchema,
...layerSettingsSchema,
...datasetSchema,
...gaugeStateSharedOptionsSchema,
/**
* Primary value configuration, must define operation.
*/
metric: mergeAllMetricsWithChartDimensionSchema(
schema.object({
export const gaugeStateSchemaNoESQL = schema.object(
{
type: schema.literal('gauge'),
...sharedPanelInfoSchema,
...dslOnlyPanelInfoSchema,
...layerSettingsSchema,
...datasetSchema,
...gaugeStateSharedOptionsSchema,
/**
* Primary value configuration, must define operation.
*/
metric: mergeAllMetricsWithChartDimensionSchema({
...gaugeStateMetricOptionsSchema,
...gaugeStateMetricInnerNoESQLOpsSchema,
})
),
});
}),
},
{ meta: { id: 'gaugeNoESQL' } }
);

export const gaugeStateSchemaESQL = schema.object({
type: schema.literal('gauge'),
...sharedPanelInfoSchema,
...layerSettingsSchema,
...datasetEsqlTableSchema,
...gaugeStateSharedOptionsSchema,
/**
* Primary value configuration, must define operation.
*/
metric: schema.allOf([
schema.object({
...genericOperationOptionsSchema,
export const gaugeStateSchemaESQL = schema.object(
{
type: schema.literal('gauge'),
...sharedPanelInfoSchema,
...layerSettingsSchema,
...datasetEsqlTableSchema,
...gaugeStateSharedOptionsSchema,
/**
* Primary value configuration, must define operation.
*/
metric: esqlColumnOperationWithLabelAndFormatSchema.extends({
...gaugeStateMetricOptionsSchema,
...gaugeStateMetricInnerESQLOpsSchema,
}),
esqlColumnSchema,
]),
});
},
{ meta: { id: 'gaugeESQL' } }
);

export const gaugeStateSchema = schema.oneOf([gaugeStateSchemaNoESQL, gaugeStateSchemaESQL]);
export const gaugeStateSchema = schema.oneOf([gaugeStateSchemaNoESQL, gaugeStateSchemaESQL], {
meta: { id: 'gaugeChartSchema' },
});

export type GaugeState = TypeOf<typeof gaugeStateSchema>;
export type GaugeStateNoESQL = TypeOf<typeof gaugeStateSchemaNoESQL>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,17 @@ import {
layerSettingsSchema,
dslOnlyPanelInfoSchema,
axisTitleSchemaProps,
legendTruncateAfterLinesSchema,
} from '../shared';
import { mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps } from './shared';
import { legendSizeSchema, mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps } from './shared';
import { positionSchema } from '../alignments';
import { builderEnums } from '../enums';
import { bucketOperationDefinitionSchema } from '../bucket_ops';

const legendSchemaProps = {
truncate_after_lines: schema.maybe(
schema.number({ meta: { description: 'Number of lines before truncating legend text' } })
),
truncate_after_lines: legendTruncateAfterLinesSchema,
visible: schema.maybe(schema.boolean({ meta: { description: 'Whether to show the legend' } })),
size: schema.maybe(
schema.oneOf(
[
schema.literal('auto'),
schema.literal('small'),
schema.literal('medium'),
schema.literal('large'),
schema.literal('xlarge'),
],
{ defaultValue: 'auto', meta: { description: 'Size of the legend' } }
)
),
size: legendSizeSchema,
position: schema.maybe(positionSchema({ meta: { description: 'Legend position' } })),
};

Expand All @@ -62,27 +50,35 @@ const simpleLabelsSchema = schema.object(omit(labelsSchemaProps, 'orientation'))
const heatmapSharedStateSchema = {
type: schema.literal('heatmap'),
legend: schema.maybe(
schema.object(legendSchemaProps, { meta: { description: 'Legend configuration' } })
schema.object(legendSchemaProps, {
meta: { id: 'heatmapLegend', description: 'Legend configuration' },
})
),
...sharedPanelInfoSchema,
...layerSettingsSchema,
axes: schema.maybe(
schema.object(
{
x: schema.maybe(
schema.object({
title: schema.maybe(schema.object(axisTitleSchemaProps)),
labels: schema.maybe(schema.object(labelsSchemaProps)),
})
schema.object(
{
title: schema.maybe(schema.object(axisTitleSchemaProps)),
labels: schema.maybe(schema.object(labelsSchemaProps)),
},
{ meta: { id: 'heatmapXAxis', description: 'X axis configuration' } }
)
),
y: schema.maybe(
schema.object({
title: schema.maybe(schema.object(axisTitleSchemaProps)),
labels: schema.maybe(simpleLabelsSchema),
})
schema.object(
{
title: schema.maybe(schema.object(axisTitleSchemaProps)),
labels: schema.maybe(simpleLabelsSchema),
},
{ meta: { id: 'heatmapYAxis', description: 'Y axis configuration' } }
)
),
},
{ meta: { description: 'Axis configuration for X and Y axes' } }
{ meta: { id: 'heatmapAxes', description: 'Axis configuration for X and Y axes' } }
)
),
cells: schema.maybe(
Expand All @@ -99,7 +95,7 @@ const heatmapSharedStateSchema = {
})
),
},
{ meta: { description: 'Cells configuration' } }
{ meta: { id: 'heatmapCells', description: 'Cells configuration' } }
)
),
};
Expand All @@ -118,24 +114,32 @@ const heatmapStateMetricOptionsSchemaProps = {
color: schema.maybe(colorByValueSchema),
};

export const heatmapStateSchemaNoESQL = schema.object({
...heatmapSharedStateSchema,
...heatmapAxesStateSchemaProps,
...dslOnlyPanelInfoSchema,
...datasetSchema,
metric: mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps(
schema.object(heatmapStateMetricOptionsSchemaProps)
),
});
export const heatmapStateSchemaNoESQL = schema.object(
{
...heatmapSharedStateSchema,
...heatmapAxesStateSchemaProps,
...dslOnlyPanelInfoSchema,
...datasetSchema,
metric: mergeAllMetricsWithChartDimensionSchemaWithRefBasedOps(
heatmapStateMetricOptionsSchemaProps
),
},
{ meta: { id: 'heatmapNoESQL' } }
);

export const heatmapStateSchemaESQL = schema.object({
...heatmapSharedStateSchema,
...heatmapAxesStateESQLSchemaProps,
...datasetEsqlTableSchema,
metric: schema.allOf([schema.object(heatmapStateMetricOptionsSchemaProps), esqlColumnSchema]),
});
export const heatmapStateSchemaESQL = schema.object(
{
...heatmapSharedStateSchema,
...heatmapAxesStateESQLSchemaProps,
...datasetEsqlTableSchema,
metric: esqlColumnSchema.extends(heatmapStateMetricOptionsSchemaProps),
},
{ meta: { id: 'heatmapESQL' } }
);

export const heatmapStateSchema = schema.oneOf([heatmapStateSchemaNoESQL, heatmapStateSchemaESQL]);
export const heatmapStateSchema = schema.oneOf([heatmapStateSchemaNoESQL, heatmapStateSchemaESQL], {
meta: { id: 'heatmapChartSchema' },
});

export type HeatmapState = TypeOf<typeof heatmapStateSchema>;
export type HeatmapStateNoESQL = TypeOf<typeof heatmapStateSchemaNoESQL>;
Expand Down
Loading
Loading