Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifications and fixes #55

Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ test('generates tag cloud chart config', async () => {
"minFontSize": 12,
"orientation": "single",
"showLabel": true,
"tagAccessor": "category",
"valueAccessor": "count",
"tagAccessor": "metric_formula_accessor_breakdown",
"valueAccessor": "metric_formula_accessor",
},
},
"title": "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
buildDatasourceStates,
buildReferences,
getAdhocDataviews,
isFormulaDataset,
mapToFormula,
} from '../utils';
import { getBreakdownColumn, getFormulaColumn, getValueColumn } from '../columns';
Expand All @@ -31,18 +30,17 @@ function getAccessorName(type: 'breakdown') {

function buildVisualizationState(config: LensTagCloudConfig): TagcloudState {
const layer = config;
const isFormula = isFormulaDataset(config.dataset) || isFormulaDataset(layer.dataset);

return {
layerId: DEFAULT_LAYER_ID,
valueAccessor: !isFormula ? layer.value : ACCESSOR,
valueAccessor: ACCESSOR,
maxFontSize: 72,
minFontSize: 12,
orientation: 'single',
showLabel: true,
...(layer.breakdown
? {
tagAccessor: !isFormula ? (layer.breakdown as string) : getAccessorName('breakdown'),
tagAccessor: getAccessorName('breakdown'),
}
: {}),
};
Expand Down
10 changes: 5 additions & 5 deletions packages/kbn-lens-embeddable-utils/config_builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { FormulaPublicApi, TypedLensByValueInput } from '@kbn/lens-plugin/public';
import type { Filter, Query } from '@kbn/es-query';
import type { AggregateQuery, Filter, Query } from '@kbn/es-query';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { Datatable } from '@kbn/expressions-plugin/common';

Expand Down Expand Up @@ -95,7 +95,7 @@ export interface LensConfigOptions {
/** optional time range override */
timeRange?: TimeRange;
filters?: Filter[];
query?: Query;
query?: Query | AggregateQuery;
}

export interface LensAxisTitleVisibilityConfig {
Expand Down Expand Up @@ -208,9 +208,9 @@ export type LensRegionMapConfig = Identity<
export interface LensMosaicConfigBase {
chartType: 'mosaic';
/** field name to apply breakdown based on field type or full breakdown configuration */
breakdown: LensBreakdownConfig;
breakdown: LensBreakdownConfig[];
/** field name to apply breakdown based on field type or full breakdown configuration */
xAxis: LensBreakdownConfig;
xAxis?: LensBreakdownConfig;
}

export type LensMosaicConfig = Identity<LensBaseConfig & LensBaseLayer & LensMosaicConfigBase>;
Expand All @@ -228,7 +228,7 @@ export type LensTableConfig = Identity<LensBaseConfig & LensBaseLayer & LensTabl
export interface LensHeatmapConfigBase {
chartType: 'heatmap';
/** field name to apply breakdown based on field type or full breakdown configuration */
breakdown: LensBreakdownConfig;
breakdown?: LensBreakdownConfig;
xAxis: LensBreakdownConfig;
legend?: Identity<LensLegendConfig>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import type { ObservabilityAIAssistantPublicStart } from '@kbn/observability-ai-assistant-plugin/public';
import { useEffect } from 'react';
import { getESQLAdHocDataview, getIndexPatternFromESQLQuery } from '@kbn/esql-utils';
import type { Embeddable } from '@kbn/embeddable-plugin/public';
import type { ESQLSearchReponse } from '@kbn/es-types';
import { esFieldTypeToKibanaFieldType } from '@kbn/field-types';
Expand Down Expand Up @@ -117,32 +116,6 @@ export function useObservabilityAIAssistantContext({
createScreenContextAction,
} = observabilityAIAssistant;

const axisType = {
type: 'string',
enum: ['dateHistogram', 'topValues', 'filters', 'intervals'],
} as const;

const xAxis = {
type: 'object',
properties: {
column: {
type: 'string',
},
type: axisType,
},
} as const;

const breakdown = {
type: 'object',
properties: {
column: {
type: 'string',
},
type: axisType,
},
required: ['column'],
} as const;

return setScreenContext({
screenDescription:
'The user is looking at the dashboard app. Here they can add visualizations to a dashboard and save them',
Expand Down Expand Up @@ -178,14 +151,11 @@ export function useObservabilityAIAssistantContext({
xy: {
type: 'object',
properties: {
xAxis,
xAxis: {
type: 'string',
},
yAxis: {
type: 'object',
properties: {
column: {
type: 'string',
},
},
type: 'string',
},
type: {
type: 'string',
Expand All @@ -197,10 +167,7 @@ export function useObservabilityAIAssistantContext({
type: 'object',
properties: {
breakdown: {
type: 'object',
properties: {
type: axisType,
},
type: 'string',
},
},
},
Expand All @@ -212,31 +179,39 @@ export function useObservabilityAIAssistantContext({
},
pie: {
type: 'object',
properties: {
breakdown: {
type: 'string',
},
},
},
heatmap: {
type: 'object',
properties: {
timestampField: {
xAxis: {
type: 'string',
},
breakdown: {
type: 'string',
},
breakdown,
},
required: ['breakdown'],
required: ['xAxis'],
},
mosaic: {
type: 'object',
properties: {
timestampField: {
breakdown: {
type: 'string',
},
breakdown,
},
required: ['breakdown'],
},
regionmap: {
type: 'object',
properties: {
breakdown,
breakdown: {
type: 'string',
},
},
required: ['breakdown'],
},
Expand All @@ -246,12 +221,19 @@ export function useObservabilityAIAssistantContext({
tagcloud: {
type: 'object',
properties: {
breakdown,
breakdown: {
type: 'string',
},
},
required: ['breakdown'],
},
treemap: {
type: 'object',
properties: {
breakdown: {
type: 'string',
},
},
},
},
},
Expand All @@ -271,15 +253,12 @@ export function useObservabilityAIAssistantContext({
esql: { query },
} = args;

const indexPattern = getIndexPatternFromESQLQuery(query);

const [columns, adhocDataView] = await Promise.all([
const [columns] = await Promise.all([
getColumns({
search,
esqlQuery: query,
signal,
}),
getESQLAdHocDataview(indexPattern, dataViews),
]);

const configBuilder = new LensConfigBuilder(dataViews);
Expand All @@ -303,10 +282,10 @@ export function useObservabilityAIAssistantContext({
{
seriesType: layers?.xy?.type || 'line',
type: 'series',
xAxis: layers?.xy?.xAxis?.column || '@timestamp',
xAxis: layers?.xy?.xAxis || '@timestamp',
yAxis: [
{
value: layers?.xy?.yAxis?.column || firstMetricColumn!,
value: layers?.xy?.yAxis || firstMetricColumn!,
},
],
},
Expand All @@ -322,12 +301,23 @@ export function useObservabilityAIAssistantContext({
chartType,
title,
value: firstMetricColumn!,
breakdown: [],
breakdown: [layers?.donut?.breakdown!],
dataset,
};
config = donutConfig;
break;

case 'pie':
const pieConfig: LensPieConfig = {
chartType,
title,
value: firstMetricColumn!,
breakdown: [layers?.pie?.breakdown!],
dataset,
};
config = pieConfig;
break;

case 'metric':
const metricConfig: LensMetricConfig = {
chartType,
Expand All @@ -354,15 +344,8 @@ export function useObservabilityAIAssistantContext({
chartType,
title,
value: firstMetricColumn!,
breakdown: {
field: layers?.heatmap?.breakdown?.column!,
type: layers?.heatmap?.breakdown?.type || 'topValues',
filters: [],
},
xAxis: {
field: layers?.heatmap?.timestampField || '@timestamp',
type: 'dateHistogram',
},
breakdown: layers?.heatmap?.breakdown,
xAxis: layers?.heatmap?.xAxis || '@timestamp',
dataset,
};
config = heatmapConfig;
Expand All @@ -373,41 +356,18 @@ export function useObservabilityAIAssistantContext({
chartType,
title,
value: firstMetricColumn!,
xAxis: {
field: layers?.mosaic?.timestampField || '@timestamp',
type: 'dateHistogram',
},
breakdown: {
field: layers?.mosaic?.breakdown.column!,
filters: [],
type: layers?.mosaic?.breakdown.type || 'topValues',
},
breakdown: [layers?.mosaic?.breakdown || '@timestamp'],
dataset,
};
config = mosaicConfig;
break;

case 'pie':
const pieConfig: LensPieConfig = {
chartType,
title,
value: firstMetricColumn!,
breakdown: [],
dataset,
};
config = pieConfig;
break;

case 'regionmap':
const regionMapConfig: LensRegionMapConfig = {
chartType,
title,
value: firstMetricColumn!,
breakdown: {
field: layers?.regionmap?.breakdown.column!,
filters: [],
type: layers?.regionmap?.breakdown.type! || 'topValues',
},
breakdown: layers?.regionmap?.breakdown!,
dataset,
};
config = regionMapConfig;
Expand All @@ -428,11 +388,7 @@ export function useObservabilityAIAssistantContext({
chartType,
title,
value: firstMetricColumn!,
breakdown: {
field: layers?.tagcloud?.breakdown.column!,
filters: [],
type: layers?.tagcloud?.breakdown.type || 'topValues',
},
breakdown: layers?.tagcloud?.breakdown!,
dataset,
};
config = tagCloudConfig;
Expand All @@ -443,7 +399,7 @@ export function useObservabilityAIAssistantContext({
chartType,
title,
value: firstMetricColumn!,
breakdown: [],
breakdown: [layers?.treemap?.breakdown || '@timestamp'],
dataset,
};
config = treeMapConfig;
Expand All @@ -452,6 +408,7 @@ export function useObservabilityAIAssistantContext({

const embeddableInput = (await configBuilder.build(config, {
embeddable: true,
query: dataset,
})) as LensEmbeddableInput;

return dashboardAPI
Expand Down
Loading