-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dashboard: Add export endpoint to API
Also create a utility download function that downloads the CSV file as a blob.
- Loading branch information
Kevin Seestrand
authored and
Kevin Seestrand
committed
May 24, 2022
1 parent
416fdcc
commit 61c14fc
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function download(data: string, fileName: string): void { | ||
const blob: Blob = new Blob([data], { type: 'text/csv' }); | ||
const blobURL: string = window.URL.createObjectURL(blob) | ||
|
||
const downloadLink: HTMLAnchorElement = document.createElement('a'); | ||
downloadLink.style.display = 'none'; | ||
downloadLink.href = blobURL; | ||
downloadLink.setAttribute('download', fileName); | ||
|
||
document.body.appendChild(downloadLink); | ||
downloadLink.click(); | ||
setTimeout(function() { | ||
document.body.removeChild(downloadLink); | ||
window.URL.revokeObjectURL(blobURL); | ||
}, 200) | ||
} |