Skip to content

Commit

Permalink
UIIN-3143: Set the previously used offset by executing 'resultOffset.…
Browse files Browse the repository at this point in the history
…replace' when changing the segment.
  • Loading branch information
Dmytro-Melnyshyn committed Nov 28, 2024
1 parent 1423654 commit ce3ccba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/components/InstancesList/InstancesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ class InstancesList extends React.Component {
data,
location,
segment,
parentMutator,
getLastSearchOffset,
} = this.props;
const sortBy = this.getSortFromParams();

Expand Down Expand Up @@ -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() {
Expand Down
21 changes: 21 additions & 0 deletions src/components/InstancesList/InstancesList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit ce3ccba

Please sign in to comment.