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 13 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 @@ -941,6 +941,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-helpers @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 @@ -943,6 +943,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-helpers": "link:packages/kbn-transpose-helpers",
"@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-helpers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/transpose-helpers

Util functions used convert raw columns into transposed columns.
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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 type { FieldFormat } from '@kbn/field-formats-plugin/common';
import type { Datatable } from '@kbn/expressions-plugin/common';
import { DatatableArgs } from './datatable';
import { DatatableArgs } from '@kbn/lens-plugin/common/expressions';

import { transposeTable } from './transpose_helpers';
import { transposeTable } from '.';

describe('transpose_helpers', () => {
describe('transpose helpers', () => {
function buildTable(): Datatable {
// 3 buckets, 2 metrics
// first bucket goes A/B/C
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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 type { Datatable, DatatableColumn, DatatableRow } from '@kbn/expressions-plugin/common';
import type { FieldFormat } from '@kbn/field-formats-plugin/common';
import type { DatatableArgs } from './datatable';
import type { DatatableColumnConfig, DatatableColumnArgs } from './datatable_column';
import {
DatatableArgs,
DatatableColumnArgs,
DatatableColumnConfig,
} from '@kbn/lens-plugin/common/expressions';

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

const TRANSPOSE_VISUAL_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}`;
Expand All @@ -34,16 +47,12 @@ export function getOriginalId(id: string) {
* Transposes the columns of the given table as defined in the arguments.
* This function modifies the passed in args and firstTable objects.
* This process consists out of three parts:
*
* * Calculating the new column arguments
* * Calculating the new datatable columns
* * Calculating the new rows
*
* If the table is tranposed by multiple columns, this process is repeated on top of the previous transformation.
*
* @internal
* @param args Arguments for the table visualization
* @param firstTable datatable object containing the actual data
* @param formatters Formatters for all columns to transpose columns by actual display values
* If the table is transposed by multiple columns, this process is repeated on top of the previous transformation.
*/
export function transposeTable(
args: DatatableArgs,
Expand All @@ -52,8 +61,7 @@ export function transposeTable(
) {
args.columns
.filter((columnArgs) => columnArgs.isTransposed)
// start with the inner nested transposed column and work up to preserve column grouping
.reverse()
.reverse() // start with the inner nested transposed column and work up to preserve column grouping
.forEach(({ columnId: transposedColumnId }) => {
const datatableColumnIndex = firstTable.columns.findIndex((c) => c.id === transposedColumnId);
const datatableColumn = firstTable.columns[datatableColumnIndex];
Expand Down Expand Up @@ -86,6 +94,11 @@ export function transposeTable(
transposedColumnId,
metricsColumnArgs
);

const colOrderMap = new Map(args.columns.map((c, i) => [c.columnId, i]));
firstTable.columns.sort((a, b) => {
return (colOrderMap.get(a.id) ?? 0) - (colOrderMap.get(b.id) ?? 0);
});
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down Expand Up @@ -131,9 +144,6 @@ function updateColumnArgs(

/**
* Finds all unique values in a column in order of first occurence
* @param table Table to search through
* @param formatter formatter for the column
* @param columnId column
*/
function getUniqueValues(table: Datatable, formatter: FieldFormat, columnId: string) {
const values = new Map<string, unknown>();
Expand All @@ -149,9 +159,6 @@ function getUniqueValues(table: Datatable, formatter: FieldFormat, columnId: str
/**
* Calculate transposed column objects of the datatable object and puts them into the datatable.
* Returns args for additional columns grouped by metric
* @param metricColumns
* @param firstTable
* @param uniqueValues
*/
function transposeColumns(
args: DatatableArgs,
Expand Down
14 changes: 14 additions & 0 deletions packages/kbn-transpose-helpers/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-helpers'],
};
5 changes: 5 additions & 0 deletions packages/kbn-transpose-helpers/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/transpose-helpers",
"owner": "@elastic/kibana-visualizations"
}
6 changes: 6 additions & 0 deletions packages/kbn-transpose-helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/transpose-helpers",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
}
23 changes: 23 additions & 0 deletions packages/kbn-transpose-helpers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/field-formats-plugin",
"@kbn/expressions-plugin",
"@kbn/lens-plugin",
]
}
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-helpers';

import type { Datatable, DatatableColumn } from '@kbn/expressions-plugin/public';
import { FormatFactory, IFieldFormat } from '@kbn/field-formats-plugin/common';
Expand Down Expand Up @@ -94,11 +95,7 @@ export function getNumericValue(rowValue: number | number[] | undefined) {
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-helpers",
],
"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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type { PaletteOutput } from '@kbn/coloring';
import type {
Datatable,
DatatableColumnMeta,
DefaultInspectorAdapters,
ExecutionContext,
ExpressionFunctionDefinition,
} from '@kbn/expressions-plugin/common';
import {
Expand Down Expand Up @@ -449,13 +451,15 @@ export type XyVisFn = ExpressionFunctionDefinition<
typeof XY_VIS,
Datatable,
XYArgs,
Promise<XYRender>
Promise<XYRender>,
ExecutionContext<DefaultInspectorAdapters>
>;
export type LayeredXyVisFn = ExpressionFunctionDefinition<
typeof LAYERED_XY_VIS,
Datatable,
LayeredXYArgs,
Promise<XYRender>
Promise<XYRender>,
ExecutionContext<DefaultInspectorAdapters>
>;

export type ExtendedDataLayerFn = ExpressionFunctionDefinition<
Expand Down
Loading