Skip to content

Commit

Permalink
[8.x] [Lens][Datatable] Fix share export and inspect data (#193780) (#…
Browse files Browse the repository at this point in the history
…197696)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Lens][Datatable] Fix share export and inspect data
(#193780)](#193780)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nick
Partridge","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-24T16:51:38Z","message":"[Lens][Datatable]
Fix share export and inspect data (#193780)\n\nThe exported table data
table provided in the inspector and the share export now match what was
visible in the
UI.","sha":"a854ff8a4e4f81397cebde70adc31e4ee893ce34","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:ExpressionLanguage","Team:Visualizations","Feature:Lens","v9.0.0","backport:prev-minor"],"title":"[Lens][Datatable]
Fix share export and inspect
data","number":193780,"url":"https://github.com/elastic/kibana/pull/193780","mergeCommit":{"message":"[Lens][Datatable]
Fix share export and inspect data (#193780)\n\nThe exported table data
table provided in the inspector and the share export now match what was
visible in the
UI.","sha":"a854ff8a4e4f81397cebde70adc31e4ee893ce34"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193780","number":193780,"mergeCommit":{"message":"[Lens][Datatable]
Fix share export and inspect data (#193780)\n\nThe exported table data
table provided in the inspector and the share export now match what was
visible in the
UI.","sha":"a854ff8a4e4f81397cebde70adc31e4ee893ce34"}}]}] BACKPORT-->

Co-authored-by: Nick Partridge <[email protected]>
  • Loading branch information
kibanamachine and nickofthyme authored Oct 24, 2024
1 parent 0ffda7b commit c7a27b8
Show file tree
Hide file tree
Showing 52 changed files with 478 additions and 280 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ packages/kbn-tinymath @elastic/kibana-visualizations
packages/kbn-tooling-log @elastic/kibana-operations
x-pack/plugins/transform @elastic/ml-ui
x-pack/plugins/translations @elastic/kibana-localization
packages/kbn-transpose-utils @elastic/kibana-visualizations
x-pack/examples/triggers_actions_ui_example @elastic/response-ops
x-pack/plugins/triggers_actions_ui @elastic/response-ops
packages/kbn-triggers-actions-ui-types @elastic/response-ops
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@
"@kbn/tinymath": "link:packages/kbn-tinymath",
"@kbn/transform-plugin": "link:x-pack/plugins/transform",
"@kbn/translations-plugin": "link:x-pack/plugins/translations",
"@kbn/transpose-utils": "link:packages/kbn-transpose-utils",
"@kbn/triggers-actions-ui-example-plugin": "link:x-pack/examples/triggers_actions_ui_example",
"@kbn/triggers-actions-ui-plugin": "link:x-pack/plugins/triggers_actions_ui",
"@kbn/triggers-actions-ui-types": "link:packages/kbn-triggers-actions-ui-types",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-transpose-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/transpose-utils

Utility functions used to identify and convert transposed column ids.
35 changes: 35 additions & 0 deletions packages/kbn-transpose-utils/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { getOriginalId, getTransposeId, isTransposeId } from '.';

describe('transpose utils', () => {
it('should covert value and id to transposed id', () => {
expect(getTransposeId('test', 'column-1')).toBe('test---column-1');
});

it('should know if id is transposed', () => {
const testId = getTransposeId('test', 'column-1');
expect(isTransposeId(testId)).toBe(true);
});

it('should know if id is not transposed', () => {
expect(isTransposeId('test')).toBe(false);
});

it('should return id for transposed id', () => {
const testId = getTransposeId('test', 'column-1');

expect(getOriginalId(testId)).toBe('column-1');
});

it('should return id for non-transposed id', () => {
expect(getOriginalId('test')).toBe('test');
});
});
36 changes: 36 additions & 0 deletions packages/kbn-transpose-utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

/**
* Used to delimitate felids of a transposed column id
*/
export const TRANSPOSE_SEPARATOR = '---';

/**
* Visual deliminator between felids of a transposed column id
*
* Meant to align with the `MULTI_FIELD_KEY_SEPARATOR` from the data plugin
*/
export const TRANSPOSE_VISUAL_SEPARATOR = '›';

export function getTransposeId(value: string, columnId: string) {
return `${value}${TRANSPOSE_SEPARATOR}${columnId}`;
}

export function isTransposeId(id: string): boolean {
return id.split(TRANSPOSE_SEPARATOR).length > 1;
}

export function getOriginalId(id: string) {
if (id.includes(TRANSPOSE_SEPARATOR)) {
const idParts = id.split(TRANSPOSE_SEPARATOR);
return idParts[idParts.length - 1];
}
return id;
}
14 changes: 14 additions & 0 deletions packages/kbn-transpose-utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-transpose-utils'],
};
5 changes: 5 additions & 0 deletions packages/kbn-transpose-utils/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/transpose-utils",
"owner": "@elastic/kibana-visualizations"
}
6 changes: 6 additions & 0 deletions packages/kbn-transpose-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/transpose-utils",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
}
19 changes: 19 additions & 0 deletions packages/kbn-transpose-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { $Values } from '@kbn/utility-types';
import type { PaletteOutput, CustomPaletteParams } from '@kbn/coloring';
import {
Datatable,
DefaultInspectorAdapters,
ExecutionContext,
ExpressionFunctionDefinition,
ExpressionValueRender,
} from '@kbn/expressions-plugin/common';
Expand Down Expand Up @@ -86,7 +88,8 @@ export type GaugeExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof EXPRESSION_GAUGE_NAME,
GaugeInput,
GaugeArguments,
ExpressionValueRender<GaugeExpressionProps>
ExpressionValueRender<GaugeExpressionProps>,
ExecutionContext<DefaultInspectorAdapters>
>;

export interface Accessors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { Position } from '@elastic/charts';
import type { PaletteOutput } from '@kbn/coloring';
import {
Datatable,
DefaultInspectorAdapters,
ExecutionContext,
ExpressionFunctionDefinition,
ExpressionValueRender,
} from '@kbn/expressions-plugin/common';
Expand Down Expand Up @@ -114,7 +116,8 @@ export type HeatmapExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof EXPRESSION_HEATMAP_NAME,
HeatmapInput,
HeatmapArguments,
ExpressionValueRender<HeatmapExpressionProps>
ExpressionValueRender<HeatmapExpressionProps>,
ExecutionContext<DefaultInspectorAdapters>
>;

export type HeatmapLegendExpressionFunctionDefinition = ExpressionFunctionDefinition<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
DEFAULT_MAX_STOP,
DEFAULT_MIN_STOP,
} from '@kbn/coloring';
import { getOriginalId } from '@kbn/transpose-utils';

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

function getId(id: string) {
return id;
}

export function getNumericValue(rowValue: number | number[] | undefined) {
if (rowValue == null || Array.isArray(rowValue)) {
return;
}
return rowValue;
}

export const findMinMaxByColumnId = (
columnIds: string[],
table: Datatable | undefined,
getOriginalId: (id: string) => string = getId
) => {
export const findMinMaxByColumnId = (columnIds: string[], table: Datatable | undefined) => {
const minMax: Record<string, { min: number; max: number; fallback?: boolean }> = {};

if (table != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@kbn/chart-expressions-common",
"@kbn/visualization-utils",
"@kbn/react-kibana-context-render",
"@kbn/transpose-utils",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import type { PaletteOutput } from '@kbn/coloring';
import {
Datatable,
DefaultInspectorAdapters,
ExecutionContext,
ExpressionFunctionDefinition,
ExpressionValueRender,
Style,
Expand Down Expand Up @@ -47,5 +49,6 @@ export type MetricVisExpressionFunctionDefinition = ExpressionFunctionDefinition
typeof EXPRESSION_METRIC_NAME,
MetricInput,
MetricArguments,
ExpressionValueRender<MetricVisRenderConfig>
ExpressionValueRender<MetricVisRenderConfig>,
ExecutionContext<DefaultInspectorAdapters>
>;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { LayoutDirection, MetricStyle, MetricWTrend } from '@elastic/charts';
import { $Values } from '@kbn/utility-types';
import {
Datatable,
DefaultInspectorAdapters,
ExecutionContext,
ExpressionFunctionDefinition,
ExpressionValueRender,
} from '@kbn/expressions-plugin/common';
Expand Down Expand Up @@ -64,7 +66,8 @@ export type MetricVisExpressionFunctionDefinition = ExpressionFunctionDefinition
typeof EXPRESSION_METRIC_NAME,
MetricInput,
MetricArguments,
ExpressionValueRender<MetricVisRenderConfig>
ExpressionValueRender<MetricVisRenderConfig>,
ExecutionContext<DefaultInspectorAdapters>
>;

export interface TrendlineArguments {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
Datatable,
ExpressionValueRender,
ExpressionValueBoxed,
DefaultInspectorAdapters,
ExecutionContext,
} from '@kbn/expressions-plugin/common';
import {
PARTITION_LABELS_VALUE,
Expand Down Expand Up @@ -66,28 +68,32 @@ export type PieVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof PIE_VIS_EXPRESSION_NAME,
Datatable,
PieVisConfig,
ExpressionValueRender<PartitionChartProps>
ExpressionValueRender<PartitionChartProps>,
ExecutionContext<DefaultInspectorAdapters>
>;

export type TreemapVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof TREEMAP_VIS_EXPRESSION_NAME,
Datatable,
TreemapVisConfig,
ExpressionValueRender<PartitionChartProps>
ExpressionValueRender<PartitionChartProps>,
ExecutionContext<DefaultInspectorAdapters>
>;

export type MosaicVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof MOSAIC_VIS_EXPRESSION_NAME,
Datatable,
MosaicVisConfig,
ExpressionValueRender<PartitionChartProps>
ExpressionValueRender<PartitionChartProps>,
ExecutionContext<DefaultInspectorAdapters>
>;

export type WaffleVisExpressionFunctionDefinition = ExpressionFunctionDefinition<
typeof WAFFLE_VIS_EXPRESSION_NAME,
Datatable,
WaffleVisConfig,
ExpressionValueRender<PartitionChartProps>
ExpressionValueRender<PartitionChartProps>,
ExecutionContext<DefaultInspectorAdapters>
>;

export enum ChartTypes {
Expand Down
Loading

0 comments on commit c7a27b8

Please sign in to comment.