Skip to content

Commit

Permalink
UIBULKED-497: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
UladzislauKutarkin committed Oct 25, 2024
1 parent af7b5fe commit b44e2b2
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const BulkEditInAppLayer = ({
downloadFile,
confirmChanges,
closePreviewModal,
setShouldRefetchStatus
} = useConfirmChanges({
queryDownloadKey: QUERY_KEY_DOWNLOAD_PREVIEW_MODAL,
updateFn: contentUpdate,
Expand Down Expand Up @@ -81,6 +82,7 @@ export const BulkEditInAppLayer = ({
onDownload={downloadFile}
onKeepEditing={closePreviewModal}
onChangesCommited={handleChangesCommited}
setShouldRefetchStatus={setShouldRefetchStatus}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const BulkEditPreviewModal = ({
onKeepEditing,
onDownload,
onChangesCommited,
setShouldRefetchStatus
}) => {
const callout = useShowCallout();
const intl = useIntl();
Expand Down Expand Up @@ -91,6 +92,7 @@ export const BulkEditPreviewModal = ({
bulkDetails={bulkDetails}
isPreviewEnabled={!isPreviewLoading}
onPreviewError={onKeepEditing}
setShouldRefetchStatus={setShouldRefetchStatus}
/>
</Modal>
);
Expand All @@ -103,4 +105,5 @@ BulkEditPreviewModal.propTypes = {
onKeepEditing: PropTypes.func,
onChangesCommited: PropTypes.func,
onDownload: PropTypes.func,
setShouldRefetchStatus: PropTypes.func
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react';
import React, { memo, useContext, useEffect, useState } from 'react';

Check warning on line 1 in src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'memo' is defined but never used. Allowed unused vars must match /React/u

Check warning on line 1 in src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'memo' is defined but never used. Allowed unused vars must match /React/u
import PropTypes from 'prop-types';
import {
FormattedMessage,
Expand Down Expand Up @@ -39,6 +39,7 @@ export const BulkEditPreviewModalList = ({
bulkDetails,
isPreviewEnabled,
onPreviewError,
setShouldRefetchStatus,

Check failure on line 42 in src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'setShouldRefetchStatus' is missing in props validation

Check failure on line 42 in src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'setShouldRefetchStatus' is missing in props validation
}) => {
const callout = useShowCallout();
const intl = useIntl();
Expand All @@ -50,6 +51,17 @@ export const BulkEditPreviewModalList = ({
} = usePagination(PAGINATION_CONFIG);

const visibleColumnKeys = getVisibleColumnsKeys(visibleColumns);
console.log('isPreviewEnabled:', isPreviewEnabled);

Check warning on line 54 in src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected console statement

Check warning on line 54 in src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected console statement
console.log('bulkDetails status:', bulkDetails?.status);

Check warning on line 55 in src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected console statement

Check warning on line 55 in src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditPreviewModalList.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected console statement
const [shouldFetch, setShouldFetch] = useState(false);

useEffect(() => {
if (isPreviewEnabled && ![JOB_STATUSES.DATA_MODIFICATION_IN_PROGRESS, JOB_STATUSES.DATA_MODIFICATION].includes(bulkDetails?.status)) {
setShouldFetch(true);
} else {
setShouldFetch(false);
}
}, [bulkDetails?.status, isPreviewEnabled]);

const {
contentData,
Expand All @@ -60,8 +72,9 @@ export const BulkEditPreviewModalList = ({
id: bulkDetails?.id,
step: EDITING_STEPS.EDIT,
capabilities: currentRecordType,
onSuccess: () => setShouldRefetchStatus(false),
queryOptions: {
enabled: isPreviewEnabled && bulkDetails?.status !== JOB_STATUSES.DATA_MODIFICATION_IN_PROGRESS,
enabled: shouldFetch,
onError: () => {
callout({
type: 'error',
Expand Down
1 change: 1 addition & 0 deletions src/components/shared/ProgressBar/ProgressBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const ProgressBar = () => {
const { bulkDetails, clearIntervalAndRedirect } = useBulkOperationDetails({
id,
interval: 1000 * 3,
shouldRefetch: true,
additionalQueryKeys: [step],
});

Expand Down
31 changes: 19 additions & 12 deletions src/hooks/api/useBulkOperationDetails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';

Check warning on line 1 in src/hooks/api/useBulkOperationDetails.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'useState' is defined but never used. Allowed unused vars must match /React/u

Check warning on line 1 in src/hooks/api/useBulkOperationDetails.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'useState' is defined but never used. Allowed unused vars must match /React/u
import { useQuery } from 'react-query';
import { useNamespace, useOkapiKy } from '@folio/stripes/core';
import { useHistory } from 'react-router-dom';
Expand All @@ -10,27 +10,34 @@ export const useBulkOperationDetails = ({
id,
interval = 0,
additionalQueryKeys = [],

Check warning on line 12 in src/hooks/api/useBulkOperationDetails.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'additionalQueryKeys' is assigned a value but never used. Allowed unused vars must match /React/u

Check warning on line 12 in src/hooks/api/useBulkOperationDetails.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'additionalQueryKeys' is assigned a value but never used. Allowed unused vars must match /React/u
shouldRefetch = false,
...options
}) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: BULK_OPERATION_DETAILS_KEY });
const history = useHistory();
const [refetchInterval, setRefetchInterval] = useState(interval);

const { data, isLoading } = useQuery({
queryKey: [BULK_OPERATION_DETAILS_KEY, namespaceKey, id, refetchInterval, ...additionalQueryKeys],
const { data, isLoading, refetch } = useQuery({
queryKey: [BULK_OPERATION_DETAILS_KEY, namespaceKey, id],
enabled: !!id,
refetchInterval,
queryFn: () => ky.get(`bulk-operations/${id}`).json(),
...options,
});

const clearInterval = () => {
setRefetchInterval(0);
};
const clearIntervalAndRedirect = (pathname, searchParams) => {
clearInterval();
useEffect(() => {
let intervalId;

if (shouldRefetch) {
intervalId = setInterval(() => {
refetch();
}, interval);
}

return () => {
clearInterval(intervalId);
};
}, [shouldRefetch, interval, refetch]);

const clearIntervalAndRedirect = (pathname, searchParams) => {
history.replace({
pathname,
search: searchParams ? buildSearch(searchParams, history.location.search) : '',
Expand All @@ -40,7 +47,7 @@ export const useBulkOperationDetails = ({
return {
bulkDetails: data,
isLoading,
clearInterval,
refetch,
clearIntervalAndRedirect,
};
};
11 changes: 10 additions & 1 deletion src/hooks/api/useRecordsPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useIntl } from 'react-intl';

import { useNamespace, useOkapiKy } from '@folio/stripes/core';

import noop from 'lodash/noop';
import { BULK_VISIBLE_COLUMNS } from '../../constants';
import { getMappedTableData } from '../../utils/mappers';
import { RootContext } from '../../context/RootContext';
Expand All @@ -21,7 +22,8 @@ export const useRecordsPreview = ({
limit,
offset,
criteria,
queryRecordType
queryRecordType,
onSuccess = noop,
}) => {
const intl = useIntl();
const { setVisibleColumns } = useContext(RootContext);
Expand Down Expand Up @@ -83,6 +85,13 @@ export const useRecordsPreview = ({
capabilities
]);

console.log(contentData);

Check warning on line 88 in src/hooks/api/useRecordsPreview.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected console statement

Check warning on line 88 in src/hooks/api/useRecordsPreview.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected console statement
useEffect(() => {
if (contentData?.length > 0) {
onSuccess();
}
}, [contentData, onSuccess]);

return {
isLoading,
refetch,
Expand Down
13 changes: 10 additions & 3 deletions src/hooks/useConfirmChanges.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useContext, useState } from 'react';

Check warning on line 1 in src/hooks/useConfirmChanges.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'useContext' is defined but never used. Allowed unused vars must match /React/u

Check warning on line 1 in src/hooks/useConfirmChanges.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'useContext' is defined but never used. Allowed unused vars must match /React/u
import { useIntl } from 'react-intl';
import { useQueryClient } from 'react-query';

Expand Down Expand Up @@ -32,8 +32,13 @@ export const useConfirmChanges = ({

const [isPreviewModalOpened, setIsPreviewModalOpened] = useState(false);
const [isPreviewLoading, setIsPreviewLoading] = useState(false);
const [shouldRefetchStatus, setShouldRefetchStatus] = useState(false);

const { bulkDetails } = useBulkOperationDetails({ id: bulkOperationId, interval: 1000 * 3 });
const { bulkDetails } = useBulkOperationDetails({
id: bulkOperationId,
interval: 1000 * 3,
shouldRefetch: shouldRefetchStatus,
});
const { bulkOperationStart } = useBulkOperationStart();

const totalRecords = bulkDetails?.totalNumOfRecords;
Expand All @@ -44,11 +49,13 @@ export const useConfirmChanges = ({

const closePreviewModal = () => {
setIsPreviewModalOpened(false);
setShouldRefetchStatus(false);
};

const confirmChanges = (payload) => {
setIsPreviewLoading(true);
setIsPreviewModalOpened(true);
setShouldRefetchStatus(true);

updateFn(payload)
.then(() => bulkOperationStart({
Expand All @@ -58,7 +65,6 @@ export const useConfirmChanges = ({
}))
.then(() => {
queryClient.invalidateQueries(BULK_OPERATION_DETAILS_KEY);
queryClient.invalidateQueries(PREVIEW_MODAL_KEY);
})
.catch(() => {
callout({
Expand Down Expand Up @@ -94,5 +100,6 @@ export const useConfirmChanges = ({
openPreviewModal,
closePreviewModal,
confirmChanges,
setShouldRefetchStatus
};
};

0 comments on commit b44e2b2

Please sign in to comment.