[#511] Fix pagination in Admin users list - #524
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @francisli, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the user experience for managing lists of users (Admin, Staff, Students) by implementing robust pagination. The changes span both the backend, where queries are now optimized for paginated data retrieval, and the frontend, where a new, more capable data table component handles display and navigation. Additionally, a new dialog component streamlines the process of adding new records, contributing to a more intuitive and responsive application.
Highlights
- Pagination Implementation: Introduced comprehensive pagination to the Admin, Staff, and Students user lists, allowing for efficient display and navigation of large datasets. This includes backend query modifications to support
pageandpageSizeparameters, and frontend updates to display pagination controls. - Data Table Component Enhancement: The generic
DataTablecomponent has been significantly upgraded to support pagination, mobile responsiveness, and improved sorting and search integration. It now includesTablePaginationfrom Material-UI. - New Dialog Component: A reusable
Dialogcomponent has been added to the design system, replacing the inline form rows for adding new records in the Admin and Staff pages. This improves the user experience for data entry. - Backend Query Refactoring: The
case_managerTRPC router queries (getMyStudentsAndIepInfoandgetMyParas) were refactored to return paginated results, includingrecords,totalCount, andtotalPages, instead of just an array of records. This involved addinglimitandoffsetclauses and a separate count query. - Styling and Responsiveness Improvements: Various CSS and Material-UI theme adjustments were made to improve the overall look and feel, especially for mobile devices. This includes changes to button font sizes, search input styling, header padding, and typography definitions.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces pagination to the Admin users list, as well as other lists like staff and students. This is a significant and valuable improvement, involving substantial refactoring on both the backend and frontend. The changes include updating API endpoints to handle pagination, overhauling the data table components to support paginated data, and introducing a new Dialog component for a better form submission experience. While the overall implementation is solid, I've identified a couple of critical issues where pagination is not correctly implemented on some pages, which would prevent it from working. I've also included some suggestions to improve code maintainability by reducing duplication in the backend.
| records: data?.records, | ||
| totalCount: data?.totalCount, |
There was a problem hiding this comment.
Pagination appears to be broken on this page. The Staff component is wrapped with withDataTablePage, which provides page and pageSize props. However, the component doesn't seem to be accepting these props and passing them to the trpc.user.getUsers.useQuery hook. This will result in the API always returning the first page of data, regardless of the pagination controls. Please update the Staff component to accept page and pageSize and pass them to the useQuery hook.
| let countQuery = req.ctx.db | ||
| .selectFrom("student") | ||
| .select(req.ctx.db.fn.countAll().as("count")) | ||
| .where("assigned_case_manager_id", "=", userId); | ||
| if (search) { | ||
| countQuery = countQuery.where((eb) => | ||
| eb.or([ | ||
| eb("student.first_name", "ilike", `%${search}%`), | ||
| eb("student.last_name", "ilike", `%${search}%`), | ||
| ]) | ||
| ); | ||
| } |
There was a problem hiding this comment.
To improve maintainability and reduce code duplication, consider creating a base query object that includes the common where and search logic. This base query can then be used for both the main data query and this count query. This avoids repeating the filtering logic and ensures consistency if the filters ever need to be updated.
| let countQuery = req.ctx.db | ||
| .selectFrom("user") | ||
| .select(req.ctx.db.fn.countAll().as("count")) | ||
| .innerJoin( | ||
| "paras_assigned_to_case_manager", | ||
| "user.user_id", | ||
| "paras_assigned_to_case_manager.para_id" | ||
| ) | ||
| .where("paras_assigned_to_case_manager.case_manager_id", "=", userId); | ||
| if (search) { | ||
| countQuery = countQuery.where((eb) => | ||
| eb.or([ | ||
| eb("user.first_name", "ilike", `%${search}%`), | ||
| eb("user.last_name", "ilike", `%${search}%`), | ||
| eb("user.email", "ilike", `%${search}%`), | ||
| ]) | ||
| ); | ||
| } |
There was a problem hiding this comment.
Similar to the getMyStudentsAndIepInfo endpoint, there's an opportunity to refactor and reduce code duplication here. The innerJoin, where clause, and search logic are repeated from the main query. Creating a base query that contains this common logic would make the code more maintainable and less error-prone.
No description provided.