Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIBULKED-497: "Are you sure" preview displays outdated values after User changed selection on bulk edit form and clicked "Confirm changes" #626

Closed
wants to merge 8 commits into from
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 @@ -40,6 +40,7 @@
bulkDetails,
isPreviewEnabled,
onPreviewError,
setShouldRefetchStatus,

Check failure on line 43 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 43 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 @@ -52,6 +53,17 @@
} = usePagination(PAGINATION_CONFIG);

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

Check warning on line 56 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 56 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 57 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 57 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 @@ -62,8 +74,10 @@
id: bulkDetails?.id,
step: EDITING_STEPS.EDIT,
capabilities: currentRecordType,
onSuccess: () => setShouldRefetchStatus(false),
queryOptions: {
enabled: shouldFetch,
enabled: isPreviewEnabled && bulkDetails?.status !== JOB_STATUSES.DATA_MODIFICATION_IN_PROGRESS,

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

View workflow job for this annotation

GitHub Actions / github-actions-ci

Duplicate key 'enabled'

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

View workflow job for this annotation

GitHub Actions / github-actions-ci

Duplicate key 'enabled'
onSuccess: showErrorMessage,
onError: () => {
callout({
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 @@ -5,7 +5,7 @@
import { Icon, Loading } from '@folio/stripes/components';
import { useShowCallout } from '@folio/stripes-acq-components';

import { useBulkOperationDetails } from '../../../hooks/api';

Check failure on line 8 in src/components/shared/ProgressBar/ProgressBar.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

useBulkOperationDetails not found in '../../../hooks/api'

Check failure on line 8 in src/components/shared/ProgressBar/ProgressBar.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

useBulkOperationDetails not found in '../../../hooks/api'
import { EDITING_STEPS, ERRORS, JOB_STATUSES } from '../../../constants';
import { getBulkOperationStep } from './utils';
import css from './ProgressBar.css';
Expand All @@ -24,6 +24,7 @@
const { bulkDetails, clearIntervalAndRedirect } = useBulkOperationDetails({
id,
interval: 1000 * 3,
shouldRefetch: true,
additionalQueryKeys: [step],
});

Expand Down
31 changes: 22 additions & 9 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';
import { useQuery } from 'react-query';
import { useNamespace, useOkapiKy } from '@folio/stripes/core';
import { useHistory } from 'react-router-dom';
Expand All @@ -12,21 +12,34 @@ export const useBulkOperationDetails = ({
id,
interval = 0,
additionalQueryKeys = [],
shouldRefetch = false,
...options
}) => {
const ky = useOkapiKy();
const [namespaceKey] = useNamespace({ key: BULK_OPERATION_DETAILS_KEY });
const history = useHistory();
const [refetchInterval, setRefetchInterval] = useState(interval);
const { showErrorMessage } = useErrorMessages();
const { data, isLoading, refetch } = useQuery({
queryKey: [BULK_OPERATION_DETAILS_KEY, namespaceKey, id],
enabled: !!id,
queryFn: () => ky.get(`bulk-operations/${id}`).json(),
...options,
});

const clearInterval = () => {
setRefetchInterval(0);
};
useEffect(() => {
let intervalId;

const clearIntervalAndRedirect = (pathname, searchParams) => {
clearInterval();
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 Down Expand Up @@ -61,7 +74,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 { 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 @@
limit,
offset,
criteria,
queryRecordType
queryRecordType,
onSuccess = noop,
}) => {
const intl = useIntl();
const { setVisibleColumns } = useContext(RootContext);
Expand Down Expand Up @@ -83,6 +85,13 @@
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,11 +1,11 @@
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';

import { useShowCallout } from '@folio/stripes-acq-components';

import {
PREVIEW_MODAL_KEY,

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

View workflow job for this annotation

GitHub Actions / github-actions-ci

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

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

View workflow job for this annotation

GitHub Actions / github-actions-ci

'PREVIEW_MODAL_KEY' is defined but never used. Allowed unused vars must match /React/u
BULK_OPERATION_DETAILS_KEY,
useBulkOperationDetails,
useBulkOperationStart,
Expand All @@ -32,8 +32,13 @@

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 @@

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 @@
}))
.then(() => {
queryClient.invalidateQueries(BULK_OPERATION_DETAILS_KEY);
queryClient.invalidateQueries(PREVIEW_MODAL_KEY);
})
.catch(() => {
callout({
Expand Down Expand Up @@ -94,5 +100,6 @@
openPreviewModal,
closePreviewModal,
confirmChanges,
setShouldRefetchStatus
};
};
Loading