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

fix: Table visualization shows total for duration, percentage and bytes field formatters #54240

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,15 @@ export function KbnAggTable(config, RecursionHelper) {
}

const isDate =
_.get(dimension, 'format.id') === 'date' ||
_.get(dimension, 'format.params.id') === 'date';
const isNumeric =
_.get(dimension, 'format.id') === 'number' ||
_.get(dimension, 'format.params.id') === 'number';
dimension.format?.id === 'date' || dimension.format?.params?.id === 'date';
const allowsNumericalAggregations = formatter?.allowsNumericalAggregations;

let { totalFunc } = $scope;
if (typeof totalFunc === 'undefined' && showPercentage) {
totalFunc = 'sum';
}

if (isNumeric || isDate || totalFunc === 'count') {
if (allowsNumericalAggregations || isDate || totalFunc === 'count') {
const sum = tableRows => {
return _.reduce(
tableRows,
Expand All @@ -161,7 +158,6 @@ export function KbnAggTable(config, RecursionHelper) {
};

formattedColumn.sumTotal = sum(table.rows);

switch (totalFunc) {
case 'sum': {
if (!isDate) {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/field_formats/converters/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export class BytesFormat extends NumeralFormat {

id = BytesFormat.id;
title = BytesFormat.title;
allowsNumericalAggregations = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class DurationFormat extends FieldFormat {
static fieldType = KBN_FIELD_TYPES.NUMBER;
static inputFormats = inputFormats;
static outputFormats = outputFormats;
allowsNumericalAggregations = true;

isHuman() {
return this.param('outputFormat') === HUMAN_FRIENDLY;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/field_formats/converters/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export class NumberFormat extends NumeralFormat {

id = NumberFormat.id;
title = NumberFormat.title;
allowsNumericalAggregations = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class PercentFormat extends NumeralFormat {

id = PercentFormat.id;
title = PercentFormat.title;
allowsNumericalAggregations = true;

getParamDefaults = () => ({
pattern: this.getConfig!('format:percent:defaultPattern'),
Expand Down