Skip to content

Pagination fix witness voters#766

Merged
feruzm merged 3 commits into
developfrom
load
Apr 28, 2026
Merged

Pagination fix witness voters#766
feruzm merged 3 commits into
developfrom
load

Conversation

@feruzm
Copy link
Copy Markdown
Member

@feruzm feruzm commented Apr 28, 2026

Summary by CodeRabbit

  • New Features

    • Witness voters dialog now uses page-based pagination with explicit sorting and sort direction.
  • Improvements

    • Voter list renders server-provided pages directly; client-side search filters visible results.
    • Sorting changes reset to page 1.
    • Loading feedback improved (better loading/empty handling and list busy state).
  • Style

    • Removed "Load more" button in favor of page navigation.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Replaces infinite-scroll client-side aggregation for witness voters with page-based server-side pagination: the UI uses a page query (including sort/direction), renders returned voters directly with client-side search, drives pagination from totalVoters, and removes "Load more" and client-side per-page slicing.

Changes

Cohort / File(s) Summary
UI: Witness voters dialog
apps/web/src/app/witnesses/_components/witness-voters-dialog.tsx
Switches from useInfiniteQuery(getWitnessVotersInfiniteQueryOptions(...)) to useQuery(getWitnessVotersPageQueryOptions(witness, page, PAGE_SIZE, sort, "desc")). Removes client-side flattening/slicing, local pagination logic, compareVests, and "Load more" button. Adds aria-busy={isFetching}, changes empty loading check to isLoading && !data, and resets page when sort changes.
SDK: Query key shape
packages/sdk/src/modules/core/query-keys.ts
Extends QueryKeys.witnesses.voters(...) signature and cache key from [witness, pageSize] to [witness, page, pageSize, sort, direction] to include pagination and ordering.
SDK: Witness voters query options
packages/sdk/src/modules/witnesses/queries/get-witnesses-query-options.ts
Removes getWitnessVotersInfiniteQueryOptions and adds getWitnessVotersPageQueryOptions(witness, page, pageSize, sort?, direction?) returning queryOptions that request a specific page (includes sort/direction in API call and key). Adds exported types WitnessVoterSortField and WitnessVoterSortDirection and sets staleTime: 60_000.
Releases & Manifests
packages/sdk/CHANGELOG.md, packages/sdk/package.json, packages/wallets/CHANGELOG.md, packages/wallets/package.json
Bumps SDK to 2.2.8 and wallets to 4.0.6; adds changelog entries referencing the pagination fix and updates wallets to depend on @ecency/sdk@2.2.8.

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant Dialog as WitnessVotersDialog
  participant Query as ReactQuery
  participant API as Hafbe API

  User->>Dialog: open dialog / change page or sort
  Dialog->>Query: useQuery(getWitnessVotersPageQueryOptions(witness,page,pageSize,sort,direction))
  Query->>API: GET /witnesses/{witness}/voters?page=&pageSize=&sort=&direction=
  API-->>Query: { voters, totalVoters, page }
  Query-->>Dialog: data (voters, totalVoters)
  Dialog->>Dialog: apply client-side search filter -> visible
  Dialog-->>User: render visible voters and pagination controls (driven by totalVoters)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped from infinite scroll to page,

Server hands pages, tidy as a sage.
Search peeks quick, sort springs to one,
No more endless loading run—
Little hops, big tidy stage!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Pagination fix witness voters' directly describes the main change: converting witness voters data-fetching from infinite-query to page-based pagination with ordering support.
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.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch load

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/sdk/src/modules/witnesses/queries/get-witnesses-query-options.ts (1)

125-138: Forward React Query signal to callREST for proper request cancellation.

Line 127 ignores the cancellation context, so rapid page/sort changes can keep stale requests in flight. Extract the signal from the queryFn context and pass it to callREST to enable cancellation of in-flight requests.

Suggested fix
     return queryOptions({
       queryKey: QueryKeys.witnesses.voters(witness, page, pageSize, sort, direction),
-      queryFn: async () => {
+      queryFn: async ({ signal }) => {
         return (await callREST(
           "hafbe",
           "/witnesses/{witness-name}/voters",
           {
             "witness-name": witness,
             "page-size": pageSize,
             page,
             sort,
             direction,
-          }
+          },
+          undefined,
+          undefined,
+          signal
         )) as WitnessVotersResponse;
       },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/sdk/src/modules/witnesses/queries/get-witnesses-query-options.ts`
around lines 125 - 138, The queryFn in get-witnesses-query-options.ts does not
forward React Query's AbortSignal, so cancelable requests aren't used; update
the async queryFn inside queryOptions to accept the context ({ signal }) or
destructure signal from its params and pass that signal into callREST (the
callREST invocation used to fetch "/witnesses/{witness-name}/voters") so
in-flight requests are aborted when queries are cancelled (keep existing
QueryKeys.witnesses.voters, page/pageSize/sort/direction usage).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/web/src/app/witnesses/_components/witness-voters-dialog.tsx`:
- Around line 79-81: The onChange handlers in witness-voters-dialog.tsx only
call setSearchText, which can leave the UI on a later page and show an empty
result; update those handlers (the ones calling setSearchText) to also reset
pagination to page 1 by invoking your pagination setter (e.g., setPage(1) or
setCurrentPage(1)/setPageIndex(1) depending on the existing state variable)
immediately after setSearchText, and make the identical change for the other
onChange instance referenced in the comment.

---

Nitpick comments:
In `@packages/sdk/src/modules/witnesses/queries/get-witnesses-query-options.ts`:
- Around line 125-138: The queryFn in get-witnesses-query-options.ts does not
forward React Query's AbortSignal, so cancelable requests aren't used; update
the async queryFn inside queryOptions to accept the context ({ signal }) or
destructure signal from its params and pass that signal into callREST (the
callREST invocation used to fetch "/witnesses/{witness-name}/voters") so
in-flight requests are aborted when queries are cancelled (keep existing
QueryKeys.witnesses.voters, page/pageSize/sort/direction usage).
🪄 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: Pro

Run ID: f7ae812e-7437-4749-9156-c5346432bc20

📥 Commits

Reviewing files that changed from the base of the PR and between de60689 and e6feaa8.

⛔ Files ignored due to path filters (7)
  • packages/sdk/dist/browser/index.d.ts is excluded by !**/dist/**
  • packages/sdk/dist/browser/index.js is excluded by !**/dist/**
  • packages/sdk/dist/browser/index.js.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.cjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.cjs.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.mjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.mjs.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (3)
  • apps/web/src/app/witnesses/_components/witness-voters-dialog.tsx
  • packages/sdk/src/modules/core/query-keys.ts
  • packages/sdk/src/modules/witnesses/queries/get-witnesses-query-options.ts

Comment on lines +79 to +81
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setSearchText(e.target.value)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Reset to page 1 when search text changes.

With page-scoped data, searching on a later page can show a false empty state. Reset page on input change to reduce that mismatch.

Suggested fix
-              onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
-                setSearchText(e.target.value)
-              }
+              onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
+                setSearchText(e.target.value);
+                setPage(1);
+              }}

Also applies to: 87-88

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/src/app/witnesses/_components/witness-voters-dialog.tsx` around
lines 79 - 81, The onChange handlers in witness-voters-dialog.tsx only call
setSearchText, which can leave the UI on a later page and show an empty result;
update those handlers (the ones calling setSearchText) to also reset pagination
to page 1 by invoking your pagination setter (e.g., setPage(1) or
setCurrentPage(1)/setPageIndex(1) depending on the existing state variable)
immediately after setSearchText, and make the identical change for the other
onChange instance referenced in the comment.

@feruzm feruzm added the patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR label Apr 28, 2026
@feruzm feruzm merged commit db06713 into develop Apr 28, 2026
1 check was pending
@feruzm feruzm deleted the load branch April 28, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant