From ce3ccba49f2fe78ee4b8b91ebf285f58934498a3 Mon Sep 17 00:00:00 2001 From: Dmytro Melnyshyn Date: Thu, 28 Nov 2024 16:14:58 +0200 Subject: [PATCH] UIIN-3143: Set the previously used offset by executing 'resultOffset.replace' when changing the segment. --- CHANGELOG.md | 1 + src/components/InstancesList/InstancesList.js | 8 +++++++ .../InstancesList/InstancesList.test.js | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ff3b643d..f988d1368 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Display informative error message when editing same instance, holdings, item in two tabs. Fixes UIIN-3127. * Display user's name instead of "Unknown user" in "Last updated" field in "Settings" for member tenant. Fixes UIIN-3144. * Update Linked data API URL to use the new API path. Fixes UIIN-3146. +* Set the previously used offset by executing `resultOffset.replace` when changing the segment. Fixes UIIN-3143. ## [12.0.3](https://github.com/folio-org/ui-inventory/tree/v12.0.3) (2024-11-27) [Full Changelog](https://github.com/folio-org/ui-inventory/compare/v12.0.2...v12.0.3) diff --git a/src/components/InstancesList/InstancesList.js b/src/components/InstancesList/InstancesList.js index 82f980546..f3036fecd 100644 --- a/src/components/InstancesList/InstancesList.js +++ b/src/components/InstancesList/InstancesList.js @@ -263,6 +263,8 @@ class InstancesList extends React.Component { data, location, segment, + parentMutator, + getLastSearchOffset, } = this.props; const sortBy = this.getSortFromParams(); @@ -295,6 +297,12 @@ class InstancesList extends React.Component { searchParams.set('sort', data.displaySettings.defaultSort); this.redirectToSearchParams(searchParams); } + + if (prevProps.segment !== segment) { + const lastSearchOffset = getLastSearchOffset(segment); + + parentMutator.resultOffset.replace(lastSearchOffset); + } } componentWillUnmount() { diff --git a/src/components/InstancesList/InstancesList.test.js b/src/components/InstancesList/InstancesList.test.js index 1a472eca6..9bfe18b39 100644 --- a/src/components/InstancesList/InstancesList.test.js +++ b/src/components/InstancesList/InstancesList.test.js @@ -416,6 +416,27 @@ describe('InstancesList', () => { expect(mockStoreLastSearchOffset).toHaveBeenCalledWith(offset, 'instances'); }); }); + + describe('and segment has been changed', () => { + it('should apply offset from storage', () => { + const lastSearchOffset = 200; + + const { rerender } = renderInstancesList({ + segment: segments.instances, + }); + + mockStoreLastSearchOffset.mockClear(); + mockResultOffsetReplace.mockClear(); + mockGetLastSearchOffset.mockReturnValueOnce(lastSearchOffset); + + rerender(getInstancesListTree({ + segment: segments.holdings, + })); + + expect(mockGetLastSearchOffset).toHaveBeenCalledWith(segments.holdings); + expect(mockResultOffsetReplace).toHaveBeenCalledWith(lastSearchOffset); + }); + }); }); describe('when user clicks Reset all', () => {