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

UIIN-3143: Set the previously used offset by executing resultOffset.replace when changing the segment. #2680

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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
Loading