Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function exportSubscribers(props: ExportProps) {
const {networkId, enqueueSnackbar} = props;
let page = 1;
let token = undefined;
const currTs = Date.now();
const subscriberExport = new CsvBuilder(`subscribers_${currTs}.csv`)
.setDelimeter(',')
.setColumns(SUBSCRIBER_EXPORT_COLUMNS.map(columnDef => columnDef.title));
try {
// last page next_page_token is an empty string
while (token !== '') {
// $FlowIgnore
const subscriberRows: paginated_subscribers = await FetchSubscribers({
networkId,
token,
});
if (subscriberRows) {
page = page + 1;
token = subscriberRows.next_page_token;
}
const subscriberData = Object.keys(subscriberRows.subscribers).map(
rowData =>
).then(logRows => {
const data = logRows.map(rowData =>
LOG_COLUMNS.map(columnDef => rowData[columnDef.field]),
);
const currTs = Date.now();
new CsvBuilder(`logs_${currTs}.csv`)
.setDelimeter(EXPORT_DELIMITER)
.setColumns(LOG_COLUMNS.map(columnDef => columnDef.title))
.addRows(data)
.exportFile();
});
}
) {
try {
const logRows = await searchLogs(
networkId,
gatewayId,
0,
MAX_PAGE_ROW_COUNT,
start,
end,
q,
);
const data = logRows.map(rowData =>
LOG_COLUMNS.map(columnDef => rowData[columnDef.field]),
);
const currTs = Date.now();
new CsvBuilder(`logs_${currTs}.csv`)
.setDelimeter(EXPORT_DELIMITER)
.setColumns(LOG_COLUMNS.map(columnDef => columnDef.title))
.addRows(data)
.exportFile();
} catch (e) {
enqueueSnackbar(e?.message ?? 'error retrieving logs', {variant: 'error'});
}
}
defaultExportCsv = () => {
const columns = this.props.columns
.filter(columnDef => {
return !columnDef.hidden && columnDef.field && columnDef.export !== false;
})
.sort((a, b) => (a.tableData.columnOrder > b.tableData.columnOrder) ? 1 : -1);
const dataToExport = this.props.exportAllData ? this.props.data : this.props.renderData;
const data = dataToExport.map(rowData =>
columns.map(columnDef => {
return this.props.getFieldValue(rowData, columnDef);
})
);
const builder = new CsvBuilder((this.props.exportFileName || this.props.title || 'data') + '.csv');
builder
.setDelimeter(this.props.exportDelimiter)
.setColumns(columns.map(columnDef => columnDef.title))
.addRows(data)
.exportFile();
}
defaultExportCsv = () => {
const columns = this.props.columns
.filter(columnDef => {
return !columnDef.hidden && columnDef.field && columnDef.export !== false;
})
.sort((a, b) => (a.tableData.columnOrder > b.tableData.columnOrder) ? 1 : -1);
const dataToExport = this.props.exportAllData ? this.props.data : this.props.renderData;
const data = dataToExport.map(rowData =>
columns.map(columnDef => {
return this.props.getFieldValue(rowData, columnDef);
})
);
const builder = new CsvBuilder((this.props.exportFileName || this.props.title || 'data') + '.csv');
builder
.setDelimeter(this.props.exportDelimiter)
.setColumns(columns.map(columnDef => columnDef.title))
.addRows(data)
.exportFile();
}