Skip to content

Commit a854ff8

Browse files
authored
[Lens][Datatable] Fix share export and inspect data (elastic#193780)
The exported table data table provided in the inspector and the share export now match what was visible in the UI.
1 parent c41178d commit a854ff8

File tree

52 files changed

+478
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+478
-280
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ packages/kbn-tinymath @elastic/kibana-visualizations
947947
packages/kbn-tooling-log @elastic/kibana-operations
948948
x-pack/plugins/transform @elastic/ml-ui
949949
x-pack/plugins/translations @elastic/kibana-localization
950+
packages/kbn-transpose-utils @elastic/kibana-visualizations
950951
x-pack/examples/triggers_actions_ui_example @elastic/response-ops
951952
x-pack/plugins/triggers_actions_ui @elastic/response-ops
952953
packages/kbn-triggers-actions-ui-types @elastic/response-ops

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@
948948
"@kbn/tinymath": "link:packages/kbn-tinymath",
949949
"@kbn/transform-plugin": "link:x-pack/plugins/transform",
950950
"@kbn/translations-plugin": "link:x-pack/plugins/translations",
951+
"@kbn/transpose-utils": "link:packages/kbn-transpose-utils",
951952
"@kbn/triggers-actions-ui-example-plugin": "link:x-pack/examples/triggers_actions_ui_example",
952953
"@kbn/triggers-actions-ui-plugin": "link:x-pack/plugins/triggers_actions_ui",
953954
"@kbn/triggers-actions-ui-types": "link:packages/kbn-triggers-actions-ui-types",
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @kbn/transpose-utils
2+
3+
Utility functions used to identify and convert transposed column ids.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { getOriginalId, getTransposeId, isTransposeId } from '.';
11+
12+
describe('transpose utils', () => {
13+
it('should covert value and id to transposed id', () => {
14+
expect(getTransposeId('test', 'column-1')).toBe('test---column-1');
15+
});
16+
17+
it('should know if id is transposed', () => {
18+
const testId = getTransposeId('test', 'column-1');
19+
expect(isTransposeId(testId)).toBe(true);
20+
});
21+
22+
it('should know if id is not transposed', () => {
23+
expect(isTransposeId('test')).toBe(false);
24+
});
25+
26+
it('should return id for transposed id', () => {
27+
const testId = getTransposeId('test', 'column-1');
28+
29+
expect(getOriginalId(testId)).toBe('column-1');
30+
});
31+
32+
it('should return id for non-transposed id', () => {
33+
expect(getOriginalId('test')).toBe('test');
34+
});
35+
});

packages/kbn-transpose-utils/index.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
/**
11+
* Used to delimitate felids of a transposed column id
12+
*/
13+
export const TRANSPOSE_SEPARATOR = '---';
14+
15+
/**
16+
* Visual deliminator between felids of a transposed column id
17+
*
18+
* Meant to align with the `MULTI_FIELD_KEY_SEPARATOR` from the data plugin
19+
*/
20+
export const TRANSPOSE_VISUAL_SEPARATOR = '›';
21+
22+
export function getTransposeId(value: string, columnId: string) {
23+
return `${value}${TRANSPOSE_SEPARATOR}${columnId}`;
24+
}
25+
26+
export function isTransposeId(id: string): boolean {
27+
return id.split(TRANSPOSE_SEPARATOR).length > 1;
28+
}
29+
30+
export function getOriginalId(id: string) {
31+
if (id.includes(TRANSPOSE_SEPARATOR)) {
32+
const idParts = id.split(TRANSPOSE_SEPARATOR);
33+
return idParts[idParts.length - 1];
34+
}
35+
return id;
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
module.exports = {
11+
preset: '@kbn/test',
12+
rootDir: '../..',
13+
roots: ['<rootDir>/packages/kbn-transpose-utils'],
14+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "shared-common",
3+
"id": "@kbn/transpose-utils",
4+
"owner": "@elastic/kibana-visualizations"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@kbn/transpose-utils",
3+
"private": true,
4+
"version": "1.0.0",
5+
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
6+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"outDir": "target/types",
5+
"types": [
6+
"jest",
7+
"node",
8+
"react"
9+
]
10+
},
11+
"include": [
12+
"**/*.ts",
13+
"**/*.tsx",
14+
],
15+
"exclude": [
16+
"target/**/*"
17+
],
18+
"kbn_references": []
19+
}

src/plugins/chart_expressions/expression_gauge/common/types/expression_functions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { $Values } from '@kbn/utility-types';
1111
import type { PaletteOutput, CustomPaletteParams } from '@kbn/coloring';
1212
import {
1313
Datatable,
14+
DefaultInspectorAdapters,
15+
ExecutionContext,
1416
ExpressionFunctionDefinition,
1517
ExpressionValueRender,
1618
} from '@kbn/expressions-plugin/common';
@@ -86,7 +88,8 @@ export type GaugeExpressionFunctionDefinition = ExpressionFunctionDefinition<
8688
typeof EXPRESSION_GAUGE_NAME,
8789
GaugeInput,
8890
GaugeArguments,
89-
ExpressionValueRender<GaugeExpressionProps>
91+
ExpressionValueRender<GaugeExpressionProps>,
92+
ExecutionContext<DefaultInspectorAdapters>
9093
>;
9194

9295
export interface Accessors {

src/plugins/chart_expressions/expression_heatmap/common/types/expression_functions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { Position } from '@elastic/charts';
1111
import type { PaletteOutput } from '@kbn/coloring';
1212
import {
1313
Datatable,
14+
DefaultInspectorAdapters,
15+
ExecutionContext,
1416
ExpressionFunctionDefinition,
1517
ExpressionValueRender,
1618
} from '@kbn/expressions-plugin/common';
@@ -114,7 +116,8 @@ export type HeatmapExpressionFunctionDefinition = ExpressionFunctionDefinition<
114116
typeof EXPRESSION_HEATMAP_NAME,
115117
HeatmapInput,
116118
HeatmapArguments,
117-
ExpressionValueRender<HeatmapExpressionProps>
119+
ExpressionValueRender<HeatmapExpressionProps>,
120+
ExecutionContext<DefaultInspectorAdapters>
118121
>;
119122

120123
export type HeatmapLegendExpressionFunctionDefinition = ExpressionFunctionDefinition<

src/plugins/chart_expressions/expression_heatmap/public/components/helpers.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
DEFAULT_MAX_STOP,
1919
DEFAULT_MIN_STOP,
2020
} from '@kbn/coloring';
21+
import { getOriginalId } from '@kbn/transpose-utils';
2122

2223
import type { Datatable, DatatableColumn } from '@kbn/expressions-plugin/public';
2324
import { FormatFactory, IFieldFormat } from '@kbn/field-formats-plugin/common';
@@ -83,22 +84,14 @@ export function applyPaletteParams<T extends PaletteOutput<CustomPaletteParams>>
8384
return displayStops;
8485
}
8586

86-
function getId(id: string) {
87-
return id;
88-
}
89-
9087
export function getNumericValue(rowValue: number | number[] | undefined) {
9188
if (rowValue == null || Array.isArray(rowValue)) {
9289
return;
9390
}
9491
return rowValue;
9592
}
9693

97-
export const findMinMaxByColumnId = (
98-
columnIds: string[],
99-
table: Datatable | undefined,
100-
getOriginalId: (id: string) => string = getId
101-
) => {
94+
export const findMinMaxByColumnId = (columnIds: string[], table: Datatable | undefined) => {
10295
const minMax: Record<string, { min: number; max: number; fallback?: boolean }> = {};
10396

10497
if (table != null) {

src/plugins/chart_expressions/expression_heatmap/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@kbn/chart-expressions-common",
2929
"@kbn/visualization-utils",
3030
"@kbn/react-kibana-context-render",
31+
"@kbn/transpose-utils",
3132
],
3233
"exclude": [
3334
"target/**/*",

src/plugins/chart_expressions/expression_legacy_metric/common/types/expression_functions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import type { PaletteOutput } from '@kbn/coloring';
1111
import {
1212
Datatable,
13+
DefaultInspectorAdapters,
14+
ExecutionContext,
1315
ExpressionFunctionDefinition,
1416
ExpressionValueRender,
1517
Style,
@@ -47,5 +49,6 @@ export type MetricVisExpressionFunctionDefinition = ExpressionFunctionDefinition
4749
typeof EXPRESSION_METRIC_NAME,
4850
MetricInput,
4951
MetricArguments,
50-
ExpressionValueRender<MetricVisRenderConfig>
52+
ExpressionValueRender<MetricVisRenderConfig>,
53+
ExecutionContext<DefaultInspectorAdapters>
5154
>;

src/plugins/chart_expressions/expression_metric/common/types/expression_functions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { LayoutDirection, MetricStyle, MetricWTrend } from '@elastic/charts';
1212
import { $Values } from '@kbn/utility-types';
1313
import {
1414
Datatable,
15+
DefaultInspectorAdapters,
16+
ExecutionContext,
1517
ExpressionFunctionDefinition,
1618
ExpressionValueRender,
1719
} from '@kbn/expressions-plugin/common';
@@ -64,7 +66,8 @@ export type MetricVisExpressionFunctionDefinition = ExpressionFunctionDefinition
6466
typeof EXPRESSION_METRIC_NAME,
6567
MetricInput,
6668
MetricArguments,
67-
ExpressionValueRender<MetricVisRenderConfig>
69+
ExpressionValueRender<MetricVisRenderConfig>,
70+
ExecutionContext<DefaultInspectorAdapters>
6871
>;
6972

7073
export interface TrendlineArguments {

src/plugins/chart_expressions/expression_partition_vis/common/types/expression_functions.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
Datatable,
1515
ExpressionValueRender,
1616
ExpressionValueBoxed,
17+
DefaultInspectorAdapters,
18+
ExecutionContext,
1719
} from '@kbn/expressions-plugin/common';
1820
import {
1921
PARTITION_LABELS_VALUE,
@@ -66,28 +68,32 @@ export type PieVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
6668
typeof PIE_VIS_EXPRESSION_NAME,
6769
Datatable,
6870
PieVisConfig,
69-
ExpressionValueRender<PartitionChartProps>
71+
ExpressionValueRender<PartitionChartProps>,
72+
ExecutionContext<DefaultInspectorAdapters>
7073
>;
7174

7275
export type TreemapVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
7376
typeof TREEMAP_VIS_EXPRESSION_NAME,
7477
Datatable,
7578
TreemapVisConfig,
76-
ExpressionValueRender<PartitionChartProps>
79+
ExpressionValueRender<PartitionChartProps>,
80+
ExecutionContext<DefaultInspectorAdapters>
7781
>;
7882

7983
export type MosaicVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
8084
typeof MOSAIC_VIS_EXPRESSION_NAME,
8185
Datatable,
8286
MosaicVisConfig,
83-
ExpressionValueRender<PartitionChartProps>
87+
ExpressionValueRender<PartitionChartProps>,
88+
ExecutionContext<DefaultInspectorAdapters>
8489
>;
8590

8691
export type WaffleVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
8792
typeof WAFFLE_VIS_EXPRESSION_NAME,
8893
Datatable,
8994
WaffleVisConfig,
90-
ExpressionValueRender<PartitionChartProps>
95+
ExpressionValueRender<PartitionChartProps>,
96+
ExecutionContext<DefaultInspectorAdapters>
9197
>;
9298

9399
export enum ChartTypes {

0 commit comments

Comments
 (0)