mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-03 14:57:22 +03:00
Fixed headers when exporting visits to CSV
This commit is contained in:
parent
843f646264
commit
71468379bd
5 changed files with 7 additions and 14 deletions
2
shlink-web-client.d.ts
vendored
2
shlink-web-client.d.ts
vendored
|
@ -10,7 +10,7 @@ declare module 'event-source-polyfill' {
|
|||
declare module 'csvjson' {
|
||||
export declare class CsvJson {
|
||||
public toObject<T>(content: string): T[];
|
||||
public toCSV<T>(data: T[], options: { headers: string }): string;
|
||||
public toCSV<T>(data: T[], options: { headers: 'full' | 'none' | 'relative' | 'key' }): string;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { dissoc, head, keys, values } from 'ramda';
|
||||
import { dissoc, values } from 'ramda';
|
||||
import { CsvJson } from 'csvjson';
|
||||
import LocalStorage from '../../utils/services/LocalStorage';
|
||||
import { ServersMap } from '../data';
|
||||
|
@ -17,9 +17,7 @@ export default class ServersExporter {
|
|||
const servers = values(this.storage.get<ServersMap>('servers') ?? {}).map(dissoc('id'));
|
||||
|
||||
try {
|
||||
const csv = this.csvjson.toCSV(servers, {
|
||||
headers: keys(head(servers)).join(','),
|
||||
});
|
||||
const csv = this.csvjson.toCSV(servers, { headers: 'key' });
|
||||
|
||||
saveCsv(this.window, csv, SERVERS_FILENAME);
|
||||
} catch (e) {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { isEmpty, propEq, values } from 'ramda';
|
|||
import { useState, useEffect, useMemo, FC } from 'react';
|
||||
import { Button, Card, Nav, NavLink, Progress, Row } from 'reactstrap';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faCalendarAlt, faMapMarkedAlt, faList, faChartPie, faFileExport } from '@fortawesome/free-solid-svg-icons';
|
||||
import { faCalendarAlt, faMapMarkedAlt, faList, faChartPie, faFileDownload } from '@fortawesome/free-solid-svg-icons';
|
||||
import { IconDefinition } from '@fortawesome/fontawesome-common-types';
|
||||
import { Route, Switch, NavLink as RouterNavLink, Redirect } from 'react-router-dom';
|
||||
import { Location } from 'history';
|
||||
|
@ -274,7 +274,7 @@ const VisitsStats: FC<VisitsStatsProps> = (
|
|||
className="btn-md-block"
|
||||
onClick={() => exportCsv(normalizedVisits)}
|
||||
>
|
||||
Export ({normalizedVisits.length}) <FontAwesomeIcon icon={faFileExport} />
|
||||
<FontAwesomeIcon icon={faFileDownload} /> Export ({normalizedVisits.length})
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -13,10 +13,7 @@ export class VisitsExporter {
|
|||
return;
|
||||
}
|
||||
|
||||
const [ firstVisit ] = visits;
|
||||
const csv = this.csvjson.toCSV(visits, {
|
||||
headers: Object.keys(firstVisit).join(','),
|
||||
});
|
||||
const csv = this.csvjson.toCSV(visits, { headers: 'key' });
|
||||
|
||||
saveCsv(this.window, csv, filename);
|
||||
};
|
||||
|
|
|
@ -44,9 +44,7 @@ describe('VisitsExporter', () => {
|
|||
|
||||
exporter.exportVisits('my_visits.csv', visits);
|
||||
|
||||
expect(toCSV).toHaveBeenCalledWith(visits, {
|
||||
headers: 'browser,city,country,date,latitude,longitude,os,referer',
|
||||
});
|
||||
expect(toCSV).toHaveBeenCalledWith(visits, { headers: 'key' });
|
||||
});
|
||||
|
||||
it('skips execution when list of visits is empty', () => {
|
||||
|
|
Loading…
Reference in a new issue