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

[Data table] Fix Date Histogram error when index does not have a time field #69934

Merged
merged 3 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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