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

adds dimensionName to datatable column meta information #106514

Merged
merged 10 commits into from
Jul 29, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export interface DatatableColumnMeta {
* index/table this column is based on
*/
index?: string;
/**
* names the domain this column represents
*/
dimensionName?: string;
/**
* serialized field format
*/
Expand Down
29 changes: 28 additions & 1 deletion src/plugins/vis_type_pie/public/pie_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition, Datatable, Render } from '../../expressions/public';
import { PieVisParams, PieVisConfig } from './types';
import { prepareLogTable } from '../../visualizations/common';

export const vislibPieName = 'pie_vis';

Expand Down Expand Up @@ -133,7 +134,33 @@ export const createPieVisFn = (): VisTypePieExpressionFunctionDefinition => ({
} as PieVisParams;

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.logDatatable('default', context);
const logTable = prepareLogTable(context, [
[
[args.metric],
i18n.translate('visTypePie.function.args.labelsHelpText', {
defaultMessage: 'Slice size',
}),
],
[
args.buckets,
i18n.translate('visTypePie.function.args.labelsHelpText', {
defaultMessage: 'Slice',
}),
],
[
args.splitColumn,
i18n.translate('visTypePie.function.args.labelsHelpText', {
defaultMessage: 'Column Split',
ppisljar marked this conversation as resolved.
Show resolved Hide resolved
}),
],
[
args.splitRow,
i18n.translate('visTypePie.function.args.labelsHelpText', {
defaultMessage: 'Row Split',
}),
],
]);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition, Datatable, Range } from '../../../expressions/public';
import { ExpressionFunctionDefinition, Datatable, Range } from '../../../expressions/common';
ppisljar marked this conversation as resolved.
Show resolved Hide resolved

interface Arguments {
from: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ExpressionValueBoxed,
Datatable,
DatatableColumn,
} from '../../../expressions/public';
} from '../../../expressions/common';

interface Arguments {
accessor: string | number;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/visualizations/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

/** @public types */
export * from './types';
export * from './prepare_log_table';
35 changes: 35 additions & 0 deletions src/plugins/visualizations/common/prepare_log_table.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 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 or the Server
* Side Public License, v 1.
*/

import { ExpressionValueVisDimension } from './expression_functions/vis_dimension';
import { Datatable } from '../../expressions/common/expression_types/specs';

export type Dimension = [ExpressionValueVisDimension[] | undefined, string];

const getDimensionName = (columnIndex: number, dimensions: Dimension[]) => {
for (const dimension of dimensions) {
if (dimension[0]?.find((d) => d.accessor === columnIndex)) {
return dimension[1];
}
}
};

export const prepareLogTable = (datatable: Datatable, dimensions: Dimension[]) => {
return {
...datatable,
columns: datatable.columns.map((column, columnIndex) => {
return {
...column,
meta: {
...column.meta,
dimensionName: getDimensionName(columnIndex, dimensions),
},
};
}),
};
};
4 changes: 2 additions & 2 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
createVisEmbeddableFromObject,
} from './embeddable';
import { TypesService } from './vis_types/types_service';
import { range as rangeExpressionFunction } from './expression_functions/range';
import { visDimension as visDimensionExpressionFunction } from './expression_functions/vis_dimension';
import { range as rangeExpressionFunction } from '../common/expression_functions/range';
import { visDimension as visDimensionExpressionFunction } from '../common/expression_functions/vis_dimension';

import { createStartServicesGetter, StartServicesGetter } from '../../kibana_utils/public';
import { createSavedVisLoader, SavedVisualizationsLoader } from './saved_visualizations';
Expand Down