mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelInspect: Handle field type frame for csv export (#91983)
PanelInspect: Handle field type frame
This commit is contained in:
parent
e60b0aef83
commit
de0e6d0fce
@ -5,6 +5,7 @@ import { MutableDataFrame } from '../dataframe/MutableDataFrame';
|
|||||||
import { getDataFrameRow, toDataFrameDTO } from '../dataframe/processDataFrame';
|
import { getDataFrameRow, toDataFrameDTO } from '../dataframe/processDataFrame';
|
||||||
import { getDisplayProcessor } from '../field/displayProcessor';
|
import { getDisplayProcessor } from '../field/displayProcessor';
|
||||||
import { createTheme } from '../themes/createTheme';
|
import { createTheme } from '../themes/createTheme';
|
||||||
|
import { FieldType } from '../types/dataFrame';
|
||||||
|
|
||||||
import { CSVHeaderStyle, readCSV, toCSV } from './csv';
|
import { CSVHeaderStyle, readCSV, toCSV } from './csv';
|
||||||
|
|
||||||
@ -159,4 +160,23 @@ describe('DataFrame to CSV', () => {
|
|||||||
1589455688623,2020-05-14 11:28:08"
|
1589455688623,2020-05-14 11:28:08"
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle field type frame', () => {
|
||||||
|
const dataFrame = new MutableDataFrame({
|
||||||
|
fields: [
|
||||||
|
{ name: 'Time', values: [1589455688623] },
|
||||||
|
{
|
||||||
|
name: 'Value',
|
||||||
|
type: FieldType.frame,
|
||||||
|
values: [{ value: '1234' }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const csv = toCSV([dataFrame]);
|
||||||
|
expect(csv).toMatchInlineSnapshot(`
|
||||||
|
""Time","Value"
|
||||||
|
1589455688623,1234"
|
||||||
|
`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -309,7 +309,11 @@ export function toCSV(data: DataFrame[], config?: CSVConfig): string {
|
|||||||
csv = csv + config.delimiter;
|
csv = csv + config.delimiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
const v = fields[j].values[i];
|
let v = fields[j].values[i];
|
||||||
|
// For FieldType frame, use value if it exists to prevent exporting [object object]
|
||||||
|
if (fields[j].type === FieldType.frame && fields[j].values[i].value) {
|
||||||
|
v = fields[j].values[i].value;
|
||||||
|
}
|
||||||
if (v !== null) {
|
if (v !== null) {
|
||||||
csv = csv + writers[j](v);
|
csv = csv + writers[j](v);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user