diff --git a/src/legacy/ui/public/agg_table/__tests__/_table.js b/src/legacy/ui/public/agg_table/__tests__/_table.js index 9a51e99344ee9..a67e09a3d0d29 100644 --- a/src/legacy/ui/public/agg_table/__tests__/_table.js +++ b/src/legacy/ui/public/agg_table/__tests__/_table.js @@ -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( diff --git a/src/legacy/ui/public/agg_table/agg_table.js b/src/legacy/ui/public/agg_table/agg_table.js index 821678fbcbdef..206aa10475d09 100644 --- a/src/legacy/ui/public/agg_table/agg_table.js +++ b/src/legacy/ui/public/agg_table/agg_table.js @@ -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 => { diff --git a/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.ts b/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.ts index 04d8d64b43235..080c21a6675e4 100644 --- a/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.ts +++ b/src/legacy/ui/public/visualize/loader/pipeline_helpers/build_pipeline.ts @@ -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); } - 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;