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

[Lens][Datatable] Fix share export and inspect data #193780

Merged
merged 25 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
caf0d04
chore: strengthen context types with default adapter type
nickofthyme Sep 19, 2024
64aaadc
fix: table inspect flyout export data
nickofthyme Sep 19, 2024
3d1d55a
feat: support transposed columns in table
nickofthyme Sep 20, 2024
5158787
improve inspect and export flow
nickofthyme Sep 23, 2024
de71e9f
fix: filter out ghost columns in inspect created from formula metrics
nickofthyme Sep 23, 2024
5bde6b9
Merge branch 'main' into fix-table-exports
nickofthyme Sep 29, 2024
351812f
Merge branch 'main' into fix-table-exports
nickofthyme Oct 13, 2024
1317666
Move transpose helpers into shared kbn package
nickofthyme Oct 13, 2024
dfc2221
cleanup columns sorting logic
nickofthyme Oct 13, 2024
fd5974d
Merge branch 'main' into fix-table-exports
nickofthyme Oct 14, 2024
44baf77
cleanup csv sorting logic, now we directly pass all tables to be expo…
nickofthyme Oct 14, 2024
11f8cb2
[CI] Auto-commit changed files from 'node scripts/lint_packages --fix'
kibanamachine Oct 14, 2024
15eaf73
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Oct 14, 2024
d8abdf6
fix quick check issues
nickofthyme Oct 20, 2024
609dc1c
update jest tests with new changes
nickofthyme Oct 20, 2024
50ffcdf
Merge branch 'main' into fix-table-exports
nickofthyme Oct 20, 2024
1e9f9b5
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Oct 20, 2024
25a6eb0
fix jest type errors
nickofthyme Oct 21, 2024
5c3ccd8
fix activeData error caused by conditional `onActiveDataChange` trans…
nickofthyme Oct 22, 2024
313c934
Merge remote-tracking branch 'origin/fix-table-exports' into fix-tabl…
nickofthyme Oct 22, 2024
b454f2a
Merge branch 'main' into fix-table-exports
nickofthyme Oct 22, 2024
ac0ff49
fix jest tests and fn tests
nickofthyme Oct 22, 2024
0d580bd
Merge branch 'main' into fix-table-exports
nickofthyme Oct 22, 2024
a37edcb
Merge branch 'main' into fix-table-exports
nickofthyme Oct 24, 2024
4592f10
fix type error in unit test
nickofthyme Oct 24, 2024
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
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 @@ -946,6 +946,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