mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-18 13:33:51 +00:00
Move some modules from src to shlink-web-component
This commit is contained in:
30
shlink-web-component/utils/services/ReportExporter.ts
Normal file
30
shlink-web-component/utils/services/ReportExporter.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { JsonToCsv } from '../../../src/utils/helpers/csvjson';
|
||||
import { saveCsv } from '../../../src/utils/helpers/files';
|
||||
import type { ExportableShortUrl } from '../../short-urls/data';
|
||||
import type { NormalizedVisit } from '../../visits/types';
|
||||
|
||||
export class ReportExporter {
|
||||
public constructor(private readonly window: Window, private readonly jsonToCsv: JsonToCsv) {
|
||||
}
|
||||
|
||||
public readonly exportVisits = (filename: string, visits: NormalizedVisit[]) => {
|
||||
if (!visits.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.exportCsv(filename, visits);
|
||||
};
|
||||
|
||||
public readonly exportShortUrls = (shortUrls: ExportableShortUrl[]) => {
|
||||
if (!shortUrls.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.exportCsv('short_urls.csv', shortUrls);
|
||||
};
|
||||
|
||||
private readonly exportCsv = (filename: string, rows: object[]) => {
|
||||
const csv = this.jsonToCsv(rows);
|
||||
saveCsv(this.window, csv, filename);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user