Skip to content

Commit

Permalink
UIBULKED-354 Two identical files with the preview of proposed changes…
Browse files Browse the repository at this point in the history
… are downloaded from Logs (#402)
  • Loading branch information
vashjs authored Oct 30, 2023
1 parent 60b331e commit 5628642
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 6 additions & 1 deletion src/components/BulkEditActionMenu/BulkEditActionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,6 +61,7 @@ const BulkEditActionMenu = ({


useFileDownload({
queryKey: QUERY_KEY_DOWNLOAD_ACTION_MENU,
enabled: !!fileInfo,
id,
fileInfo: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
useBulkOperationDetails,
useContentUpdate,
useFileDownload,
QUERY_KEY_DOWNLOAD_IN_APP,
} from '../../../../hooks/api';

import { getContentUpdatesBody } from '../BulkEditInApp/ContentUpdatesForm/helpers';
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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: {
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/api/useFileDownload.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down

0 comments on commit 5628642

Please sign in to comment.