Skip to content

Commit

Permalink
UIEXPMGR-106 Update logic related to download files (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaSedyx authored Apr 12, 2024
1 parent 3847b6f commit 92a767f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const ExportEdiJobDetailsActionMenu = ({

const onDownload = () => {
onToggle();
downloadSecurely(fileNames[0]);
downloadSecurely(fileNames);
};

const onResend = useCallback(async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/components/ExportJobId/ExportJobId.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 7 additions & 3 deletions src/common/hooks/useSecureDownload/useSecureDownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -29,5 +29,9 @@ export const useSecureDownload = (jobId) => {
});
};

const download = async (fileNames) => {
return Promise.all(fileNames.map(downloadSingleFile));
}

return { download };
};
4 changes: 2 additions & 2 deletions src/common/hooks/useSecureDownload/useSecureDownload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('useSecureDownload', () => {
() => useSecureDownload(jobId),
);

await result.current.download('fileName.csv');
await result.current.download(['fileName.csv']);

expect(kyGetMock).toHaveBeenCalled();
});
Expand All @@ -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`,
Expand Down

0 comments on commit 92a767f

Please sign in to comment.