Skip to content

Commit

Permalink
feat: add confirmation for large CSV downloads (#1322)
Browse files Browse the repository at this point in the history
- Prompt users with a confirmation dialog for downloads with over 2500 records
- Default to synchronous download when record count is small or user cancels
- Preserve asynchronous download for large downloads upon user confirmation
  • Loading branch information
tabiodun authored Jan 29, 2025
1 parent 7851473 commit 41bbb8f
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions src/pages/Work.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1886,14 +1886,38 @@ export default defineComponent({
params.skip_size_warning = true;
}
const response = await axios.get(
`${
import.meta.env.VITE_APP_API_BASE_URL
}/worksites_download/download_csv_async`,
{
params,
},
);
let url = `worksites_download/download_csv`;
if (
filteredWorksiteCount.value > 2500 ||
(filteredWorksiteCount.value === 0 && allWorksiteCount.value > 2500)
) {
const result = await confirm({
title: t('~~Large CSV Download warning'),
content: t(
'~~This CSV download contains over 2500 records. Please consider filtering your results to reduce the size of the download. Do you want to continue with this download?',
),
actions: {
yes: {
text: t('actions.yes'),
type: 'solid',
},
no: {
text: t('actions.no'),
type: 'outline',
},
},
});
if (result === 'yes') {
url = `worksites_download/download_csv_async`;
} else {
return;
}
}
const response = await axios.get(url, {
params,
});
switch (response.status) {
case 202: {
await component({
Expand Down

0 comments on commit 41bbb8f

Please sign in to comment.