Skip to content

Commit

Permalink
fix(plugin-chart-table): metrics should be undefined (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud authored and zhaoyongjie committed Nov 26, 2021
1 parent a628251 commit e03c4ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ const buildQuery: BuildQuery<TableChartFormData> = (formData: TableChartFormData
}

return buildQueryContext(formDataCopy, baseQueryObject => {
let { metrics = [], orderby = [] } = baseQueryObject;
let { metrics, orderby = [] } = baseQueryObject;
let postProcessing: PostProcessingRule[] = [];

if (queryMode === QueryMode.aggregate) {
metrics = metrics || [];
// orverride orderby with timeseries metric when in aggregation mode
if (sortByMetric) {
orderby = [[sortByMetric, !orderDesc]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ describe('plugin-chart-table', () => {
]);
});

it('should not add metrics in raw records mode', () => {
const query = buildQuery({
...basicFormData,
query_mode: QueryMode.raw,
columns: ['a'],
metrics: ['aaa', 'aaa'],
percent_metrics: ['bbb', 'bbb'],
}).queries[0];
expect(query.metrics).toBeUndefined();
expect(query.post_processing).toEqual([]);
});

it('should not add post-processing when there is no percent metric', () => {
const query = buildQuery({
...basicFormData,
Expand All @@ -65,7 +77,7 @@ describe('plugin-chart-table', () => {
columns: ['rawcol'],
percent_metrics: ['ccc'],
}).queries[0];
expect(query.metrics).toEqual([]);
expect(query.metrics).toBeUndefined();
expect(query.columns).toEqual(['rawcol']);
expect(query.post_processing).toEqual([]);
});
Expand Down

0 comments on commit e03c4ee

Please sign in to comment.