PanelInspect: Download CSV without extra blank rows (#71248)

This commit is contained in:
Juan Cabanas
2023-07-10 12:16:47 -03:00
committed by GitHub
parent 9f2baaf5c3
commit 8a6c6c3285
3 changed files with 14 additions and 13 deletions

View File

@@ -104,9 +104,7 @@ describe('write csv', () => {
"sep=,
"Time","Value"
1598784913123,1234
1598784914123,5678
"
1598784914123,5678"
`);
});
});
@@ -131,9 +129,7 @@ describe('DataFrame to CSV', () => {
const csv = toCSV([dataFrame]);
expect(csv).toMatchInlineSnapshot(`
""Time","{label1=""value1"", label2=""value1""}"
1589455688623,1234
"
1589455688623,1234"
`);
});
@@ -160,9 +156,7 @@ describe('DataFrame to CSV', () => {
const csv = toCSV([dataFrame]);
expect(csv).toMatchInlineSnapshot(`
""Time","Value"
1589455688623,2020-05-14 11:28:08
"
1589455688623,2020-05-14 11:28:08"
`);
});
});

View File

@@ -273,7 +273,8 @@ export function toCSV(data: DataFrame[], config?: CSVConfig): string {
});
let csv = config.useExcelHeader ? `sep=${config.delimiter}${config.newline}` : '';
for (const series of data) {
for (let s = 0; s < data.length; s++) {
const series = data[s];
const { fields } = series;
// ignore frames with no fields
@@ -313,10 +314,16 @@ export function toCSV(data: DataFrame[], config?: CSVConfig): string {
csv = csv + writers[j](v);
}
}
csv = csv + config.newline;
if (i !== length - 1) {
csv = csv + config.newline;
}
}
}
csv = csv + config.newline;
if (s !== data.length - 1) {
csv = csv + config.newline;
}
}
return csv;

View File

@@ -37,7 +37,7 @@ describe('inspector download', () => {
},
};
it.each([[dataFrameFromJSON(json), 'test', '"time","name","value"\r\n100,a,1\r\n\r\n']])(
it.each([[dataFrameFromJSON(json), 'test', '"time","name","value"\r\n100,a,1']])(
'should, when logsModel is %s and title is %s, resolve in %s',
async (dataFrame, title, expected) => {
downloadDataFrameAsCsv(dataFrame, title);