mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-02 22:01:52 +00:00
Created VisitsExporter test
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { CsvJson } from 'csvjson';
|
||||
import { head, keys } from 'ramda';
|
||||
import { NormalizedVisit } from '../types';
|
||||
import { saveCsv } from '../../utils/helpers/csv';
|
||||
|
||||
@@ -10,15 +9,15 @@ export class VisitsExporter {
|
||||
) {}
|
||||
|
||||
public readonly exportVisits = (filename: string, visits: NormalizedVisit[]) => {
|
||||
try {
|
||||
const csv = this.csvjson.toCSV(visits, {
|
||||
headers: keys(head(visits)).join(','),
|
||||
});
|
||||
|
||||
saveCsv(this.window, csv, filename);
|
||||
} catch (e) {
|
||||
// FIXME Handle error
|
||||
console.error(e);
|
||||
if (!visits.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [ firstVisit ] = visits;
|
||||
const csv = this.csvjson.toCSV(visits, {
|
||||
headers: Object.keys(firstVisit).join(','),
|
||||
});
|
||||
|
||||
saveCsv(this.window, csv, filename);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user