Skip to content
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

Fix total count in show page #6462

Merged
merged 1 commit into from
Jul 30, 2024
Merged

Conversation

prateekj117
Copy link
Contributor

Fixes #6405

We need to take into account both the totalCount of before cursor results and after cursor results.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

The changes fix the total count display on the show page by separately tracking records before and after the cursor and combining these counts.

  • Modified packages/twenty-front/src/modules/object-record/record-show/hooks/useRecordShowPagePagination.ts to track and combine totalCountBefore and totalCountAfter.
  • Introduced logic to handle edge cases where total counts might be incorrectly combined.
  • Ensured accurate total count display even when the count is 1.

Potential issue: The logic for combining counts might still lead to inaccuracies in some edge cases.

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

Comment on lines 151 to 156
const totalCount =
totalCountBefore === 0
? totalCountAfter === 0
? 1
: totalCountAfter
: totalCountBefore;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Combining totalCountBefore and totalCountAfter using this logic might lead to incorrect counts if both are non-zero but not equal. Consider summing the counts instead.

@prateekj117
Copy link
Contributor Author

@charlesBochet Can help with a review on this?

@prateekj117 prateekj117 force-pushed the bug/issue-6405 branch 2 times, most recently from 9642211 to ae8b44e Compare July 30, 2024 16:03
if (totalCountBefore !== 0 && totalCountAfter !== 0) {
totalCount = Math.max(totalCountBefore, totalCountAfter);
} else {
totalCount =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalCount = (totalCountBefore === 0 && totalCountAfter === 0) ? 1 : Math.max(totalCountBefore, totalCountAfter)
I believe this should work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. That's a better way to write it. Let me correct this.

@prateekj117
Copy link
Contributor Author

@charlesBochet Ready for another round of review.

@@ -147,6 +148,11 @@ export const useRecordShowPagePagination = (

const objectLabel = capitalize(objectMetadataItem.namePlural);

const totalCount =
totalCountBefore === 0 && totalCountAfter === 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be even shorter

const totalCount = Math.max(1, totalCountBefore, totalCountAfter)

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@charlesBochet charlesBochet merged commit ee4f1da into twentyhq:main Jul 30, 2024
11 checks passed
charlesBochet pushed a commit that referenced this pull request Jul 31, 2024
Fixes #6405

We need to take into account both the totalCount of **before cursor**
results and **after cursor** results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix total count in show page navigation bar when total count = 1
3 participants