Skip to content

Commit

Permalink
[Visualizations] Adds dimensionName in datatable meta info (#107265)
Browse files Browse the repository at this point in the history
* [Visualizations] Adds dimensionName in datatable meta info

* Delete unused file

* fix i18n

* Another fix of i18n

* Fix translations

* Remove double types

* Fix types

* Another type fix

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
stratoula and kibanamachine committed Aug 3, 2021
1 parent 4e51173 commit d231cef
Show file tree
Hide file tree
Showing 28 changed files with 305 additions and 70 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/plugins/vis_type_metric/public/metric_vis_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { createMetricVisFn } from './metric_vis_fn';
import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { Datatable } from '../../expressions/common/expression_types/specs';

describe('interpreter/functions#metric', () => {
const fn = functionWrapper(createMetricVisFn());
Expand Down Expand Up @@ -56,4 +57,20 @@ describe('interpreter/functions#metric', () => {

expect(actual).toMatchSnapshot();
});

it('logs correct datatable to inspector', async () => {
let loggedTable: Datatable;
const handlers = {
inspectorAdapters: {
tables: {
logDatatable: (name: string, datatable: Datatable) => {
loggedTable = datatable;
},
},
},
};
await fn(context, args, handlers as any);

expect(loggedTable!).toMatchSnapshot();
});
});
20 changes: 19 additions & 1 deletion src/plugins/vis_type_metric/public/metric_vis_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Style,
} from '../../expressions/public';
import { visType, DimensionsVisParam, VisParams } from './types';
import { prepareLogTable, Dimension } from '../../visualizations/public';
import { ColorSchemas, vislibColorMaps, ColorMode } from '../../charts/public';

export type Input = Datatable;
Expand Down Expand Up @@ -164,7 +165,24 @@ export const createMetricVisFn = (): MetricVisExpressionFunctionDefinition => ({
const fontSize = Number.parseInt(args.font.spec.fontSize || '', 10);

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.logDatatable('default', input);
const argsTable: Dimension[] = [
[
args.metric,
i18n.translate('visTypeMetric.function.dimension.metric', {
defaultMessage: 'Metric',
}),
],
];
if (args.bucket) {
argsTable.push([
[args.bucket],
i18n.translate('visTypeMetric.function.adimension.splitGroup', {
defaultMessage: 'Split group',
}),
]);
}
const logTable = prepareLogTable(input, argsTable);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}
return {
type: 'render',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/plugins/vis_type_table/public/table_vis_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createTableVisFn } from './table_vis_fn';
import { tableVisResponseHandler } from './utils';

import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { Datatable } from '../../expressions/common/expression_types/specs';

jest.mock('./utils', () => ({
tableVisResponseHandler: jest.fn().mockReturnValue({
Expand Down Expand Up @@ -67,4 +68,20 @@ describe('interpreter/functions#table', () => {
expect(tableVisResponseHandler).toHaveBeenCalledTimes(1);
expect(tableVisResponseHandler).toHaveBeenCalledWith(context, visConfig);
});

it('logs correct datatable to inspector', async () => {
let loggedTable: Datatable;
const handlers = {
inspectorAdapters: {
tables: {
logDatatable: (name: string, datatable: Datatable) => {
loggedTable = datatable;
},
},
},
};
await fn(context, visConfig, handlers as any);

expect(loggedTable!).toMatchSnapshot();
});
});
34 changes: 33 additions & 1 deletion src/plugins/vis_type_table/public/table_vis_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition, Datatable, Render } from '../../expressions/public';
import { prepareLogTable, Dimension } from '../../visualizations/public';
import { TableVisData, TableVisConfig } from './types';
import { VIS_TYPE_TABLE } from '../common';
import { tableVisResponseHandler } from './utils';
Expand Down Expand Up @@ -122,7 +123,38 @@ export const createTableVisFn = (): TableExpressionFunctionDefinition => ({
const convertedData = tableVisResponseHandler(input, args);

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.logDatatable('default', input);
const argsTable: Dimension[] = [
[
args.metrics,
i18n.translate('visTypeTable.function.dimension.metrics', {
defaultMessage: 'Metrics',
}),
],
[
args.buckets,
i18n.translate('visTypeTable.function.adimension.buckets', {
defaultMessage: 'Buckets',
}),
],
];
if (args.splitColumn) {
argsTable.push([
[args.splitColumn],
i18n.translate('visTypeTable.function.dimension.splitColumn', {
defaultMessage: 'Split by column',
}),
]);
}
if (args.splitRow) {
argsTable.push([
[args.splitRow],
i18n.translate('visTypeTable.function.dimension.splitRow', {
defaultMessage: 'Split by row',
}),
]);
}
const logTable = prepareLogTable(input, argsTable);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}
return {
type: 'render',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/plugins/vis_type_tagcloud/public/tag_cloud_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { createTagCloudFn } from './tag_cloud_fn';

import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { Datatable } from '../../expressions/common/expression_types/specs';

describe('interpreter/functions#tagcloud', () => {
const fn = functionWrapper(createTagCloudFn());
Expand All @@ -31,4 +32,20 @@ describe('interpreter/functions#tagcloud', () => {
const actual = fn(context, visConfig, undefined);
expect(actual).toMatchSnapshot();
});

it('logs correct datatable to inspector', async () => {
let loggedTable: Datatable;
const handlers = {
inspectorAdapters: {
tables: {
logDatatable: (name: string, datatable: Datatable) => {
loggedTable = datatable;
},
},
},
};
await fn(context, visConfig, handlers as any);

expect(loggedTable!).toMatchSnapshot();
});
});
20 changes: 19 additions & 1 deletion src/plugins/vis_type_tagcloud/public/tag_cloud_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 { prepareLogTable, Dimension } from '../../visualizations/public';
import { TagCloudVisParams, TagCloudVisConfig } from './types';

const name = 'tagcloud';
Expand Down Expand Up @@ -109,7 +110,24 @@ export const createTagCloudFn = (): TagcloudExpressionFunctionDefinition => ({
} as TagCloudVisParams;

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.logDatatable('default', input);
const argsTable: Dimension[] = [
[
[args.metric],
i18n.translate('visTypeTagCloud.function.dimension.tagSize', {
defaultMessage: 'Tag size',
}),
],
];
if (args.bucket) {
argsTable.push([
[args.bucket],
i18n.translate('visTypeTagCloud.function.adimension.tags', {
defaultMessage: 'Tags',
}),
]);
}
const logTable = prepareLogTable(input, argsTable);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}
return {
type: 'render',
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/vis_type_vislib/public/to_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
VisParams,
} from '../../visualizations/public';
import { buildExpression, buildExpressionFunction } from '../../expressions/public';
import type { Dimensions, DateHistogramParams, HistogramParams } from '../../vis_type_xy/public';
import type { Dimensions } from '../../vis_type_xy/public';
import type { DateHistogramParams, HistogramParams } from '../../visualizations/public';

import { BUCKET_TYPES } from '../../data/public';

import { vislibVisName, VisTypeVislibExpressionFunctionDefinition } from './vis_type_vislib_vis_fn';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import moment from 'moment';

import type { DateHistogramParams, HistogramParams } from '../../../../../vis_type_xy/public';
import type { DateHistogramParams, HistogramParams } from '../../../../../visualizations/public';

import { initXAxis } from './_init_x_axis';
import { makeFakeXAspect } from './_fake_x_aspect';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import moment from 'moment';
import _ from 'lodash';

import type { DateHistogramParams } from '../../../../../vis_type_xy/public/types';
import type { DateHistogramParams } from '../../../../../visualizations/public';

import { orderedDateAxis } from './_ordered_date_axis';
import { OrderedChart } from './point_series';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@

import { Duration } from 'moment';

import type {
Dimension,
Dimensions,
DateHistogramParams,
HistogramParams,
} from '../../../../../vis_type_xy/public';
import type { Dimension, Dimensions } from '../../../../../vis_type_xy/public';
import type { DateHistogramParams, HistogramParams } from '../../../../../visualizations/public';

import { getSeries } from './_get_series';
import { getAspects } from './_get_aspects';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_xy/public/config/get_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { ScaleContinuousType } from '@elastic/charts';

import { Datatable } from '../../../expressions/public';
import { BUCKET_TYPES } from '../../../data/public';
import { DateHistogramParams } from '../../../visualizations/public';

import {
Aspect,
AxisConfig,
DateHistogramParams,
SeriesParam,
VisConfig,
VisParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ export { seriesParam, ExpressionValueSeriesParam } from './series_param';
export { thresholdLine, ExpressionValueThresholdLine } from './threshold_line';
export { label, ExpressionValueLabel } from './label';
export { visScale, ExpressionValueScale } from './vis_scale';
export { xyDimension, ExpressionValueXYDimension } from './xy_dimension';
42 changes: 40 additions & 2 deletions src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import { i18n } from '@kbn/i18n';

import type { ExpressionFunctionDefinition, Datatable, Render } from '../../../expressions/public';
import type { ExpressionFunctionDefinition, Datatable, Render } from '../../../expressions/common';
import { prepareLogTable, Dimension } from '../../../visualizations/public';
import type { ChartType } from '../../common';
import type { VisParams, XYVisConfig } from '../types';

Expand Down Expand Up @@ -262,7 +263,44 @@ export const visTypeXyVisFn = (): VisTypeXyExpressionFunctionDefinition => ({
} as VisParams;

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.logDatatable('default', context);
const argsTable: Dimension[] = [
[
args.yDimension,
i18n.translate('visTypeXy.function.dimension.metric', {
defaultMessage: 'Metric',
}),
],
[
args.zDimension,
i18n.translate('visTypeXy.function.adimension.dotSize', {
defaultMessage: 'Dot size',
}),
],
[
args.splitColumnDimension,
i18n.translate('visTypeXy.function.dimension.splitcolumn', {
defaultMessage: 'Column split',
}),
],
[
args.splitRowDimension,
i18n.translate('visTypeXy.function.dimension.splitrow', {
defaultMessage: 'Row split',
}),
],
];

if (args.xDimension) {
argsTable.push([
[args.xDimension],
i18n.translate('visTypeXy.function.adimension.bucket', {
defaultMessage: 'Bucket',
}),
]);
}

const logTable = prepareLogTable(context, argsTable);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}

return {
Expand Down
Loading

0 comments on commit d231cef

Please sign in to comment.