CSV Export: FieldType.other objects will be stringified (#113854)
This commit is contained in:
@@ -181,6 +181,26 @@ describe('DataFrame to CSV', () => {
|
||||
`);
|
||||
});
|
||||
|
||||
it('should handle field type other', () => {
|
||||
const dataFrame = new MutableDataFrame({
|
||||
fields: [
|
||||
{ name: 'Time', values: [1589455688623, 1589455692345] },
|
||||
{
|
||||
name: 'Value',
|
||||
type: FieldType.other,
|
||||
values: [{ text: 'value1' }, { text: 'value2' }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const csv = toCSV([dataFrame]);
|
||||
expect(csv).toMatchInlineSnapshot(`
|
||||
""Time","Value"
|
||||
1589455688623,"{""text"":""value1""}"
|
||||
1589455692345,"{""text"":""value2""}""
|
||||
`);
|
||||
});
|
||||
|
||||
it('should handle null values', () => {
|
||||
const dataFrame = new MutableDataFrame({
|
||||
fields: [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Libraries
|
||||
import { defaults } from 'lodash';
|
||||
import { defaults, isObject } from 'lodash';
|
||||
import Papa, { ParseConfig, Parser, ParseResult } from 'papaparse';
|
||||
|
||||
// Types
|
||||
@@ -317,6 +317,10 @@ export function toCSV(data: DataFrame[], config?: CSVConfig): string {
|
||||
v = v.value;
|
||||
}
|
||||
|
||||
if (fields[j].type === FieldType.other && isObject(v)) {
|
||||
v = JSON.stringify(v);
|
||||
}
|
||||
|
||||
csv += writers[j](v);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user