Skip to content

Commit 56ccab8

Browse files
authored
[8.19] [Lens][ConfigBuilder] Fix internal reference handling (#239431) (#239799)
# Backport This will backport the following commits from `main` to `8.19`: - [[Lens][ConfigBuilder] Fix internal reference handling (#239431)](#239431) <!--- Backport version: 10.1.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Nick Partridge","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-20T15:01:19Z","message":"[Lens][ConfigBuilder] Fix internal reference handling (#239431)\n\n## Summary\n\nFixes a bug in the `LensConfigBuilder` that treated all dataview\nreferences the same, causing the UI to throw an error attempting to find\nan ad-hoc dataview that does not exist as a SavedObject.\n\nFixes #239430\n\n## Release Notes\n\nFixes a bug in Lens that incorrectly assigned unsaved (ad-hoc) dataview\nreferences.","sha":"ad143b19f8086f1b027d3c6f4d5dbe436264c5a7","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Visualizations","Feature:Lens","backport:all-open","v9.3.0"],"title":"[Lens][ConfigBuilder] Fix internal reference handling","number":239431,"url":"https://github.com/elastic/kibana/pull/239431","mergeCommit":{"message":"[Lens][ConfigBuilder] Fix internal reference handling (#239431)\n\n## Summary\n\nFixes a bug in the `LensConfigBuilder` that treated all dataview\nreferences the same, causing the UI to throw an error attempting to find\nan ad-hoc dataview that does not exist as a SavedObject.\n\nFixes #239430\n\n## Release Notes\n\nFixes a bug in Lens that incorrectly assigned unsaved (ad-hoc) dataview\nreferences.","sha":"ad143b19f8086f1b027d3c6f4d5dbe436264c5a7"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/239431","number":239431,"mergeCommit":{"message":"[Lens][ConfigBuilder] Fix internal reference handling (#239431)\n\n## Summary\n\nFixes a bug in the `LensConfigBuilder` that treated all dataview\nreferences the same, causing the UI to throw an error attempting to find\nan ad-hoc dataview that does not exist as a SavedObject.\n\nFixes #239430\n\n## Release Notes\n\nFixes a bug in Lens that incorrectly assigned unsaved (ad-hoc) dataview\nreferences.","sha":"ad143b19f8086f1b027d3c6f4d5dbe436264c5a7"}}]}] BACKPORT-->
1 parent 3c6125b commit 56ccab8

File tree

21 files changed

+211
-196
lines changed

21 files changed

+211
-196
lines changed

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/gauge.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@ test('generates gauge chart config', async () => {
6868
);
6969
expect(result).toMatchInlineSnapshot(`
7070
Object {
71-
"references": Array [
72-
Object {
73-
"id": "test",
74-
"name": "indexpattern-datasource-layer-layer_0",
75-
"type": "index-pattern",
76-
},
77-
],
71+
"references": Array [],
7872
"state": Object {
7973
"adHocDataViews": Object {
8074
"test": Object {},
@@ -105,7 +99,13 @@ test('generates gauge chart config', async () => {
10599
},
106100
},
107101
"filters": Array [],
108-
"internalReferences": Array [],
102+
"internalReferences": Array [
103+
Object {
104+
"id": "test",
105+
"name": "indexpattern-datasource-layer-layer_0",
106+
"type": "index-pattern",
107+
},
108+
],
109109
"query": Object {
110110
"language": "kuery",
111111
"query": "",
@@ -144,13 +144,7 @@ test('generates gauge chart config with goal and max', async () => {
144144
);
145145
expect(result).toMatchInlineSnapshot(`
146146
Object {
147-
"references": Array [
148-
Object {
149-
"id": "test",
150-
"name": "indexpattern-datasource-layer-layer_0",
151-
"type": "index-pattern",
152-
},
153-
],
147+
"references": Array [],
154148
"state": Object {
155149
"adHocDataViews": Object {
156150
"test": Object {},
@@ -197,7 +191,13 @@ test('generates gauge chart config with goal and max', async () => {
197191
},
198192
},
199193
"filters": Array [],
200-
"internalReferences": Array [],
194+
"internalReferences": Array [
195+
Object {
196+
"id": "test",
197+
"name": "indexpattern-datasource-layer-layer_0",
198+
"type": "index-pattern",
199+
},
200+
],
201201
"query": Object {
202202
"language": "kuery",
203203
"query": "",

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/gauge.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import { BuildDependencies, DEFAULT_LAYER_ID, LensAttributes, LensGaugeConfig }
1717
import {
1818
addLayerFormulaColumns,
1919
buildDatasourceStates,
20-
buildReferences,
21-
getAdhocDataviews,
20+
extractReferences,
2221
mapToFormula,
2322
} from '../utils';
2423
import { getFormulaColumn, getValueColumn } from '../columns';
@@ -138,18 +137,19 @@ export async function buildGauge(
138137
getValueColumns,
139138
dataViewsAPI
140139
);
140+
const { references, internalReferences, adHocDataViews } = extractReferences(dataviews);
141+
141142
return {
142143
title: config.title,
143144
visualizationType: 'lnsGauge',
144-
references: buildReferences(dataviews),
145+
references,
145146
state: {
146147
datasourceStates,
147-
internalReferences: [],
148+
internalReferences,
148149
filters: [],
149150
query: { language: 'kuery', query: '' },
150151
visualization: buildVisualizationState(config),
151-
// Getting the spec from a data view is a heavy operation, that's why the result is cached.
152-
adHocDataViews: getAdhocDataviews(dataviews),
152+
adHocDataViews,
153153
},
154154
};
155155
}

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/heatmap.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,7 @@ test('generates metric chart config', async () => {
7070
);
7171
expect(result).toMatchInlineSnapshot(`
7272
Object {
73-
"references": Array [
74-
Object {
75-
"id": "test",
76-
"name": "indexpattern-datasource-layer-layer_0",
77-
"type": "index-pattern",
78-
},
79-
],
73+
"references": Array [],
8074
"state": Object {
8175
"adHocDataViews": Object {
8276
"test": Object {},
@@ -123,7 +117,13 @@ test('generates metric chart config', async () => {
123117
},
124118
},
125119
"filters": Array [],
126-
"internalReferences": Array [],
120+
"internalReferences": Array [
121+
Object {
122+
"id": "test",
123+
"name": "indexpattern-datasource-layer-layer_0",
124+
"type": "index-pattern",
125+
},
126+
],
127127
"query": Object {
128128
"language": "kuery",
129129
"query": "",

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/heatmap.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@ import type {
1313
HeatmapVisualizationState,
1414
} from '@kbn/lens-plugin/public';
1515
import type { DataView } from '@kbn/data-views-plugin/public';
16-
import { BuildDependencies, DEFAULT_LAYER_ID, LensAttributes, LensHeatmapConfig } from '../types';
17-
import {
18-
addLayerColumn,
19-
buildDatasourceStates,
20-
buildReferences,
21-
getAdhocDataviews,
22-
mapToFormula,
23-
} from '../utils';
16+
import type { BuildDependencies, LensAttributes, LensHeatmapConfig } from '../types';
17+
import { DEFAULT_LAYER_ID } from '../types';
18+
import { addLayerColumn, buildDatasourceStates, extractReferences, mapToFormula } from '../utils';
2419
import { getBreakdownColumn, getFormulaColumn, getValueColumn } from '../columns';
2520

2621
const ACCESSOR = 'metric_formula_accessor';
@@ -123,19 +118,19 @@ export async function buildHeatmap(
123118
getValueColumns,
124119
dataViewsAPI
125120
);
121+
const { references, internalReferences, adHocDataViews } = extractReferences(dataviews);
126122

127123
return {
128124
title: config.title,
129125
visualizationType: 'lnsHeatmap',
130-
references: buildReferences(dataviews),
126+
references,
131127
state: {
132128
datasourceStates,
133-
internalReferences: [],
129+
internalReferences,
134130
filters: [],
135131
query: { language: 'kuery', query: '' },
136132
visualization: buildVisualizationState(config),
137-
// Getting the spec from a data view is a heavy operation, that's why the result is cached.
138-
adHocDataViews: getAdhocDataviews(dataviews),
133+
adHocDataViews,
139134
},
140135
};
141136
}

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/metric.test.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,7 @@ test('generates metric chart config', async () => {
7272
);
7373
expect(result).toMatchInlineSnapshot(`
7474
Object {
75-
"references": Array [
76-
Object {
77-
"id": "test",
78-
"name": "indexpattern-datasource-layer-layer_0",
79-
"type": "index-pattern",
80-
},
81-
],
75+
"references": Array [],
8276
"state": Object {
8377
"adHocDataViews": Object {
8478
"test": Object {},
@@ -115,7 +109,13 @@ test('generates metric chart config', async () => {
115109
},
116110
},
117111
"filters": Array [],
118-
"internalReferences": Array [],
112+
"internalReferences": Array [
113+
Object {
114+
"id": "test",
115+
"name": "indexpattern-datasource-layer-layer_0",
116+
"type": "index-pattern",
117+
},
118+
],
119119
"query": Object {
120120
"language": "kuery",
121121
"query": "",
@@ -191,18 +191,7 @@ test('generates metric chart config with trendline', async () => {
191191

192192
expect(result).toMatchInlineSnapshot(`
193193
Object {
194-
"references": Array [
195-
Object {
196-
"id": undefined,
197-
"name": "indexpattern-datasource-layer-layer_0",
198-
"type": "index-pattern",
199-
},
200-
Object {
201-
"id": undefined,
202-
"name": "indexpattern-datasource-layer-layer_0_trendline",
203-
"type": "index-pattern",
204-
},
205-
],
194+
"references": Array [],
206195
"state": Object {
207196
"adHocDataViews": Object {
208197
"3feeaf26-927e-448e-968f-c7e970671564": Object {},

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/metric.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import {
1919
addLayerColumn,
2020
addLayerFormulaColumns,
2121
buildDatasourceStates,
22-
buildReferences,
23-
getAdhocDataviews,
22+
extractReferences,
2423
mapToFormula,
2524
} from '../utils';
2625
import {
@@ -221,18 +220,19 @@ export async function buildMetric(
221220
getValueColumns,
222221
dataViewsAPI
223222
);
223+
const { references, internalReferences, adHocDataViews } = extractReferences(dataviews);
224+
224225
return {
225226
title: config.title,
226227
visualizationType: 'lnsMetric',
227-
references: buildReferences(dataviews),
228+
references,
228229
state: {
229230
datasourceStates,
230-
internalReferences: [],
231+
internalReferences,
231232
filters: [],
232233
query: { language: 'kuery', query: '' },
233234
visualization: buildVisualizationState(config),
234-
// Getting the spec from a data view is a heavy operation, that's why the result is cached.
235-
adHocDataViews: getAdhocDataviews(dataviews),
235+
adHocDataViews,
236236
},
237237
};
238238
}

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/partition.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ test('generates metric chart config', async () => {
6969
);
7070
expect(result).toMatchInlineSnapshot(`
7171
Object {
72-
"references": Array [
73-
Object {
74-
"id": "test",
75-
"name": "indexpattern-datasource-layer-layer_0",
76-
"type": "index-pattern",
77-
},
78-
],
72+
"references": Array [],
7973
"state": Object {
8074
"adHocDataViews": Object {
8175
"test": Object {},
@@ -122,7 +116,13 @@ test('generates metric chart config', async () => {
122116
},
123117
},
124118
"filters": Array [],
125-
"internalReferences": Array [],
119+
"internalReferences": Array [
120+
Object {
121+
"id": "test",
122+
"name": "indexpattern-datasource-layer-layer_0",
123+
"type": "index-pattern",
124+
},
125+
],
126126
"query": Object {
127127
"language": "kuery",
128128
"query": "",

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/partition.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ import {
2222
LensMosaicConfig,
2323
LensLegendConfig,
2424
} from '../types';
25-
import {
26-
addLayerColumn,
27-
buildDatasourceStates,
28-
buildReferences,
29-
getAdhocDataviews,
30-
mapToFormula,
31-
} from '../utils';
25+
import { addLayerColumn, buildDatasourceStates, extractReferences, mapToFormula } from '../utils';
3226
import { getBreakdownColumn, getFormulaColumn, getValueColumn } from '../columns';
3327

3428
const ACCESSOR = 'metric_formula_accessor';
@@ -127,18 +121,19 @@ export async function buildPartitionChart(
127121
getValueColumns,
128122
dataViewsAPI
129123
);
124+
const { references, internalReferences, adHocDataViews } = extractReferences(dataviews);
125+
130126
return {
131127
title: config.title,
132128
visualizationType: 'lnsPie',
133-
references: buildReferences(dataviews),
129+
references,
134130
state: {
135131
datasourceStates,
136-
internalReferences: [],
132+
internalReferences,
137133
filters: [],
138134
query: { language: 'kuery', query: '' },
139135
visualization: buildVisualizationState(config),
140-
// Getting the spec from a data view is a heavy operation, that's why the result is cached.
141-
adHocDataViews: getAdhocDataviews(dataviews),
136+
adHocDataViews,
142137
},
143138
};
144139
}

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/region_map.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ test('generates region map chart config', async () => {
6969
);
7070
expect(result).toMatchInlineSnapshot(`
7171
Object {
72-
"references": Array [
73-
Object {
74-
"id": "test",
75-
"name": "indexpattern-datasource-layer-layer_0",
76-
"type": "index-pattern",
77-
},
78-
],
72+
"references": Array [],
7973
"state": Object {
8074
"adHocDataViews": Object {
8175
"test": Object {},
@@ -114,7 +108,13 @@ test('generates region map chart config', async () => {
114108
},
115109
},
116110
"filters": Array [],
117-
"internalReferences": Array [],
111+
"internalReferences": Array [
112+
Object {
113+
"id": "test",
114+
"name": "indexpattern-datasource-layer-layer_0",
115+
"type": "index-pattern",
116+
},
117+
],
118118
"query": Object {
119119
"language": "kuery",
120120
"query": "",

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/charts/region_map.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ import {
1717
LensRegionMapConfig,
1818
LensTagCloudConfig,
1919
} from '../types';
20-
import {
21-
addLayerColumn,
22-
buildDatasourceStates,
23-
buildReferences,
24-
getAdhocDataviews,
25-
mapToFormula,
26-
} from '../utils';
20+
import { addLayerColumn, buildDatasourceStates, extractReferences, mapToFormula } from '../utils';
2721
import { getBreakdownColumn, getFormulaColumn, getValueColumn } from '../columns';
2822

2923
const ACCESSOR = 'metric_formula_accessor';
@@ -100,19 +94,19 @@ export async function buildRegionMap(
10094
getValueColumns,
10195
dataViewsAPI
10296
);
97+
const { references, internalReferences, adHocDataViews } = extractReferences(dataviews);
10398

10499
return {
105100
title: config.title,
106101
visualizationType: 'lnsChoropleth',
107-
references: buildReferences(dataviews),
102+
references,
108103
state: {
109104
datasourceStates,
110-
internalReferences: [],
105+
internalReferences,
111106
filters: [],
112107
query: { language: 'kuery', query: '' },
113108
visualization: buildVisualizationState(config),
114-
// Getting the spec from a data view is a heavy operation, that's why the result is cached.
115-
adHocDataViews: getAdhocDataviews(dataviews),
109+
adHocDataViews,
116110
},
117111
};
118112
}

0 commit comments

Comments
 (0)