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

Show 'Page 1 of 1' instead of 'Page 1 of 0'. #1413

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

devdanzin
Copy link
Member

This trivial PR intends to fix #1412 and plone/Products.CMFPlone#3591 by checking that totalPages is zero and setting it to one.

Copy link
Member

@thet thet left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the PR!

Some remarks though:

  1. We're using automatic changelog generation based on commit messages using release-it, conventional-changelog and commitlint. Please change your commit message according to:
    https://github.com/Patternslib/Patterns/blob/master/docs/developer/styleguide.md#commits-messages

If you even add Fixes: ... speficiers, than you automatically reference and close the related issues.

My suggestion:

fix(pat-structure): If there are no search results, still show "Page 1 of 1" instead "Page 1 of 0".

Fixes: plone/mockup#1412
Fixes: plone/Products.CMFPlone#3591
  1. See my code suggestion. I think it's simpler and I don't know if Backbone goes unnecessarily crazy when changing some state attributes too often. My simplification assigns the value in one go.

Comment on lines 72 to 73
this.state.totalPages = Math.ceil(response.total / state.pageSize);
this.state.totalPages = this.state.totalPages === 0 ? 1 : this.state.totalPages;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.state.totalPages = Math.ceil(response.total / state.pageSize);
this.state.totalPages = this.state.totalPages === 0 ? 1 : this.state.totalPages;
// Calculate the number of pages and set it to "1" if there are no results.
this.state.totalPages = Math.ceil(response.total / state.pageSize) || 1;

@petschki
Copy link
Member

petschki commented Dec 3, 2024

Looking at the issue, I'd recomment to completely remove the pagination when there is no result in the listing. Would make more sense to me. Btw. thank you @devdanzin for contributing! We were talking briefly at the conference about the plone.protect issue. Very much appreciated!

@devdanzin
Copy link
Member Author

Thank you very much for the review!

1. We're using automatic changelog generation based on commit messages

I've adapted your suggestion, please let me know if it should be improved.

2. See my code suggestion.

I tried @petschki's suggestion of not showing the pagination text and it looks better to me. Please let me know which option we should go with and whether the code makes sense.

@devdanzin
Copy link
Member Author

I'd recomment to completely remove the pagination when there is no result in the listing.

Done, not sure whether it's better to leave the empty div or also make it conditional. I've left it in current form.

Btw. thank you @devdanzin for contributing! We were talking briefly at the conference about the plone.protect issue.

Thank you for the review and for helping me at the sprint!

Copy link
Member

@thet thet left a comment

Choose a reason for hiding this comment

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

Yes, not showing the pagination at all is even a better solution.
I lean towards not showing the div when there are no results because I favor simple, small and clean HTML output. But I'm OK with the current solution.

@petschki petschki merged commit 7d09cde into plone:master Dec 9, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid showing the message Page: 1 of 0 shown
3 participants