Skip to content

Fixes #38858 - Fix search cleared on bottom pagination #10901

Open
jeremylenz wants to merge 1 commit intotheforeman:3.17-stablefrom
jeremylenz:3.17-stable
Open

Fixes #38858 - Fix search cleared on bottom pagination #10901
jeremylenz wants to merge 1 commit intotheforeman:3.17-stablefrom
jeremylenz:3.17-stable

Conversation

@jeremylenz
Copy link
Contributor

@jeremylenz jeremylenz commented Mar 6, 2026

cherry-pick requested by community: https://community.theforeman.org/t/new-host-page-and-paging/45910/3?u=jeremylenz

(cherry picked from commit jeremylenz@45f7dfd)

When using the All Hosts page with replacementResponse pattern, the
bottom pagination was clearing the search query because HostsIndex
maintained a separate params state that wasn't synced with the API
response values.

This fix merges the API response's page and perPage values into the
params object during render, ensuring the bottom pagination displays
the correct page number while preserving the search query. This
follows React best practices by calculating values during render
instead of using useEffect.

Also adds a test to verify the params merging behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Fixes #38858 - Fix search cleared on bottom pagination (revised)

The previous fix had two issues:
1. Both per_page and perPage appeared in URL params
2. Search was still being cleared on bottom pagination

Root cause: HostsIndex's params state doesn't sync with search changes
made through TableIndexPage's SearchBar. The API response contains the
current search query, page, and perPage, but they weren't being merged
into the params passed to Table.

Solution: Merge fresh values from API response into params:
- page: current page number
- per_page: current per-page value (using snake_case, not camelCase)
- search: current search query

This ensures:
- Only snake_case per_page in URL (no duplicate perPage)
- Search query always preserved when using bottom pagination
- Page/perPage are always current values from API response

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Fixes #38858 - Prevent duplicate perPage/per_page in Table params

Previous fix had two remaining issues:
1. Test was failing because mock API response lacked search field
2. Both perPage (camelCase) and per_page (snake_case) appeared in params

Changes:
- Added search field to mock API response in test
- Destructured and excluded stale perPage from params before spreading
- This ensures only per_page (snake_case) appears in Table params

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
(cherry picked from commit 45f7dfd)
@pr-processor pr-processor bot added Not yet reviewed Stable branch PRs that are opened against a stable branch. Usually a cherry pick labels Mar 6, 2026
@github-actions github-actions bot added the UI label Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Not yet reviewed Stable branch PRs that are opened against a stable branch. Usually a cherry pick UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant