diff --git a/CHANGELOG.md b/CHANGELOG.md index 536eb16..1d84988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## (IN PROGRESS) * Update HTML Page Title on Export Manager Tabs Page. Refs UIEXPMGR-105. +* Update logic related to download files. Refs UIEXPMGR-106. ## [3.1.0](https://github.com/folio-org/ui-export-manager/tree/v3.1.0) (2024-03-19) [Full Changelog](https://github.com/folio-org/ui-export-manager/compare/v3.0.0...v3.1.0) diff --git a/src/ExportEdiJobs/ExportEdiJobDetailsActionMenu/ExportEdiJobDetailsActionMenu.js b/src/ExportEdiJobs/ExportEdiJobDetailsActionMenu/ExportEdiJobDetailsActionMenu.js index 1962576..a5540a4 100644 --- a/src/ExportEdiJobs/ExportEdiJobDetailsActionMenu/ExportEdiJobDetailsActionMenu.js +++ b/src/ExportEdiJobs/ExportEdiJobDetailsActionMenu/ExportEdiJobDetailsActionMenu.js @@ -73,7 +73,7 @@ export const ExportEdiJobDetailsActionMenu = ({ const onDownload = () => { onToggle(); - downloadSecurely(fileNames[0]); + downloadSecurely(fileNames); }; const onResend = useCallback(async () => { diff --git a/src/common/components/ExportJobId/ExportJobId.js b/src/common/components/ExportJobId/ExportJobId.js index 982d8e7..065958f 100644 --- a/src/common/components/ExportJobId/ExportJobId.js +++ b/src/common/components/ExportJobId/ExportJobId.js @@ -32,7 +32,7 @@ export const ExportJobId = ({ job }) => { e.stopPropagation(); if (EXPORTED_JOB_TYPES.includes(jobType)) { - downloadSecurely(fileNames[0]); + downloadSecurely(fileNames); } else { files.forEach((file, index) => { if (file && index !== 2) { diff --git a/src/common/constants.js b/src/common/constants.js index 930307a..4bd08d7 100644 --- a/src/common/constants.js +++ b/src/common/constants.js @@ -16,6 +16,9 @@ export const EXPORT_JOB_STATUS_OPTIONS = Object.values(EXPORT_JOB_STATUSES).map( export const EXPORT_CONFIGS_API = 'data-export-spring/configs'; export const EXPORT_JOBS_API = 'data-export-spring/jobs'; export const EXPORTED_JOB_TYPES = [ + 'BULK_EDIT_IDENTIFIERS', + 'BULK_EDIT_QUERY', + 'BULK_EDIT_UPDATE', 'CIRCULATION_LOG', 'E_HOLDINGS', 'AUTH_HEADINGS_UPDATES', diff --git a/src/common/hooks/useSecureDownload/useSecureDownload.js b/src/common/hooks/useSecureDownload/useSecureDownload.js index fe5d707..5575795 100644 --- a/src/common/hooks/useSecureDownload/useSecureDownload.js +++ b/src/common/hooks/useSecureDownload/useSecureDownload.js @@ -13,13 +13,13 @@ export const useSecureDownload = (jobId) => { const ky = useOkapiKy(); const showCallout = useShowCallout(); - const download = async (fileName) => { - return ky.get(`${EXPORT_JOBS_API}/${jobId}/download`, { + const downloadSingleFile = async (fileName) => { + return ky.get(`${EXPORT_JOBS_API}/${jobId}/download?key=${fileName}`, { headers: { accept: 'application/octet-stream' }, }) .blob() .then(data => { - downloadBase64(fileName, URL.createObjectURL(data)); + downloadBase64(fileName.replace(`${jobId}/`, ''), URL.createObjectURL(data)); }) .catch(() => { showCallout({ @@ -29,5 +29,9 @@ export const useSecureDownload = (jobId) => { }); }; + const download = async (fileNames) => { + return Promise.all(fileNames.map(downloadSingleFile)); + } + return { download }; }; diff --git a/src/common/hooks/useSecureDownload/useSecureDownload.test.js b/src/common/hooks/useSecureDownload/useSecureDownload.test.js index e3634ef..0b01476 100644 --- a/src/common/hooks/useSecureDownload/useSecureDownload.test.js +++ b/src/common/hooks/useSecureDownload/useSecureDownload.test.js @@ -42,7 +42,7 @@ describe('useSecureDownload', () => { () => useSecureDownload(jobId), ); - await result.current.download('fileName.csv'); + await result.current.download(['fileName.csv']); expect(kyGetMock).toHaveBeenCalled(); }); @@ -54,7 +54,7 @@ describe('useSecureDownload', () => { () => useSecureDownload(jobId), ); - await result.current.download('fileName.csv'); + await result.current.download(['fileName.csv']); expect(showCallout).toHaveBeenCalledWith(expect.objectContaining({ messageId: toastMessage`download.error`,