solution#1474
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on the core pagination functionality! The component is well-structured and handles most of the display logic correctly. However, a few key requirements are missing, so I am requesting changes before approval.
The most critical missing piece is the integration with React Router in src/App.tsx. The task requires using URL query parameters to manage the page and perPage state, allowing the component to initialize from the URL and update it on changes.
Additionally, in src/components/Pagination/Pagination.tsx, please address two points:
- The
onPageChangecallback should only be triggered if the selected page is different from the current one. - The
currentPageprop's type should be optional (currentPage?: number) to match the requirements.
Once these items are addressed, your solution will be in great shape!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| const total = 42; | ||
| //const perPage = 5; | ||
|
|
||
| export const App: React.FC = () => { |
There was a problem hiding this comment.
This component is missing the requirement to integrate with React Router. The task specifies that page and perPage should be stored in the URL as query parameters (e.g., ?page=2&perPage=7) and used to initialize the state when the page loads.
| type Props = { | ||
| total: number; | ||
| perPage: number; | ||
| currentPage: number; |
There was a problem hiding this comment.
According to the task description, the currentPage prop should be optional (currentPage?: number). The current type definition makes it a required prop.
| href={`#${page}`} | ||
| onClick={e => { | ||
| e.preventDefault(); | ||
| onPageChange(page); |
There was a problem hiding this comment.
The requirements state that the onPageChange callback should be triggered 'only if page was changed'. Currently, it's called even if the user clicks on the currently active page. You should add a condition to call this function only when the new page is different from the current one.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on the component logic and React Router integration! The functionality is well-implemented and meets the core requirements.
However, this requires changes because all 25 automated tests are failing. The test runner cannot find the necessary elements to verify the component's behavior because the data-cy attributes are missing from your JSX code.
Please add the following attributes to their corresponding elements:
data-cy="perPageSelector"data-cy="prevLink"data-cy="nextLink"data-cy="pageLink"data-cy="item"
Once you add these attributes, the tests should pass, and your solution will be ready for approval. You're very close to finishing this!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job on the component logic and your use of React Router for state management! I'm approving your submission as an educational override to help you keep moving forward. Please be aware that the automated tests are currently failing because they can't find key elements. This indicates that required data-cy attributes like pageLink, prevLink, and perPageSelector are missing from your JSX. Please take a moment to add these attributes, as it's a crucial step for building testable applications. You're doing great work, keep it up!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
brespect
left a comment
There was a problem hiding this comment.
Almost done, also try to pass all tests before requesting the review
|
|
||
| export const Pagination: React.FC<Props> = ({ | ||
| total, | ||
| perPage, |
There was a problem hiding this comment.
no validation — user can pass any value via URL.
| const [searchParams, setSearchParams] = useSearchParams(); | ||
|
|
||
| const currentPage = Number(searchParams.get('page')) || 1; | ||
| const perPage = Number(searchParams.get('perPage')) || 5; |
There was a problem hiding this comment.
better to have validation - for now, can enter ?perPage=9999
| const startIndex = (currentPage - 1) * perPage; | ||
| const visibleItems = items.slice(startIndex, startIndex + perPage); |
There was a problem hiding this comment.
potential bug here, if currentPage > max pages → the array will be empty, need clamp:
const totalPages = Math.ceil(total / perPage);
const safePage = Math.min(currentPage, totalPages);
DEMO LINK