forked from github/plane
b2ac7b9ac6
* 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
15 lines
574 B
TypeScript
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
|
|
};
|