From a6d78a6259d74629f3bd65afbccfd1ed31f82a58 Mon Sep 17 00:00:00 2001 From: vashjs Date: Thu, 23 Jan 2025 11:24:33 +0100 Subject: [PATCH 01/12] UIBULKED-588 Displaying errors and warnings --- .../ErrorsAccordion/ErrorsAccordion.js | 34 +++++++++++++------ .../BulkEditListResult/Preview/Preview.js | 13 ++++++- src/components/shared/ProgressBar/utils.js | 2 +- src/constants/core.js | 5 +++ src/hooks/api/useErrorsPreview.js | 5 +-- src/hooks/useBulkOperationStats.js | 7 ++++ src/hooks/useErrorType.js | 22 ++++++++++++ 7 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 src/hooks/useErrorType.js diff --git a/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js b/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js index 81373cbe..d86d957c 100644 --- a/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js +++ b/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js @@ -12,7 +12,7 @@ import { useStripes } from '@folio/stripes/core'; import { PrevNextPagination } from '@folio/stripes-acq-components'; import css from '../Preview.css'; import { useSearchParams } from '../../../../../hooks'; -import { CAPABILITIES, ERROR_PARAMETERS_KEYS } from '../../../../../constants'; +import { CAPABILITIES, ERROR_PARAMETERS_KEYS, ERROR_TYPES } from '../../../../../constants'; const getParam = (error, key) => error.parameters.find(param => param.key === key)?.value; @@ -24,6 +24,14 @@ const columnMapping = { const visibleColumns = Object.keys(columnMapping); +const renderErrorType = (error) => { + if (error.type === ERROR_TYPES.ERROR) { + return ; + } + + return ; +}; + const renderErrorMessage = (error, isLinkAvailable) => { const link = getParam(error, ERROR_PARAMETERS_KEYS.LINK); @@ -45,16 +53,19 @@ const renderErrorMessage = (error, isLinkAvailable) => { }; const getResultsFormatter = ({ isLinkAvailable }) => ({ - type: () => , + type: renderErrorType, key: error => getParam(error, ERROR_PARAMETERS_KEYS.IDENTIFIER), message: error => renderErrorMessage(error, isLinkAvailable), }); const ErrorsAccordion = ({ errors = [], + errorType, totalErrors, + totalWarnings, isFetching, pagination, + onShowWarnings, onChangePage, }) => { const { user, okapi } = useStripes(); @@ -65,13 +76,10 @@ const ErrorsAccordion = ({ const isLinkAvailable = (isCentralTenant && capabilities === CAPABILITIES.INSTANCE) || !isCentralTenant; const resultsFormatter = getResultsFormatter({ isLinkAvailable }); const errorLength = errors.length; + // temporary solution to calculate total errors and warnings, until backend will provide it in scope of MODBULKOPS-451 + const totalErrorsAndWarnings = errorType === ERROR_TYPES.ERROR ? totalErrors : totalErrors + totalWarnings; const [opened, setOpened] = useState(!!errorLength); - const [showWarnings, setShowWarnings] = useState(false); - - const handleShowWarnings = () => { - setShowWarnings(prev => !prev); - }; return (
@@ -89,13 +97,14 @@ const ErrorsAccordion = ({ id="ui-bulk-edit.list.errors.info" values={{ errors: totalErrors, - warnings: 0, + warnings: totalWarnings, }} /> } - checked={showWarnings} - onChange={handleShowWarnings} + checked={!errorType} + onChange={onShowWarnings} + disabled={!totalWarnings} /> @@ -113,7 +122,7 @@ const ErrorsAccordion = ({ {errors.length > 0 && ( @@ -128,11 +137,14 @@ const ErrorsAccordion = ({ ErrorsAccordion.propTypes = { errors: PropTypes.arrayOf(PropTypes.object), totalErrors: PropTypes.number, + totalWarnings: PropTypes.number, + errorType: PropTypes.string, isFetching: PropTypes.bool, pagination: { limit: PropTypes.number, offset: PropTypes.number, }, + onShowWarnings: PropTypes.func, onChangePage: PropTypes.func, }; diff --git a/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js b/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js index a08f4626..6417e816 100644 --- a/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js +++ b/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { FormattedMessage } from 'react-intl'; import PropTypes from 'prop-types'; @@ -26,6 +26,7 @@ import { usePagination } from '../../../../hooks/usePagination'; import { useBulkOperationStats } from '../../../../hooks/useBulkOperationStats'; import { NoResultsMessage } from '../NoResultsMessage/NoResultsMessage'; import { useSearchParams } from '../../../../hooks'; +import { useErrorType } from '../../../../hooks/useErrorType'; export const Preview = ({ id, title, isInitial, bulkDetails }) => { const { @@ -43,9 +44,15 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => { const { countOfRecords, countOfErrors, + countOfWarnings, visibleColumns, } = useBulkOperationStats({ bulkDetails, step }); + const { errorType, toggleErrorType } = useErrorType({ + countOfErrors, + countOfWarnings + }); + const { pagination: previewPagination, changePage: changePreviewPage, @@ -71,6 +78,7 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => { const { errors, isFetching: isErrorsFetching } = useErrorsPreview({ id, + errorType, enabled: isPreviewEnabled, ...errorsPagination, }); @@ -117,7 +125,10 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => { diff --git a/src/components/shared/ProgressBar/utils.js b/src/components/shared/ProgressBar/utils.js index bd2da5c8..c6d579e0 100644 --- a/src/components/shared/ProgressBar/utils.js +++ b/src/components/shared/ProgressBar/utils.js @@ -10,7 +10,7 @@ export const getBulkOperationStep = (bulkOperation) => { case bulkOperation.status === JOB_STATUSES.COMPLETED: case ( bulkOperation.status === JOB_STATUSES.COMPLETED_WITH_ERRORS - && Boolean(bulkOperation.committedNumOfErrors) + && (Boolean(bulkOperation.committedNumOfErrors) || Boolean(bulkOperation.committedNumOfWarnings)) ): return EDITING_STEPS.COMMIT; case bulkOperation.status === JOB_STATUSES.DATA_MODIFICATION: diff --git a/src/constants/core.js b/src/constants/core.js index 22ce450e..06f7583e 100644 --- a/src/constants/core.js +++ b/src/constants/core.js @@ -7,6 +7,11 @@ export const PREVIEW_LIMITS = { RECORDS: 100, }; +export const ERROR_TYPES = { + WARNING: 'WARNING', + ERROR: 'ERROR', +}; + export const APPROACHES = { IN_APP: 'IN_APP', MANUAL: 'MANUAL', diff --git a/src/hooks/api/useErrorsPreview.js b/src/hooks/api/useErrorsPreview.js index cc91e749..45bb3bcf 100644 --- a/src/hooks/api/useErrorsPreview.js +++ b/src/hooks/api/useErrorsPreview.js @@ -10,6 +10,7 @@ export const useErrorsPreview = ({ enabled, offset = 0, limit = PREVIEW_LIMITS.ERRORS, + errorType, }) => { const ky = useOkapiKy(); const [namespaceKey] = useNamespace({ key: PREVIEW_ERRORS_KEY }); @@ -18,8 +19,8 @@ export const useErrorsPreview = ({ const { data, isFetching } = useQuery( { - queryKey: [namespaceKey, id, limit, offset], - queryFn: () => ky.get(`bulk-operations/${id}/errors`, { searchParams: { limit, offset } }).json(), + queryKey: [namespaceKey, id, limit, offset, errorType], + queryFn: () => ky.get(`bulk-operations/${id}/errors`, { searchParams: { limit, offset, errorType } }).json(), onError: showErrorMessage, onSuccess: showErrorMessage, keepPreviousData: true, diff --git a/src/hooks/useBulkOperationStats.js b/src/hooks/useBulkOperationStats.js index fd965602..dd9a585d 100644 --- a/src/hooks/useBulkOperationStats.js +++ b/src/hooks/useBulkOperationStats.js @@ -5,6 +5,7 @@ import { RootContext } from '../context/RootContext'; export const useBulkOperationStats = ({ bulkDetails, step }) => { const { countOfRecords, setCountOfRecords, visibleColumns } = useContext(RootContext); const [countOfErrors, setCountOfErrors] = useState(0); + const [countOfWarnings, setCountOfWarnings] = useState(0); const [totalCount, setTotalCount] = useState(0); useEffect(() => { @@ -18,7 +19,12 @@ export const useBulkOperationStats = ({ bulkDetails, step }) => { ? bulkDetails.matchedNumOfErrors : bulkDetails.committedNumOfErrors; + const countWarnings = isInitialPreview + ? bulkDetails.matchedNumOfWarnings + : bulkDetails.сommittedNumOfWarnings; + setCountOfErrors(countErrors); + setCountOfWarnings(countWarnings); setCountOfRecords(countRecords); setTotalCount(isInitialPreview ? bulkDetails.totalNumOfRecords : bulkDetails.matchedNumOfRecords); }, [ @@ -32,6 +38,7 @@ export const useBulkOperationStats = ({ bulkDetails, step }) => { return { countOfRecords, countOfErrors, + countOfWarnings, totalCount, visibleColumns, }; diff --git a/src/hooks/useErrorType.js b/src/hooks/useErrorType.js new file mode 100644 index 00000000..79295399 --- /dev/null +++ b/src/hooks/useErrorType.js @@ -0,0 +1,22 @@ +import { useEffect, useState } from 'react'; +import { ERROR_TYPES } from '../constants'; + +// empty string is used to reset the error type and show both errors and warnings +const getDynamicErrorType = (condition) => (condition ? '' : ERROR_TYPES.ERROR); + +export const useErrorType = ({ countOfErrors, countOfWarnings }) => { + const hasOnlyWarnings = countOfErrors === 0 && countOfWarnings > 0; + const initialErrorType = getDynamicErrorType(hasOnlyWarnings); + + const [errorType, setErrorType] = useState(initialErrorType); + + const toggleErrorType = () => { + setErrorType(getDynamicErrorType(!!errorType)); + }; + + useEffect(() => { + setErrorType(initialErrorType); + }, [initialErrorType]); + + return { errorType, toggleErrorType }; +}; From 357fc8f22602effe05bb5fe4f41bdf7230049710 Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 09:29:47 +0100 Subject: [PATCH 02/12] update tests --- src/hooks/api/useErrorsPreview.test.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/hooks/api/useErrorsPreview.test.js b/src/hooks/api/useErrorsPreview.test.js index 5bfd6b65..de2ae727 100644 --- a/src/hooks/api/useErrorsPreview.test.js +++ b/src/hooks/api/useErrorsPreview.test.js @@ -5,7 +5,7 @@ import { useNamespace, useOkapiKy } from '@folio/stripes/core'; import { useErrorMessages } from '../useErrorMessages'; import { useErrorsPreview, PREVIEW_ERRORS_KEY } from './useErrorsPreview'; -import { PREVIEW_LIMITS } from '../../constants'; +import { ERROR_TYPES, PREVIEW_LIMITS } from '../../constants'; jest.mock('react-query', () => ({ useQuery: jest.fn(), @@ -40,7 +40,11 @@ describe('useErrorsPreview', () => { isFetching: true, }); - const { result } = renderHook(() => useErrorsPreview({ id: '123', enabled: true })); + const { result } = renderHook(() => useErrorsPreview({ + id: '123', + enabled: true, + errorType: ERROR_TYPES.ERROR + })); expect(result.current.errors).toEqual(['error1', 'error2']); expect(result.current.isFetching).toBe(true); @@ -48,7 +52,7 @@ describe('useErrorsPreview', () => { expect(useNamespace).toHaveBeenCalledWith({ key: PREVIEW_ERRORS_KEY }); expect(useQuery).toHaveBeenCalledWith( expect.objectContaining({ - queryKey: [PREVIEW_ERRORS_KEY, '123', PREVIEW_LIMITS.ERRORS, 0], + queryKey: [PREVIEW_ERRORS_KEY, '123', PREVIEW_LIMITS.ERRORS, 0, ERROR_TYPES.ERROR], queryFn: expect.any(Function), enabled: true, }) @@ -62,10 +66,16 @@ describe('useErrorsPreview', () => { return { data: null, isFetching: false }; }); - renderHook(() => useErrorsPreview({ id: '123', enabled: true, offset: 10, limit: 20 })); + renderHook(() => useErrorsPreview({ + id: '123', + enabled: true, + offset: 10, + limit: 20, + errorType: ERROR_TYPES.WARNING + })); expect(mockGet).toHaveBeenCalledWith('bulk-operations/123/errors', { - searchParams: { limit: 20, offset: 10 }, + searchParams: { limit: 20, offset: 10, errorType: ERROR_TYPES.WARNING }, }); }); From 454b63730183721e3789a223551c59d97e2d2e22 Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 09:34:22 +0100 Subject: [PATCH 03/12] add tests for useErrorType.test.js --- src/hooks/useErrorType.test.js | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/hooks/useErrorType.test.js diff --git a/src/hooks/useErrorType.test.js b/src/hooks/useErrorType.test.js new file mode 100644 index 00000000..f204765e --- /dev/null +++ b/src/hooks/useErrorType.test.js @@ -0,0 +1,48 @@ +import { renderHook, act } from '@testing-library/react-hooks'; +import { useErrorType } from './useErrorType'; +import { ERROR_TYPES } from '../constants'; + +describe('useErrorType', () => { + it('should initialize with no error type if only warnings exist', () => { + const { result } = renderHook(() => useErrorType({ countOfErrors: 0, countOfWarnings: 1 })); + expect(result.current.errorType).toBe(''); + }); + + it('should initialize with error type if errors exist', () => { + const { result } = renderHook(() => useErrorType({ countOfErrors: 1, countOfWarnings: 0 })); + expect(result.current.errorType).toBe(ERROR_TYPES.ERROR); + }); + + it('should toggle error type when toggleErrorType is called', () => { + const { result } = renderHook(() => useErrorType({ countOfErrors: 1, countOfWarnings: 0 })); + + expect(result.current.errorType).toBe(ERROR_TYPES.ERROR); + + act(() => { + result.current.toggleErrorType(); + }); + expect(result.current.errorType).toBe(''); + + act(() => { + result.current.toggleErrorType(); + }); + expect(result.current.errorType).toBe(ERROR_TYPES.ERROR); + }); + + it('should reset error type when the input props change', () => { + const { result, rerender } = renderHook( + ({ countOfErrors, countOfWarnings }) => useErrorType({ countOfErrors, countOfWarnings }), + { + initialProps: { countOfErrors: 1, countOfWarnings: 0 }, + } + ); + + expect(result.current.errorType).toBe(ERROR_TYPES.ERROR); + + rerender({ countOfErrors: 0, countOfWarnings: 1 }); + expect(result.current.errorType).toBe(''); + + rerender({ countOfErrors: 2, countOfWarnings: 0 }); + expect(result.current.errorType).toBe(ERROR_TYPES.ERROR); + }); +}); From 57a366ec5cb9775a6ab71f50a40680196b0ec851 Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 09:39:25 +0100 Subject: [PATCH 04/12] remove unused imports --- .../BulkEditPane/BulkEditListResult/Preview/Preview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js b/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js index 6417e816..a81e4032 100644 --- a/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js +++ b/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React from 'react'; import { FormattedMessage } from 'react-intl'; import PropTypes from 'prop-types'; From 0ccc04cc86d1ecf6a11f2411012d79dbb804b697 Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 09:54:36 +0100 Subject: [PATCH 05/12] update --- .../Preview/ErrorsAccordion/ErrorsAccordion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js b/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js index d86d957c..3aa03aea 100644 --- a/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js +++ b/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js @@ -25,7 +25,7 @@ const columnMapping = { const visibleColumns = Object.keys(columnMapping); const renderErrorType = (error) => { - if (error.type === ERROR_TYPES.ERROR) { + if (!error.type || error.type === ERROR_TYPES.ERROR) { return ; } From 8790711cd05a3d7edaa451403c434a65532c776e Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 12:00:17 +0100 Subject: [PATCH 06/12] update holding to holdings --- src/constants/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/core.js b/src/constants/core.js index 06f7583e..e81b1787 100644 --- a/src/constants/core.js +++ b/src/constants/core.js @@ -156,7 +156,7 @@ export const ERROR_PARAMETERS_KEYS = { }; export const RECORD_TYPES_MAPPING = { - [CAPABILITIES.HOLDING]: 'holding', + [CAPABILITIES.HOLDING]: 'holdings', [CAPABILITIES.INSTANCE]: 'instance', [CAPABILITIES.ITEM]: 'item', [CAPABILITIES.USER]: 'user', From 92ab2bbaab85efea98db821e119cc37c0b5dc7aa Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 12:10:08 +0100 Subject: [PATCH 07/12] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 166c3c9c..bd767c91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * [UIBULKED-597](https://folio-org.atlassian.net/browse/UIBULKED-597) Commit changes button enabled before preview is populated * [UIBULKED-599](https://folio-org.atlassian.net/browse/UIBULKED-599) Change Administrative note type is not supported for MARC instances. * [UIBULKED-589](https://folio-org.atlassian.net/browse/UIBULKED-589) Make options in the "Actions" dropdown in "Bulk edits" in alphabetical order. +* [IBULKED-588](https://folio-org.atlassian.net/browse/IBULKED-588) Displaying errors and warnings. ## [4.2.2](https://github.com/folio-org/ui-bulk-edit/tree/v4.2.2) (2024-11-15) From 4e93a28d2d3478399c3b6a13977b3d01ac4f0ac9 Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 12:10:59 +0100 Subject: [PATCH 08/12] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd767c91..fd365c9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ * [UIBULKED-597](https://folio-org.atlassian.net/browse/UIBULKED-597) Commit changes button enabled before preview is populated * [UIBULKED-599](https://folio-org.atlassian.net/browse/UIBULKED-599) Change Administrative note type is not supported for MARC instances. * [UIBULKED-589](https://folio-org.atlassian.net/browse/UIBULKED-589) Make options in the "Actions" dropdown in "Bulk edits" in alphabetical order. -* [IBULKED-588](https://folio-org.atlassian.net/browse/IBULKED-588) Displaying errors and warnings. +* [UIBULKED-588](https://folio-org.atlassian.net/browse/IBULKED-588) Displaying errors and warnings. ## [4.2.2](https://github.com/folio-org/ui-bulk-edit/tree/v4.2.2) (2024-11-15) From 147945fab2b941dd12565d6552cadfce04c8ce86 Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 13:48:56 +0100 Subject: [PATCH 09/12] update checkbox --- .../Preview/ErrorsAccordion/ErrorsAccordion.js | 3 ++- src/hooks/useBulkOperationStats.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js b/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js index 3aa03aea..a2a7ea4e 100644 --- a/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js +++ b/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js @@ -78,6 +78,7 @@ const ErrorsAccordion = ({ const errorLength = errors.length; // temporary solution to calculate total errors and warnings, until backend will provide it in scope of MODBULKOPS-451 const totalErrorsAndWarnings = errorType === ERROR_TYPES.ERROR ? totalErrors : totalErrors + totalWarnings; + const isWarningsCheckboxDisabled = !totalWarnings || (totalWarnings && !totalErrors); const [opened, setOpened] = useState(!!errorLength); @@ -104,7 +105,7 @@ const ErrorsAccordion = ({ label={} checked={!errorType} onChange={onShowWarnings} - disabled={!totalWarnings} + disabled={isWarningsCheckboxDisabled} /> diff --git a/src/hooks/useBulkOperationStats.js b/src/hooks/useBulkOperationStats.js index dd9a585d..bd0bf8b2 100644 --- a/src/hooks/useBulkOperationStats.js +++ b/src/hooks/useBulkOperationStats.js @@ -21,7 +21,7 @@ export const useBulkOperationStats = ({ bulkDetails, step }) => { const countWarnings = isInitialPreview ? bulkDetails.matchedNumOfWarnings - : bulkDetails.сommittedNumOfWarnings; + : bulkDetails.committedNumOfWarnings; setCountOfErrors(countErrors); setCountOfWarnings(countWarnings); From be999b1fbd8aa6030f172abf53d5dfacd0676a81 Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 15:06:51 +0100 Subject: [PATCH 10/12] update checkbox logic --- .../Preview/ErrorsAccordion/ErrorsAccordion.js | 2 +- .../BulkEditPane/BulkEditListResult/Preview/Preview.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js b/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js index a2a7ea4e..14b2f9b8 100644 --- a/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js +++ b/src/components/BulkEditPane/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js @@ -78,7 +78,7 @@ const ErrorsAccordion = ({ const errorLength = errors.length; // temporary solution to calculate total errors and warnings, until backend will provide it in scope of MODBULKOPS-451 const totalErrorsAndWarnings = errorType === ERROR_TYPES.ERROR ? totalErrors : totalErrors + totalWarnings; - const isWarningsCheckboxDisabled = !totalWarnings || (totalWarnings && !totalErrors); + const isWarningsCheckboxDisabled = !totalWarnings || !totalErrors; const [opened, setOpened] = useState(!!errorLength); diff --git a/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js b/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js index a81e4032..c38f2ccc 100644 --- a/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js +++ b/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js @@ -83,6 +83,11 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => { ...errorsPagination, }); + const handleToggleWarnings = () => { + changeErrorPage(ERRORS_PAGINATION_CONFIG); + toggleErrorType(); + }; + if (!((bulkDetails.fqlQuery && criteria === CRITERIA.QUERY) || (criteria !== CRITERIA.QUERY && !bulkDetails.fqlQuery))) { return ; } @@ -128,7 +133,7 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => { totalWarnings={countOfWarnings} errorType={errorType} onChangePage={changeErrorPage} - onShowWarnings={toggleErrorType} + onShowWarnings={handleToggleWarnings} pagination={errorsPagination} isFetching={isErrorsFetching} /> From 14fb646ad9cc422aaef60d03f4d4c999c0e9388b Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 15:28:16 +0100 Subject: [PATCH 11/12] add step to errors preview keys --- .../BulkEditPane/BulkEditListResult/Preview/Preview.js | 1 + src/hooks/api/useErrorsPreview.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js b/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js index c38f2ccc..287ed5ae 100644 --- a/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js +++ b/src/components/BulkEditPane/BulkEditListResult/Preview/Preview.js @@ -78,6 +78,7 @@ export const Preview = ({ id, title, isInitial, bulkDetails }) => { const { errors, isFetching: isErrorsFetching } = useErrorsPreview({ id, + step, errorType, enabled: isPreviewEnabled, ...errorsPagination, diff --git a/src/hooks/api/useErrorsPreview.js b/src/hooks/api/useErrorsPreview.js index 45bb3bcf..9c2a6600 100644 --- a/src/hooks/api/useErrorsPreview.js +++ b/src/hooks/api/useErrorsPreview.js @@ -10,7 +10,8 @@ export const useErrorsPreview = ({ enabled, offset = 0, limit = PREVIEW_LIMITS.ERRORS, - errorType, + step, + errorType }) => { const ky = useOkapiKy(); const [namespaceKey] = useNamespace({ key: PREVIEW_ERRORS_KEY }); @@ -19,7 +20,7 @@ export const useErrorsPreview = ({ const { data, isFetching } = useQuery( { - queryKey: [namespaceKey, id, limit, offset, errorType], + queryKey: [namespaceKey, id, limit, offset, errorType, step], queryFn: () => ky.get(`bulk-operations/${id}/errors`, { searchParams: { limit, offset, errorType } }).json(), onError: showErrorMessage, onSuccess: showErrorMessage, From 77264b272b7026e9d7856a0550b3d8bf9d6219da Mon Sep 17 00:00:00 2001 From: vashjs Date: Fri, 24 Jan 2025 15:34:53 +0100 Subject: [PATCH 12/12] fix tests --- src/hooks/api/useErrorsPreview.test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hooks/api/useErrorsPreview.test.js b/src/hooks/api/useErrorsPreview.test.js index de2ae727..c66164e6 100644 --- a/src/hooks/api/useErrorsPreview.test.js +++ b/src/hooks/api/useErrorsPreview.test.js @@ -5,7 +5,7 @@ import { useNamespace, useOkapiKy } from '@folio/stripes/core'; import { useErrorMessages } from '../useErrorMessages'; import { useErrorsPreview, PREVIEW_ERRORS_KEY } from './useErrorsPreview'; -import { ERROR_TYPES, PREVIEW_LIMITS } from '../../constants'; +import { EDITING_STEPS, ERROR_TYPES, PREVIEW_LIMITS } from '../../constants'; jest.mock('react-query', () => ({ useQuery: jest.fn(), @@ -43,7 +43,8 @@ describe('useErrorsPreview', () => { const { result } = renderHook(() => useErrorsPreview({ id: '123', enabled: true, - errorType: ERROR_TYPES.ERROR + errorType: ERROR_TYPES.ERROR, + step: EDITING_STEPS.UPLOAD, })); expect(result.current.errors).toEqual(['error1', 'error2']); @@ -52,7 +53,7 @@ describe('useErrorsPreview', () => { expect(useNamespace).toHaveBeenCalledWith({ key: PREVIEW_ERRORS_KEY }); expect(useQuery).toHaveBeenCalledWith( expect.objectContaining({ - queryKey: [PREVIEW_ERRORS_KEY, '123', PREVIEW_LIMITS.ERRORS, 0, ERROR_TYPES.ERROR], + queryKey: [PREVIEW_ERRORS_KEY, '123', PREVIEW_LIMITS.ERRORS, 0, ERROR_TYPES.ERROR, EDITING_STEPS.UPLOAD], queryFn: expect.any(Function), enabled: true, })