Skip to content

Commit

Permalink
Filter out error when calculating a label (#69934)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
sulemanof and elasticmachine committed Jul 2, 2020
1 parent e08fda0 commit c02e6dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/plugins/data/public/search/tabify/get_columns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,20 @@ describe('get columns', () => {
'Sum of @timestamp',
]);
});

test('should not fail if there is no field for date histogram agg', () => {
const columns = tabifyGetColumns(
createAggConfigs([
{
type: 'date_histogram',
schema: 'segment',
params: {},
},
{ type: 'sum', schema: 'metric', params: { field: '@timestamp' } },
]).aggs,
false
);

expect(columns.map((c) => c.name)).toEqual(['', 'Sum of @timestamp']);
});
});
9 changes: 8 additions & 1 deletion src/plugins/data/public/search/tabify/get_columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ import { IAggConfig } from '../aggs';
import { TabbedAggColumn } from './types';

const getColumn = (agg: IAggConfig, i: number): TabbedAggColumn => {
let name = '';
try {
name = agg.makeLabel();
} catch (e) {
// skip the case when makeLabel throws an error (e.x. no appropriate field for an aggregation)
}

return {
aggConfig: agg,
id: `col-${i}-${agg.id}`,
name: agg.makeLabel(),
name,
};
};

Expand Down

0 comments on commit c02e6dc

Please sign in to comment.