plane/web/helpers/download.helper.ts
Aaryan Khandelwal b2ac7b9ac6
chore: revamp the API tokens workflow (#2880)
* chore: added getLayout method to api tokens pages

* revamp: api tokens workflow

* chore: add title validation and update types

* chore: minor UI updates

* chore: update route
2023-11-27 12:14:06 +05:30

15 lines
574 B
TypeScript

export const csvDownload = (data: Array<Array<string>> | { [key: string]: string }, name: string) => {
const rows = Array.isArray(data) ? [...data] : [Object.keys(data), Object.values(data)];
const csvContent = "data:text/csv;charset=utf-8," + rows.map((e) => e.join(",")).join("\n");
const encodedUri = encodeURI(csvContent);
const link = document.createElement("a");
link.href = encodedUri;
link.download = `${name}.csv`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link); // Cleanup after the download link is clicked
};