Skip to content

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

Merged
merged 1 commit into from
May 19, 2025

Conversation

seven-amid
Copy link
Contributor

ref: #DTCORE-3345

Description

Ticket Reference: #...

Additional Information

ref: #DTCORE-3345
Signed-off-by: LIDRISSI Hamid <lidrissi.hamid@gmail.com>
@seven-amid seven-amid requested a review from a team as a code owner May 16, 2025 08:50
@seven-amid seven-amid requested review from lionel95200x, Rom123Soleil and fredericvilcot and removed request for a team May 16, 2025 08:50
@github-actions github-actions bot added the bug Something isn't working label May 16, 2025
@@ -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,

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),
Copy link
Contributor

@fredericvilcot fredericvilcot May 19, 2025

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,
Copy link
Contributor

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

Copy link
Contributor

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 :)

@seven-amid
Copy link
Contributor Author

@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.
It would be great if you could still proceed with your review here https://github.com/ovh/manager/pull/16722/files, so we can later align and discuss everything together with the Control Tower team.

Thanks for u're feedbacks.

@seven-amid seven-amid merged commit 8381313 into feat/pci-volume-backup May 19, 2025
15 checks passed
@seven-amid seven-amid deleted the fix/DTCORE-3345 branch May 19, 2025 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants