Fix missing column totals in data table. (#34169)

This commit is contained in:
Luke Elmers 2019-04-03 16:04:55 -06:00 committed by GitHub
parent 0ce68ceb9d
commit 5bb9947b50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 37 deletions

View file

@ -181,12 +181,12 @@ describe('AggTable Directive', function () {
$scope.dimensions = {
buckets: [
{ accessor: 0, params: {} },
{ accessor: 1, format: { id: 'date', params: { pattern: 'YYYY-MM-DD' } }, params: { isDate: true } }
{ accessor: 1, format: { id: 'date', params: { pattern: 'YYYY-MM-DD' } } },
], metrics: [
{ accessor: 2, format: { id: 'number' }, params: { isNumeric: true } },
{ accessor: 3, format: { id: 'date' }, params: { isDate: true } },
{ accessor: 4, format: { id: 'number' }, params: { isNumeric: true } },
{ accessor: 5, format: { id: 'number' }, params: { isNumeric: true } }
{ accessor: 2, format: { id: 'number' } },
{ accessor: 3, format: { id: 'date' } },
{ accessor: 4, format: { id: 'number' } },
{ accessor: 5, format: { id: 'number' } },
]
};
const response = await tableAggResponse(

View file

@ -125,7 +125,8 @@ uiModules
formattedColumn.class = 'visualize-table-right';
}
const { isNumeric, isDate } = dimension.params;
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';
if (isNumeric || isDate || $scope.totalFunc === 'count') {
const sum = tableRows => {

View file

@ -28,10 +28,15 @@ interface SchemaFormat {
params?: any;
}
interface SchemaConfigParams {
precision?: number;
useGeocentroid?: boolean;
}
interface SchemaConfig {
accessor: number;
format: SchemaFormat | {};
params: any;
params: SchemaConfigParams;
aggType: string;
}
@ -104,43 +109,39 @@ export const getSchemas = (vis: Vis, timeRange?: any): Schemas => {
};
const createSchemaConfig = (accessor: number, agg: AggConfig): SchemaConfig => {
const schema = {
accessor,
format: {},
params: {},
aggType: agg.type.name,
};
if (agg.type.name === 'date_histogram') {
agg.params.timeRange = timeRange;
setBounds(agg, true);
}
const hasSubAgg = [
'derivative',
'moving_avg',
'serial_diff',
'cumulative_sum',
'sum_bucket',
'avg_bucket',
'min_bucket',
'max_bucket',
].includes(agg.type.name);
const format = createFormat(
hasSubAgg ? agg.params.customMetric || agg.aggConfigs.byId[agg.params.metricAgg] : agg
);
const params: SchemaConfigParams = {};
if (agg.type.name === 'geohash_grid') {
schema.params = {
precision: agg.params.precision,
useGeocentroid: agg.params.useGeocentroid,
};
params.precision = agg.params.precision;
params.useGeocentroid = agg.params.useGeocentroid;
}
if (
[
'derivative',
'moving_avg',
'serial_diff',
'cumulative_sum',
'sum_bucket',
'avg_bucket',
'min_bucket',
'max_bucket',
].includes(agg.type.name)
) {
const subAgg = agg.params.customMetric || agg.aggConfigs.byId[agg.params.metricAgg];
schema.format = createFormat(subAgg);
} else {
schema.format = createFormat(agg);
}
return schema;
return {
accessor,
format,
params,
aggType: agg.type.name,
};
};
let cnt = 0;