fix csv export (#466)

* style: cleanup formatting

* fix: prevent issues with csv export

* chore: update test snapshots
This commit is contained in:
Carlos Valente
2023-07-23 15:06:25 +02:00
committed by GitHub
parent 3603b836f6
commit bb1eb2838f
4 changed files with 13 additions and 8 deletions
@@ -76,12 +76,18 @@ export default function CuesheetWrapper() {
const sheetData = makeTable(headerData, rundown, userFields);
const csvContent = makeCSV(sheetData);
const encodedUri = encodeURI(csvContent);
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.setAttribute('href', encodedUri);
link.setAttribute('href', url);
link.setAttribute('download', 'ontime export.csv');
document.body.appendChild(link);
link.click();
// Clean up the URL.createObjectURL to release resources
URL.revokeObjectURL(url);
},
[rundown, userFields],
);
@@ -84,7 +84,7 @@ describe('make CSV()', () => {
it('joins an array of arrays with commas and newlines', () => {
const testdata = [['field'], ['after newline', 'after comma'], ['', 'after empty']];
expect(makeCSV(testdata)).toMatchInlineSnapshot(`
"data:text/csv;charset=utf-8,field
"field
after newline,after comma
,after empty
"
@@ -49,13 +49,13 @@ function MakeTimer({ getValue, row: { original } }: CellContext<OntimeRundownEnt
const cellValue = (getValue() as number | null) ?? 0;
const delayValue = (original as OntimeEvent)?.delay ?? 0;
console.log(delayValue)
return (
<span className={style.time}>
<DelayIndicator delayValue={delayValue} />
{millisToString(cellValue)}
{(delayValue !== 0 && showDelayedTimes) && <span className={style.delayedTime}>{` ${millisToString(cellValue + delayValue)}`}</span>}
{delayValue !== 0 && showDelayedTimes && (
<span className={style.delayedTime}>{` ${millisToString(cellValue + delayValue)}`}</span>
)}
</span>
);
}
@@ -108,7 +108,6 @@ export const makeTable = (headerData: EventData, rundown: OntimeRundown, userFie
* @return {string}
*/
export const makeCSV = (arrayOfArrays: string[][]) => {
const csvData = 'data:text/csv;charset=utf-8,';
const stringifiedData = stringify(arrayOfArrays);
return csvData + stringifiedData;
return stringifiedData;
};