[v10.0.x] PanelInspect: Download CSV without extra blank rows (#71290)

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

(cherry picked from commit 8a6c6c3285)

Co-authored-by: Juan Cabanas <juan.cabanas@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2023-07-10 12:28:31 -03:00
committed by GitHub
co-authored by Juan Cabanas
parent c7031f48d4
commit 84594e2fba
3 changed files with 14 additions and 13 deletions
+3 -9
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"
`);
});
});
+10 -3
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;
@@ -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);