-
Notifications
You must be signed in to change notification settings - Fork 101
fix(pvi-volume-backup): fix loadMore pagination display condition #17144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ref: #DTCORE-3345 Signed-off-by: LIDRISSI Hamid <lidrissi.hamid@gmail.com>
@@ -148,7 +148,7 @@ export function useVolumeBackups<T extends Record<string, unknown>>({ | |||
flattenData: flattenData?.slice(0, (pageIndex + 1) * pageSize), | |||
isError, | |||
isLoading, | |||
hasNextPage: pageIndex * pageSize + pageSize <= flattenData?.length, | |||
hasNextPage: pageIndex * pageSize + pageSize < flattenData?.length, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make the intent more explicit by first calculating the total number of pages or by giving the variables clear, descriptive names:
const totalItems = flattenData?.length ?? 0;
const currentItemCount = (pageIndex + 1) * pageSize;
const hasNextPage = currentItemCount < totalItems;
@@ -148,7 +148,7 @@ export function useVolumeBackups<T extends Record<string, unknown>>({ | |||
flattenData: flattenData?.slice(0, (pageIndex + 1) * pageSize), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, do not use these kinds of computations, but rather a select
function that flattens data
@@ -148,7 +148,7 @@ export function useVolumeBackups<T extends Record<string, unknown>>({ | |||
flattenData: flattenData?.slice(0, (pageIndex + 1) * pageSize), | |||
isError, | |||
isLoading, | |||
hasNextPage: pageIndex * pageSize + pageSize <= flattenData?.length, | |||
hasNextPage: pageIndex * pageSize + pageSize < flattenData?.length, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use a useInfiniteQuery
hook instead that automatically returns hasNextPage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will remove all boilerplate code from your hook :)
@StephaneRavet @fredericvilcot I completely agree with you, there are several aspects of this component that need to be reviewed. However, please note that this component is largely a copy/paste from MRC, with some minor adjustments made to fit our needs. A refactor PR has already been opened and is currently under discussion with the MRC team in this context. Thanks for u're feedbacks. |
ref: #DTCORE-3345
Description
Ticket Reference: #...
Additional Information