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

Revert "UIIN-3137: Add the isSearchToggleHitInBrowse flag to the history state to use in the condition that specifies whether to use the default sort on mount." #2684

Merged
merged 1 commit 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: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* 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.
* Add the `isSearchToggleHitInBrowse` flag to the history state to use in the condition that specifies whether to use the default sort on mount. Fixes UIIN-3137.

## [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
10 changes: 1 addition & 9 deletions src/components/InstancesList/InstancesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ class InstancesList extends React.Component {
data,
} = this.props;

const { isSearchToggleHitInBrowse } = _location.state || {};
const params = getParams();
const defaultSort = data.displaySettings.defaultSort;

Expand All @@ -252,16 +251,9 @@ class InstancesList extends React.Component {
const searchParams = new URLSearchParams(_location.search);

const isStaffSuppressFilterChanged = this.applyDefaultStaffSuppressFilter(searchParams);
let isSortingChanged = false;

// don't set the default sort when redirecting from Browse search by hitting the Search toggle,
// the previously selected sort option should be used (it will be taken from session storage).
if (params.sort !== defaultSort && !isSearchToggleHitInBrowse) {
isSortingChanged = true;
if (params.sort !== defaultSort || isStaffSuppressFilterChanged) {
searchParams.set('sort', defaultSort);
}

if (isSortingChanged || isStaffSuppressFilterChanged) {
this.redirectToSearchParams(searchParams);
}
}
Expand Down
47 changes: 5 additions & 42 deletions src/components/InstancesList/InstancesList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,7 @@ describe('InstancesList', () => {
it('should call history.replace with sort parameter from Settings', () => {
jest.spyOn(history, 'replace');

history.push({
pathname: '/inventory',
search: '?filters=staffSuppress.false&sort=title',
state: {
isSearchToggleHitInBrowse: false,
},
});
history.push('/inventory?filters=staffSuppress.false&sort=title');

renderInstancesList({
segment: 'instances',
Expand All @@ -335,41 +329,10 @@ describe('InstancesList', () => {
},
});

expect(history.replace).toHaveBeenLastCalledWith(expect.objectContaining({
search: expect.stringContaining('sort=relevance'),
}));
});

describe('and redirection from Browse search by pressing Search toggle', () => {
it('should not call history.replace with sort parameter from Settings', () => {
jest.spyOn(history, 'replace');

history.push({
pathname: '/inventory',
search: '?filters=staffSuppress.false&sort=title',
state: {
isSearchToggleHitInBrowse: true,
},
});

const defaultSort = SORT_OPTIONS.RELEVANCE;

renderInstancesList({
segment: segments.instances,
data: {
...data,
query: {
query: '',
},
displaySettings: {
defaultSort,
},
},
});

expect(history.replace).not.toHaveBeenLastCalledWith(expect.objectContaining({
search: expect.stringContaining(`sort=${defaultSort}`),
}));
expect(history.replace).toHaveBeenLastCalledWith({
pathname: '/inventory',
search: 'filters=staffSuppress.false&sort=relevance',
state: undefined,
});
});
});
Expand Down
3 changes: 0 additions & 3 deletions src/views/BrowseInventory/BrowseInventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ const BrowseInventory = () => {
>
<SearchModeNavigation
search={getLastSearch()}
state={{
isSearchToggleHitInBrowse: true,
}}
/>

<SingleSearchForm
Expand Down
8 changes: 1 addition & 7 deletions src/views/BrowseInventory/BrowseInventory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,11 @@ describe('BrowseInventory', () => {

it('should have search prop in SearchModeNavigation component', () => {
const search = '?qindex=title&query=book&sort=title';
const state = {
isSearchToggleHitInBrowse: true,
};

mockGetLastSearch.mockClear().mockImplementation(() => search);
renderBrowseInventory();

expect(SearchModeNavigation).toHaveBeenCalledWith({
search,
state,
}, {});
expect(SearchModeNavigation).toHaveBeenCalledWith({ search }, {});
mockGetLastSearch.mockRestore();
});

Expand Down
Loading