diff --git a/CHANGELOG.md b/CHANGELOG.md index c411ef1ca..26f274803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,7 @@ UIIN-3437. * Inventory Item: Add number generator button "Generate call number" to additional item call numbers. Refs UIIN-3608. * Make `circulation-settings` dependency optional. Refs UIIN-3621. * User without affiliation in member tenant is not able to see an item record. Fixes UIIN-3614. +* Item reorder changes are lost if holdings accordion is collapsed before 'stop item movement' invoked. Fixes UIIN-3626. ## [13.0.13](https://github.com/folio-org/ui-inventory/tree/v13.0.13) (2026-03-11) [Full Changelog](https://github.com/folio-org/ui-inventory/compare/v13.0.12...v13.0.13) diff --git a/src/Instance/HoldingsList/Holding/HoldingAccordion.js b/src/Instance/HoldingsList/Holding/HoldingAccordion.js index b277890ae..4f64e87b0 100644 --- a/src/Instance/HoldingsList/Holding/HoldingAccordion.js +++ b/src/Instance/HoldingsList/Holding/HoldingAccordion.js @@ -1,4 +1,5 @@ import PropTypes from 'prop-types'; +import { useRef } from 'react'; import { FormattedMessage, useIntl, @@ -93,6 +94,7 @@ const HoldingAccordion = ({ dragHandleListeners, ref, }) => { + const hasBeenOpenedRef = useRef(false); const searchParams = { limit: 0, offset: 0, @@ -163,15 +165,24 @@ const HoldingAccordion = ({ displayWhenClosed={holdingButtonsGroup(false)} closedByDefault > - {open => ( - open && ( + {open => { + if (open) { + hasBeenOpenedRef.current = true; + } + + if (!hasBeenOpenedRef.current) return null; + + return ( - + {children} - ) - )} + ); + }} ); }; diff --git a/src/hooks/useHoldingItemsQuery.js b/src/hooks/useHoldingItemsQuery.js index fc81f973c..6d3556a79 100644 --- a/src/hooks/useHoldingItemsQuery.js +++ b/src/hooks/useHoldingItemsQuery.js @@ -58,12 +58,15 @@ const useHoldingItemsQuery = ( ...omit(options.searchParams, ['sortBy']), }; - const queryKey = [namespace, options.key, holdingsRecordId, searchParams.offset, sortBy]; + const queryKey = [namespace, options.key, holdingsRecordId, searchParams]; const queryFn = () => ky.get('inventory/items-by-holdings-id', { searchParams }).json(); + const queryOptions = omit(options, ['searchParams']); const { data, refetch, isLoading, isFetching } = useQuery({ queryKey, queryFn, - ...omit(options, ['searchParams']), + staleTime: queryOptions.staleTime ?? Infinity, + refetchOnMount: queryOptions.refetchOnMount ?? false, + ...queryOptions, }); return { diff --git a/src/hooks/useHoldingItemsQuery.test.js b/src/hooks/useHoldingItemsQuery.test.js index e3b32f46e..609c7db68 100644 --- a/src/hooks/useHoldingItemsQuery.test.js +++ b/src/hooks/useHoldingItemsQuery.test.js @@ -28,6 +28,8 @@ describe('useHoldingItemsQuery', () => { })); beforeEach(() => { + queryClient.clear(); + mockGet.mockClear(); useOkapiKy.mockClear().mockReturnValue({ get: mockGet, extend: jest.fn().mockReturnValue({ get: mockGet }), @@ -110,4 +112,27 @@ describe('useHoldingItemsQuery', () => { ); }); }); + + it('does not refetch on remount when request params are unchanged', async () => { + const id = items[0].holdingsRecordId; + const searchParams = { limit: 5, offset: 0 }; + + const { unmount } = renderHook( + () => useHoldingItemsQuery(id, { searchParams }), + { wrapper } + ); + + await act(() => !queryClient.isFetching()); + expect(mockGet).toHaveBeenCalledTimes(1); + + unmount(); + + renderHook( + () => useHoldingItemsQuery(id, { searchParams }), + { wrapper } + ); + + await act(() => !queryClient.isFetching()); + expect(mockGet).toHaveBeenCalledTimes(1); + }); });