fix: add server-side sorting to user list, prevent client-side sort on paged data#6194
fix: add server-side sorting to user list, prevent client-side sort on paged data#6194DawnMoon1542 wants to merge 2 commits into
Conversation
…n paged data The user management table applied client-side sorting to the current page slice while pagination was handled server-side, causing ID-asc views to show pages out of order (e.g. 23-42, 3-22, 1-2). Backend: add sort_by/sort_order query params to GetAllUsers and SearchUsers with a column whitelist for safe ORDER BY generation. Frontend: pass sorting state to the API and reset to page 1 on sort change. Generic useDataTable hook now disables client-side sorted row model and sort UI for tables with manual pagination but no server-side sort handler.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughUser list and search now support validated server-side sorting. The users table tracks sorting state, sends sort parameters through the API, and resets pagination when sorting changes. Backend queries apply ordering before pagination, with tests covering ordered pages. ChangesUser sorting flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant UsersTable
participant UsersAPI
participant UserController
participant UserModel
participant Database
User->>UsersTable: Select column sort
UsersTable->>UsersAPI: Request sort_by and sort_order
UsersAPI->>UserController: Send sorted list/search request
UserController->>UserModel: Construct and pass UserSortOptions
UserModel->>Database: Order results before pagination
Database-->>UsersTable: Return ordered users
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 `@model/user.go`:
- Around line 52-61: Update UserSortOptions.Apply to append a secondary
ascending sort by the unique id column after the requested sort, while
preserving the selected column and sort direction as the primary ordering.
In `@web/default/src/features/users/components/users-table.tsx`:
- Around line 115-123: Update handleSortingChange so the setSorting updater only
computes and returns the next sorting state; move the conditional
onPaginationChange call outside that updater closure while preserving the page
reset when pagination.pageIndex is greater than zero.
🪄 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: f6056100-43a4-403b-8c8e-2e37e161a306
📒 Files selected for processing (8)
controller/user.gomodel/user.gomodel/user_pagination_test.goweb/default/src/components/data-table/hooks/use-data-table.tsweb/default/src/features/models/components/models-table.tsxweb/default/src/features/users/api.tsweb/default/src/features/users/components/users-table.tsxweb/default/src/features/users/types.ts
💤 Files with no reviewable changes (1)
- web/default/src/features/models/components/models-table.tsx
…t from state updater Append secondary ORDER BY id DESC when sorting by non-unique columns (quota, created_at, etc.) to prevent row duplication/skipping across OFFSET pages. Move onPaginationChange out of setSorting updater to avoid side effects inside a pure function (React Strict Mode double-invocation safety).
Note
This PR was authored with AI assistance.
📝 变更描述 / Description
The user management table applied client-side sorting to the current page slice while pagination was handled server-side, causing ID-asc views to show pages out of order (e.g. 23-42, 3-22, 1-2).
GetAllUsersandSearchUsersnow acceptsort_by/sort_orderquery params with a column whitelist generating safeORDER BYvia GORMclause.OrderByColumn.users-tablepasses sorting state to the API and resets to page 1 on sort change.useDataTablehook disables the client-side sorted row model and sort UI for any table withmanualPaginationbut no server-side sort handler, preventing the same class of bug elsewhere.🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
Summary by CodeRabbit