mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Backwards-compat for multi-query table transform
* treat single-query table panels like they were before * adjusted test cases
This commit is contained in:
parent
1dd90c8105
commit
eb31833d52
@ -1,6 +1,6 @@
|
||||
import {transformers, transformDataToTable} from '../transformers';
|
||||
|
||||
describe('when transforming time series table.', () => {
|
||||
describe('when transforming time series table', () => {
|
||||
var table;
|
||||
|
||||
describe('given 2 time series', () => {
|
||||
@ -189,7 +189,7 @@ describe('when transforming time series table.', () => {
|
||||
var columns = transformers[transform].getColumns(singleQueryData);
|
||||
expect(columns[0].text).toBe('Time');
|
||||
expect(columns[1].text).toBe('Label Key 1');
|
||||
expect(columns[2].text).toBe('Value #A');
|
||||
expect(columns[2].text).toBe('Value');
|
||||
});
|
||||
|
||||
it('should return the union of data columns given a multiple queries', function() {
|
||||
@ -221,7 +221,7 @@ describe('when transforming time series table.', () => {
|
||||
expect(table.columns.length).toBe(3);
|
||||
expect(table.columns[0].text).toBe('Time');
|
||||
expect(table.columns[1].text).toBe('Label Key 1');
|
||||
expect(table.columns[2].text).toBe('Value #A');
|
||||
expect(table.columns[2].text).toBe('Value');
|
||||
});
|
||||
|
||||
it ('should return the union of columns for multiple queries', () => {
|
||||
|
@ -136,6 +136,11 @@ transformers['table'] = {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Single query returns data columns as is
|
||||
if (data.length === 1) {
|
||||
return [...data[0].columns];
|
||||
}
|
||||
|
||||
// Track column indexes: name -> index
|
||||
const columnNames = {};
|
||||
|
||||
@ -155,7 +160,7 @@ transformers['table'] = {
|
||||
|
||||
// Append one value column per data set
|
||||
data.forEach((_, i) => {
|
||||
// Value (A), Value (B),...
|
||||
// Value #A, Value #B,...
|
||||
const text = `Value #${String.fromCharCode(65 + i)}`;
|
||||
columnNames[text] = columns.length;
|
||||
columns.push({ text });
|
||||
@ -173,6 +178,13 @@ transformers['table'] = {
|
||||
throw {message: `Result of query #${String.fromCharCode(65 + noTableIndex)} is not in table format, try using another transform.`};
|
||||
}
|
||||
|
||||
// Single query returns data columns and rows as is
|
||||
if (data.length === 1) {
|
||||
model.columns = [...data[0].columns];
|
||||
model.rows = [...data[0].rows];
|
||||
return;
|
||||
}
|
||||
|
||||
// Track column indexes: name -> index
|
||||
const columnNames = {};
|
||||
const columnIndexes = [];
|
||||
|
Loading…
Reference in New Issue
Block a user