Skip to content

Commit 41bbb8f

Browse files
authored
feat: add confirmation for large CSV downloads (#1322)
- 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
1 parent 7851473 commit 41bbb8f

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

src/pages/Work.vue

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,14 +1886,38 @@ export default defineComponent({
18861886
params.skip_size_warning = true;
18871887
}
18881888
1889-
const response = await axios.get(
1890-
`${
1891-
import.meta.env.VITE_APP_API_BASE_URL
1892-
}/worksites_download/download_csv_async`,
1893-
{
1894-
params,
1895-
},
1896-
);
1889+
let url = `worksites_download/download_csv`;
1890+
1891+
if (
1892+
filteredWorksiteCount.value > 2500 ||
1893+
(filteredWorksiteCount.value === 0 && allWorksiteCount.value > 2500)
1894+
) {
1895+
const result = await confirm({
1896+
title: t('~~Large CSV Download warning'),
1897+
content: t(
1898+
'~~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?',
1899+
),
1900+
actions: {
1901+
yes: {
1902+
text: t('actions.yes'),
1903+
type: 'solid',
1904+
},
1905+
no: {
1906+
text: t('actions.no'),
1907+
type: 'outline',
1908+
},
1909+
},
1910+
});
1911+
if (result === 'yes') {
1912+
url = `worksites_download/download_csv_async`;
1913+
} else {
1914+
return;
1915+
}
1916+
}
1917+
1918+
const response = await axios.get(url, {
1919+
params,
1920+
});
18971921
switch (response.status) {
18981922
case 202: {
18991923
await component({

0 commit comments

Comments
 (0)