Skip to content

EDM-3868: Reset page to 1 when filters change#664

Open
celdrake wants to merge 2 commits into
flightctl:mainfrom
celdrake:EDM-3868-reset-pagination-on-filter-change
Open

EDM-3868: Reset page to 1 when filters change#664
celdrake wants to merge 2 commits into
flightctl:mainfrom
celdrake:EDM-3868-reset-pagination-on-filter-change

Conversation

@celdrake

@celdrake celdrake commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes filters not returning the expected results when the user was on a page other than page 1.

Fixed for:

  • Main devices page
  • Decommissioned devices page
  • Catalog page for deploying an element to fleetless devices (simplified signature of useDevicesPaginated to make the code simpler while keeping all existing functionality)

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: d8a55b3c-b919-42b5-8a1d-fa44d6a40405

📥 Commits

Reviewing files that changed from the base of the PR and between 5238d87 and 4d82bf9.

📒 Files selected for processing (6)
  • libs/ui-components/src/components/Catalog/InstallWizard/steps/SelectTargetStep.tsx
  • libs/ui-components/src/components/Catalog/InstallWizard/steps/SpecificationsStep.tsx
  • libs/ui-components/src/components/Device/DevicesPage/DevicesPage.tsx
  • libs/ui-components/src/components/Device/DevicesPage/useDeviceBackendFilters.ts
  • libs/ui-components/src/components/Device/DevicesPage/useDevices.ts
  • libs/ui-components/src/hooks/useTablePagination.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • libs/ui-components/src/components/Catalog/InstallWizard/steps/SelectTargetStep.tsx
  • libs/ui-components/src/components/Device/DevicesPage/useDeviceBackendFilters.ts
  • libs/ui-components/src/components/Device/DevicesPage/useDevices.ts

Summary by CodeRabbit

  • Bug Fixes

    • Pagination now reliably resets to page 1 when backend filter criteria change, avoiding empty result pages.
  • Refactor

    • Streamlined device name filtering in the install wizard selection flow.
    • Device list used for specification/target selection now includes a broader set of devices, updating when availability changes and clearing selections when appropriate.
    • Improved pagination state handling across device selection and management interfaces.

Walkthrough

Refactors device pagination/filtering: adds a hook to reset pagination on backend filter changes, exposes a stable filterKey, and simplifies useDevicesPaginated to accept an optional deviceNameFilter; updates DevicesPage and Install Wizard call sites.

Changes

Device Pagination and Filter Management

Layer / File(s) Summary
Pagination reset hook foundation
libs/ui-components/src/hooks/useTablePagination.ts
New useResetPaginationOnFilterChange hook uses a ref to track previous queryKey and calls setCurrentPage(1) when it changes.
Filter state key derivation
libs/ui-components/src/components/Device/DevicesPage/useDeviceBackendFilters.ts
Added getSearchParamsQueryKey and a memoized filterKey derived from searchParams, returned from useDeviceBackendFilters.
Simplified device pagination API and integration
libs/ui-components/src/components/Device/DevicesPage/useDevices.ts
useDevicesPaginated now takes a single optional deviceNameFilter string, derives textFilters, uses useResetPaginationOnFilterChange to reset pagination on filter changes, and calls useDevicesEndpoint with pagination and hard-coded fleet flags.
DevicesPage filter-aware pagination
libs/ui-components/src/components/Device/DevicesPage/DevicesPage.tsx
DevicesPage imports useResetPaginationOnFilterChange, reads filterKey from useDeviceBackendFilters, and resets pagination when filterKey or onlyDecommissioned change.
Install Wizard step updates
libs/ui-components/src/components/Catalog/InstallWizard/steps/SelectTargetStep.tsx, libs/ui-components/src/components/Catalog/InstallWizard/steps/SpecificationsStep.tsx
SelectTargetStep now passes deviceNameFilter to useDevicesPaginated; SpecificationsStep calls useDevicesPaginated() without the prior onlyFleetless restriction.
sequenceDiagram
  participant SelectTargetStep
  participant SpecificationsStep
  participant DevicesPage
  participant useDevicesPaginated
  participant useResetPaginationOnFilterChange
  participant useDevicesEndpoint
  SelectTargetStep->>useDevicesPaginated: pass deviceNameFilter
  SpecificationsStep->>useDevicesPaginated: call without fleet filter
  DevicesPage->>useDevicesPaginated: observe filterKey/onlyDecommissioned
  useDevicesPaginated->>useResetPaginationOnFilterChange: notify filter key
  useResetPaginationOnFilterChange->>useDevicesPaginated: setCurrentPage(1)
  useDevicesPaginated->>useDevicesEndpoint: call with derived textFilters & pagination
  useDevicesEndpoint-->>useDevicesPaginated: return devices
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: resetting pagination when filters change, which directly addresses the core issue in the PR.
Description check ✅ Passed The description is directly related to the changeset, explaining the issue fixed (filters not returning expected results when on pages other than 1) and listing the affected components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@libs/ui-components/src/components/Device/DevicesPage/useDeviceBackendFilters.ts`:
- Around line 19-26: getSearchParamsQueryKey currently builds a joined string
from searchParams.entries() that can collide when keys/values contain '&' or
'='; update getSearchParamsQueryKey to percent-encode each entry before joining
(e.g., encodeURIComponent on both key and value) or use URLSearchParams
serialization that performs encoding, keep the .map/.sort/.join logic intact but
replace `${key}=${value}` with an encoded pair so filterKey is unambiguous
(refer to function name getSearchParamsQueryKey).

In `@libs/ui-components/src/components/Device/DevicesPage/useDevices.ts`:
- Around line 174-188: useDevicesPaginated now fetches all enrolled devices and
drops the fleetless filter used by the install wizard; restore a fleetless-only
filter by passing a filter flag into useDevicesEndpoint (or include it in the
textFilters) when called from useDevicesPaginated so the API request limits to
fleetless devices. Locate useDevicesPaginated and the useDevicesEndpoint call
and add the fleetless filter (e.g., include a property like fleetless: true or
FilterSearchParams.Fleetless) to the options passed to useDevicesEndpoint (while
preserving existing textFilters and nextContinue) so downstream components (like
SpecificationsStep) can still get only fleetless devices. Ensure you reference
FilterSearchParams.NameOrAlias and keep pagination.nextContinue unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 969d5b83-8095-414f-bcde-68c3194b6c26

📥 Commits

Reviewing files that changed from the base of the PR and between 905a256 and 5238d87.

📒 Files selected for processing (6)
  • libs/ui-components/src/components/Catalog/InstallWizard/steps/SelectTargetStep.tsx
  • libs/ui-components/src/components/Catalog/InstallWizard/steps/SpecificationsStep.tsx
  • libs/ui-components/src/components/Device/DevicesPage/DevicesPage.tsx
  • libs/ui-components/src/components/Device/DevicesPage/useDeviceBackendFilters.ts
  • libs/ui-components/src/components/Device/DevicesPage/useDevices.ts
  • libs/ui-components/src/hooks/useTablePagination.ts

Comment thread libs/ui-components/src/components/Device/DevicesPage/useDevices.ts
@celdrake celdrake force-pushed the EDM-3868-reset-pagination-on-filter-change branch from 5238d87 to 4d82bf9 Compare June 2, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant