From 56286423cbfee2ce7269b6f4bb3c5926fe2e7ddd Mon Sep 17 00:00:00 2001 From: vashjs <86330150+vashjs@users.noreply.github.com> Date: Mon, 30 Oct 2023 06:55:40 +0000 Subject: [PATCH] UIBULKED-354 Two identical files with the preview of proposed changes are downloaded from Logs (#402) --- CHANGELOG.md | 1 + src/components/BulkEditActionMenu/BulkEditActionMenu.js | 7 ++++++- .../BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js | 2 ++ .../BulkEditLogsActions/BulkEditLogsActions.js | 3 ++- src/hooks/api/useFileDownload.js | 7 ++++++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a7cf796..02fe7f44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [UIBULKED-355](https://issues.folio.org/browse/UIBULKED-355) Remove reference to Query tab on the landing page. * [UIBULKED-315](https://issues.folio.org/browse/UIBULKED-315) Group holdings record properties using optgroup component +* [UIBULKED-354](https://issues.folio.org/browse/UIBULKED-354) Two identical files with the preview of proposed changes are downloaded from Logs ## [4.0.0](https://github.com/folio-org/ui-bulk-edit/tree/v4.0.0) (2023-10-12) diff --git a/src/components/BulkEditActionMenu/BulkEditActionMenu.js b/src/components/BulkEditActionMenu/BulkEditActionMenu.js index e715dd1e..93176639 100644 --- a/src/components/BulkEditActionMenu/BulkEditActionMenu.js +++ b/src/components/BulkEditActionMenu/BulkEditActionMenu.js @@ -26,7 +26,11 @@ import { usePathParams, } from '../../hooks'; import { RootContext } from '../../context/RootContext'; -import { useBulkOperationDetails, useFileDownload } from '../../hooks/api'; +import { + QUERY_KEY_DOWNLOAD_ACTION_MENU, + useBulkOperationDetails, + useFileDownload +} from '../../hooks/api'; const BulkEditActionMenu = ({ onEdit, @@ -57,6 +61,7 @@ const BulkEditActionMenu = ({ useFileDownload({ + queryKey: QUERY_KEY_DOWNLOAD_ACTION_MENU, enabled: !!fileInfo, id, fileInfo: { diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js index 956eb279..40905310 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js @@ -23,6 +23,7 @@ import { useBulkOperationDetails, useContentUpdate, useFileDownload, + QUERY_KEY_DOWNLOAD_IN_APP, } from '../../../../hooks/api'; import { getContentUpdatesBody } from '../BulkEditInApp/ContentUpdatesForm/helpers'; @@ -75,6 +76,7 @@ const BulkEditInAppPreviewModal = ({ }); const { refetch } = useFileDownload({ + queryKey: QUERY_KEY_DOWNLOAD_IN_APP, enabled: false, // to prevent automatic file fetch in preview modal id: bulkOperationId, fileInfo: { diff --git a/src/components/BulkEditLogs/BulkEditLogsActions/BulkEditLogsActions.js b/src/components/BulkEditLogs/BulkEditLogsActions/BulkEditLogsActions.js index 8201b77f..177eb1a3 100644 --- a/src/components/BulkEditLogs/BulkEditLogsActions/BulkEditLogsActions.js +++ b/src/components/BulkEditLogs/BulkEditLogsActions/BulkEditLogsActions.js @@ -15,7 +15,7 @@ import { InfoPopover, } from '@folio/stripes/components'; import { FormattedMessage } from 'react-intl'; -import { useFileDownload } from '../../../hooks/api'; +import { QUERY_KEY_DOWNLOAD_LOGS, useFileDownload } from '../../../hooks/api'; import { CAPABILITIES, linkNamesMap } from '../../../constants'; import { useBulkPermissions } from '../../../hooks'; @@ -26,6 +26,7 @@ const BulkEditLogsActions = ({ item }) => { } = useBulkPermissions(); const [triggeredFile, setTriggeredFile] = useState(null); const { refetch } = useFileDownload({ + queryKey: QUERY_KEY_DOWNLOAD_LOGS, enabled: false, id: item.id, fileInfo: { diff --git a/src/hooks/api/useFileDownload.js b/src/hooks/api/useFileDownload.js index 388df3e3..2090d0a1 100644 --- a/src/hooks/api/useFileDownload.js +++ b/src/hooks/api/useFileDownload.js @@ -1,17 +1,22 @@ import { useQuery } from 'react-query'; import { useOkapiKy } from '@folio/stripes/core'; +export const QUERY_KEY_DOWNLOAD_LOGS = 'downloadLogs'; +export const QUERY_KEY_DOWNLOAD_ACTION_MENU = 'downloadActionMenu'; +export const QUERY_KEY_DOWNLOAD_IN_APP = 'downloadInApp'; + export const useFileDownload = ({ id, fileInfo, onSuccess, + queryKey, ...queryProps }) => { const ky = useOkapiKy(); const { refetch } = useQuery( { - queryKey: ['downloadFile', id, fileInfo], + queryKey: [queryKey, id, fileInfo], queryFn: () => ky.get(`bulk-operations/${id}/download`, { searchParams: { fileContentType: fileInfo?.fileContentType }, }).blob(),