feat: download test cases csv (#219)
This commit is contained in:
@@ -132,4 +132,33 @@ async function deleteCases(jwt: string, deleteCaseIds: number[], projectId: numb
|
||||
}
|
||||
}
|
||||
|
||||
export { fetchCase, fetchCases, updateCase, createCase, deleteCases };
|
||||
async function csvDownload(jwt: string, folderId: number) {
|
||||
const url = `${apiServer}/cases/download?folderId=${folderId}&type=csv`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const objectUrl = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = objectUrl;
|
||||
a.download = `folder_${folderId}.csv`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
window.URL.revokeObjectURL(objectUrl);
|
||||
} catch (error: any) {
|
||||
console.error('Error fetching data:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
export { fetchCase, fetchCases, updateCase, createCase, deleteCases, csvDownload };
|
||||
|
||||
Reference in New Issue
Block a user