Skip to content

Commit

Permalink
Fix missing column totals in data table. (elastic#34169)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Apr 3, 2019
1 parent 41fa1d0 commit 725d2c7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 37 deletions.
10 changes: 5 additions & 5 deletions src/legacy/ui/public/agg_table/__tests__/_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/legacy/ui/public/agg_table/agg_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
if (agg.type.name === 'geohash_grid') {
schema.params = {
precision: agg.params.precision,
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);
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') {
params.precision = agg.params.precision;
params.useGeocentroid = agg.params.useGeocentroid;
}

return schema;
return {
accessor,
format,
params,
aggType: agg.type.name,
};
};

let cnt = 0;
Expand Down

0 comments on commit 725d2c7

Please sign in to comment.