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

Block Library: Add the Comments Pagination Next block #36562

Merged
merged 14 commits into from
Dec 20, 2021

Conversation

cbravobernal
Copy link
Contributor

@cbravobernal cbravobernal commented Nov 17, 2021

Description

We are adding the Next Comments block for FSE with this PR. Will close #35008 once is done.

How has this been tested?

  • Create a Comment Query Loop inside a post or a page.
  • Add pagination.
  • Check arrows are working, including RTL version.
  • Check that if you are on the last page, the link is not appearing.

Screenshots

https://loom.com/share/553a6762010747c7ba591a208c4a8a34

Types of changes

  • New feature. New core block.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@github-actions
Copy link

github-actions bot commented Nov 17, 2021

Size Change: +289 B (0%)

Total Size: 1.13 MB

Filename Size Change
build/block-library/blocks/comments-pagination/style-rtl.css 242 B +7 B (+3%)
build/block-library/blocks/comments-pagination/style.css 237 B +6 B (+3%)
build/block-library/blocks/navigation/style-rtl.css 1.69 kB -1 B (0%)
build/block-library/blocks/navigation/style.css 1.68 kB +1 B (0%)
build/block-library/index.min.js 164 kB +257 B (0%)
build/block-library/style-rtl.css 10.8 kB +11 B (0%)
build/block-library/style.css 10.8 kB +8 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 960 B
build/admin-manifest/index.min.js 1.1 kB
build/annotations/index.min.js 2.75 kB
build/api-fetch/index.min.js 2.21 kB
build/autop/index.min.js 2.12 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.28 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/index.min.js 140 kB
build/block-editor/style-rtl.css 14.6 kB
build/block-editor/style.css 14.6 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 291 B
build/block-library/blocks/buttons/editor.css 291 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 134 B
build/block-library/blocks/code/theme.css 134 B
build/block-library/blocks/columns/editor-rtl.css 210 B
build/block-library/blocks/columns/editor.css 208 B
build/block-library/blocks/columns/style-rtl.css 502 B
build/block-library/blocks/columns/style.css 501 B
build/block-library/blocks/comment-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.22 kB
build/block-library/blocks/cover/style.css 1.22 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 966 B
build/block-library/blocks/gallery/editor.css 970 B
build/block-library/blocks/gallery/style-rtl.css 1.63 kB
build/block-library/blocks/gallery/style.css 1.62 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 810 B
build/block-library/blocks/image/editor.css 809 B
build/block-library/blocks/image/style-rtl.css 507 B
build/block-library/blocks/image/style.css 511 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 649 B
build/block-library/blocks/navigation-link/editor.css 650 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.91 kB
build/block-library/blocks/navigation/editor.css 1.91 kB
build/block-library/blocks/navigation/view.min.js 2.82 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 172 B
build/block-library/blocks/page-list/style.css 172 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 446 B
build/block-library/blocks/post-comments-form/style.css 446 B
build/block-library/blocks/post-comments/style-rtl.css 507 B
build/block-library/blocks/post-comments/style.css 507 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 391 B
build/block-library/blocks/post-template/style.css 392 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 389 B
build/block-library/blocks/pullquote/style.css 388 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 273 B
build/block-library/blocks/query-pagination/style.css 269 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 245 B
build/block-library/blocks/separator/style.css 245 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 744 B
build/block-library/blocks/site-logo/editor.css 744 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 670 B
build/block-library/blocks/social-links/editor.css 669 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB
build/block-library/blocks/social-links/style.css 1.32 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 560 B
build/block-library/blocks/template-part/editor.css 559 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 569 B
build/block-library/blocks/video/editor.css 570 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 910 B
build/block-library/common.css 908 B
build/block-library/editor-rtl.css 10 kB
build/block-library/editor.css 10 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/theme-rtl.css 675 B
build/block-library/theme.css 679 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 46.3 kB
build/components/index.min.js 214 kB
build/components/style-rtl.css 15.5 kB
build/components/style.css 15.5 kB
build/compose/index.min.js 11.2 kB
build/core-data/index.min.js 13.2 kB
build/customize-widgets/index.min.js 11.4 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 631 B
build/data/index.min.js 7.49 kB
build/date/index.min.js 31.9 kB
build/deprecated/index.min.js 485 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.5 kB
build/edit-navigation/index.min.js 16 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.4 kB
build/edit-post/style-rtl.css 7.13 kB
build/edit-post/style.css 7.13 kB
build/edit-site/index.min.js 35.6 kB
build/edit-site/style-rtl.css 6.61 kB
build/edit-site/style.css 6.6 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.18 kB
build/edit-widgets/style.css 4.18 kB
build/editor/index.min.js 37.9 kB
build/editor/style-rtl.css 3.75 kB
build/editor/style.css 3.74 kB
build/element/index.min.js 3.29 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 6.58 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.63 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.71 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.8 kB
build/keycodes/index.min.js 1.39 kB
build/list-reusable-blocks/index.min.js 1.72 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 925 B
build/nux/index.min.js 2.08 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.84 kB
build/primitives/index.min.js 924 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.65 kB
build/reusable-blocks/index.min.js 2.22 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11 kB
build/server-side-render/index.min.js 1.57 kB
build/shortcode/index.min.js 1.49 kB
build/token-list/index.min.js 639 B
build/url/index.min.js 1.9 kB
build/viewport/index.min.js 1.05 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.15 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@gziolo gziolo added [Block] Comments Affects the Comments Block - formerly known as Comments Query Loop New Block Suggestion for a new block labels Nov 18, 2021
@gziolo gziolo changed the title Add/comments pagination next Block Library: Add Comments Pagination Next block Nov 18, 2021
@gziolo gziolo changed the title Block Library: Add Comments Pagination Next block Block Library: Add the Comments Pagination Next block Nov 18, 2021
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

This PR depends on the PR that implements the Comments Pagination block so let’s wait with testing once everything is integrated. It looks great so far 👍

}
/>
{ displayArrow && (
<span className={ `wp-block-query-pagination-next-arrow` }>
Copy link
Member

Choose a reason for hiding this comment

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

It looks like a copy and paste issue:

Suggested change
<span className={ `wp-block-query-pagination-next-arrow` }>
<span className="wp-block-comments-pagination-next-arrow">

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not 😅 . The function that renders the arrow has that class hardcoded, so, in order to be the same both in editor and frontend and also with the same styles of the query pagination, should include that name.

packages/block-library/src/query-pagination-next/edit.js Outdated Show resolved Hide resolved
@gziolo gziolo added the [Status] In Progress Tracking issues with work in progress label Nov 29, 2021
@cbravobernal cbravobernal force-pushed the add/comments-pagination-next branch 2 times, most recently from 4abd6ea to 103068c Compare December 1, 2021 15:54
@gziolo
Copy link
Member

gziolo commented Dec 2, 2021

Huh, I see some failing tests completely unrelated to this PR. Do they exist on trunk, too?

}

return sprintf(
'<div %1s>%2s</div>',
Copy link
Member

Choose a reason for hiding this comment

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

In the edit implementation we apply block wrapper attributes to the <a> tag. Should we align that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we should remove the extraneous div here.

</span>
) }
</a>
<div { ...useBlockProps() }>
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove those changes from this PR, it was fixed already by @ntsekouras.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we should not forget about this 😄

@@ -0,0 +1 @@
<!-- wp:comments-pagination-next /-->
Copy link
Member

Choose a reason for hiding this comment

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

Should we include some customized attributes in the test fixtures?

* @return string Returns the next comments link for the query pagination.
*/
function render_block_core_comments_pagination_next( $attributes, $content, $block ) {
$comments_per_page = isset( $block->context['queryPerPage'] ) ? $block->context['queryPerPage'] : 4;
Copy link
Member

Choose a reason for hiding this comment

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

Where does the fallback value 4 come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was the default setting on Query Comment Loop a few days ago. As this is coming from the parent block. I think it would be good to remove it.

@@ -37,17 +39,18 @@ export default function QueryPaginationEdit( {
const innerBlocks = getBlocks( clientId );
/**
* Show the `paginationArrow` control only if a
* `QueryPaginationNext/Previous` block exists.
* `CommentsPaginationNext/Previous` block exists.
Copy link
Member

@gziolo gziolo Dec 2, 2021

Choose a reason for hiding this comment

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

Suggested change
* `CommentsPaginationNext/Previous` block exists.
* Comments Pagination Next block exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's merge first the Comments Pagination Previous. And after that we can update with:
Comments Pagination Next and/or Previous

Copy link
Member

Choose a reason for hiding this comment

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

Whatever works best. From my perspective, we can land this PR first because the other one still needs to be reviewed 😄

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

This PR tests well. This is what I see.

Frontend:
Screenshot 2021-12-02 at 13 05 30

Editor:
Screenshot 2021-12-02 at 13 05 40

There are some subtle differences in how the wrappers are rendered that might be related to the <div> vs <a> that I commented about.

Overall, it's good to go once all the nitpicks are addressed.

@gziolo gziolo removed the [Status] In Progress Tracking issues with work in progress label Dec 2, 2021
@cbravobernal
Copy link
Contributor Author

I updated the code in order to have the frontend styled. I'm not sure if we can still edit get_query_pagination_arrow in order to work both with comments and query loops, or it's better to create a similar function just for the comments arrow.

Attached a video with the explanation:
https://www.loom.com/share/4c9e2bdc2cba4bb08a330df59c69f45d

What do you think?
cc @gziolo @DAreRodz @michalczaplinski @ntsekouras

@cbravobernal
Copy link
Contributor Author

Huh, I see some failing tests completely unrelated to this PR. Do they exist on trunk, too?

Seems so, is happening on other PRs as well.

@DAreRodz
Copy link
Contributor

DAreRodz commented Dec 2, 2021

Why don't we simply use CSS to render the arrows? That way, the code won't depend on PHP functions that could change in future versions, am I right? Maybe there are some things ― RTL, accessibility, backwards compatibility, etc. ― that should be taken into consideration, and would invalidate this approach… Please, let me know. 😅

Anyway, for example, we could use the following styles for the Comments Pagination Next block inside styles.scss:

> .wp-block-comments-pagination-next {
  &::after {
    margin-left: 1ch;
    display: inline-block;
  }

  &.use-arrow-chevron::after {
    content: "»";
  }
  &.use-arrow-arrow::after {
    content: "";
    transform: scaleX(1) #{"/*rtl:scaleX(-1);*/"}; // This points the arrow right for LTR and left for RTL.
  }
}

…and then, in index.php, add the use-arrow-arrow, use-arrow-chevron, or nothing, as needed, and the correct arrow will be shown. Code logic would be simpler as well. 🤔

$arrow_attribute    = $block->context['paginationArrow'];
$wrapper_attributes = get_block_wrapper_attributes(
    array(
        'class' => "use-arrow-$arrow_attribute"
    )
);

@cbravobernal
Copy link
Contributor Author

cbravobernal commented Dec 2, 2021

― RTL, accessibility, backwards compatibility, etc. ―

In this case, it seems to be an accessibility issue.

The main issue here is the get_query_pagination_arrow providing classes. Maybe an option would be to add the class with get_block_wrapper_attributes as you mention, in each block, and remove the class provided in that function, being more flexible.

But we have to edit that function, and I don't know if we can do it or not 😓

@DAreRodz
Copy link
Contributor

DAreRodz commented Dec 3, 2021

In this case, it seems to be an accessibility issue.

Oh, I didn't know that. Thanks for the info, @c4rl0sbr4v0. 😊

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks for your work here @c4rl0sbr4v0 !

I'm not sure if we can still edit get_query_pagination_arrow in order to work both with comments and query loops, or it's better to create a similar function just for the comments arrow.

I think it's okay to just change the function now since it's going to be introduced in 5.9, but we would need to backport the change to core.

Having said that, I don't find it bad to actually use the existing css class as well, though. If we are planning to have this display arrow functionality synced, using the .wp-block-query-pagination- prefix, could work for both these blocks as they are actually both query blocks (posts/comments) and they are already wrapped inside their parent block.

lib/compat/wordpress-5.9.1/blocks.php Outdated Show resolved Hide resolved
lib/load.php Outdated Show resolved Hide resolved
"type": "string"
}
},
"usesContext": [ "postId", "queryPerPage", "paginationArrow" ],
Copy link
Contributor

Choose a reason for hiding this comment

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

When we are at the place of testing these blocks inside a Query Loop we'll need to make sure to check the context name for queryPerPage as we had discussed before - aliased context if needed or not.

Not a blocker of course for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gziolo started working on that in #37196
We will keep an eye there!

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it needs to be updated. I think we should also add the namespace to the pagination arrow context value.

}

return sprintf(
'<div %1s>%2s</div>',
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we should remove the extraneous div here.

</span>
) }
</a>
<div { ...useBlockProps() }>
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we should not forget about this 😄

if ( $pagination_arrow ) {
$label .= $pagination_arrow;
}
$next_comments_link = get_next_comments_link( $label, $max_page );
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't make the pagination work as expected. I'm not sure the implementation here is correct as we have a custom Comments query and get_next_comments_link internally uses the global query $page = get_query_var( 'cpage' );

I guess we should take into account get_approved_comments that is used in the parent block to fetch the comments and we might probably need to make a new custom query ourselves, similar to QueryPagination blocks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that there were some recent changes in query pagination blocks that I'll have to check first, but the fact that I couldn't make this work as expected, still stands.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm updating the code with a lot of changes that were requested if you prefer to wait for them.

How is your discussion settings configured? Maybe we have a different configuration there.

Maybe we need the comment query loop working with pagination at first, although we have already the page numbers working, so I will keep taking a look at it to have it working as expected.

Regarding

I guess we should take into account get_approved_comments that is used in the parent block to fetch the comments and we might probably need to make a new custom query ourselves, similar to QueryPagination blocks.

We started a discussion about that right here! I think now is starting to get more relevant the requirement of having a multi-query loop for comments.

Screenshot 2021-12-03 at 16 53 19

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! It's helping quite a lot to move the comments pagination forward.

I couldn't make the pagination work as expected. I'm not sure the implementation here is correct as we have a custom Comments query and get_next_comments_link internally uses the global query $page = get_query_var( 'cpage' );

You are adding the block outside a post or page? If this help you, I have these Discussion settings:

Screenshot 2021-12-03 at 16 53 19

If you are not and it is not working, we should also have to take a look at the Comment Pagination, as I think we are using there also the cpage query var.

I guess we should take into account get_approved_comments that is used in the parent block to fetch the comments and we might probably need to make a new custom query ourselves, similar to QueryPagination blocks.

We started a discussion about that here! Maybe this issue will help us understand the requirement of having multi-query comments like in the Query. I will add it to the conversation.

@cbravobernal cbravobernal marked this pull request as draft December 3, 2021 16:07
@cbravobernal cbravobernal marked this pull request as ready for review December 9, 2021 16:13
Comment on lines 14 to 20
function add_next_comments_link_attributes() {
if ( ! function_exists( 'get_block_wrapper_attributes' ) ) {
return;
}
return get_block_wrapper_attributes();
}
add_filter( 'next_comments_link_attributes', 'add_next_comments_link_attributes' );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this a good way to add the attributes to the a tag?
cc: @gziolo @ntsekouras

Copy link
Member

Choose a reason for hiding this comment

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

I think I don't know the answer. Why do we need to use the filter here? Maybe we need a different implementation fo get_next_comments_link instead?

As far as I can tell get_next_comments_link works only with the singular page so it reads everything from the WordPress's page context. If we want to support custom settings for order, items per page, etc... then we need a custom implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't followed all the discussions about where the comment blocks are going, but with this approach get_next_comments_link and using the global query, I think this is a good way to add the attributes. That's what I did for Query pagination blocks. The thing is though that you should add the filter inside the render function and then you have to remove_filter before exiting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only way I found to provide HTML attributes without a wrapper, directly into the <a> tag.

* @return string Returns the styles and classes defined on the block editor for the block.
*/
function add_next_comments_link_attributes() {
if ( ! function_exists( 'get_block_wrapper_attributes' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines 14 to 20
function add_next_comments_link_attributes() {
if ( ! function_exists( 'get_block_wrapper_attributes' ) ) {
return;
}
return get_block_wrapper_attributes();
}
add_filter( 'next_comments_link_attributes', 'add_next_comments_link_attributes' );
Copy link
Member

Choose a reason for hiding this comment

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

I think I don't know the answer. Why do we need to use the filter here? Maybe we need a different implementation fo get_next_comments_link instead?

As far as I can tell get_next_comments_link works only with the singular page so it reads everything from the WordPress's page context. If we want to support custom settings for order, items per page, etc... then we need a custom implementation.

"type": "string"
}
},
"usesContext": [ "postId", "queryPerPage", "paginationArrow" ],
Copy link
Member

Choose a reason for hiding this comment

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

Yes, it needs to be updated. I think we should also add the namespace to the pagination arrow context value.

lib/blocks.php Show resolved Hide resolved
@@ -32,6 +32,6 @@
}
}
},
"editorStyle": "wp-block-comments-pagination-editor",
"style": "wp-block-comments-pagination"
"editorStyle": "wp-block-query-pagination-editor",
Copy link
Member

Choose a reason for hiding this comment

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

Does it mean it reuses the styles from the Query Pagination block?

I'm wondering how much overlap there really is between comments and posts. For comments, I think there are now links for older/newer comments instead of next/previous page. It doesn't mean we can't change it. However, it would be great to clarify the design.

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem right. If we need some styles we should copy them and add the specificity of the comments block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This reuses the styles due to this function , it is applying a class to the arrow with that name.

Should we create a new function to render the arrow for comments?

Could I add a new variable to set if it is a query or a comment instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still confused why we need a change here. And actually this results in not loading this block styles (change comments-pagination/styles.scss and check the frontend). I think we can reuse the get_query_pagination_arrow function which adds a css class like wp-block-query-pagination-..., just copy the related styles from QueryPagination styles with any small possible needed adjustments - the styles will be wrapped under each block's base css class, and finally remove this change:

get_block_wrapper_attributes( array( 'class' => 'wp-block-query-pagination' ) )

You made the above change for this styling issues, no? If not can you share the reason for adding it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your patience and sorry for messing this issue so much 😓

The reason of get_block_wrapper_attributes( array( 'class' => 'wp-block-query-pagination' ) ) is because we are not getting the styles in editor / frontend, due to the block has the parent class wp-block-**comment**-pagination instead of wp-block-**query**-pagination on the parent.

For the arrow, the function get_query_pagination_arrow adds the child class wp-block-query-pagination-$pagination_type-arrow.

So, in order to have the correct styling, we need .wp-block-query-pagination .wp-block-query-pagination-type-arrow

The SCSS files on the pagination block, being the same as query pagination, won't be loaded if we only have a Comment Query Loop. That's the reason why we need them to be duplicated in both blocks.

Anyway, let's better make a small refactor to have everything clear, I'll keep you updated!

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries at all @c4rl0sbr4v0, there are a lot of subtle things here. You are doing great work here not messing anything! 😄

Copy link
Member

Choose a reason for hiding this comment

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

The more I read about those styles, the more I think that we should build a completely independent logic for the Comments Pagination block. The styles used for Query Pagination are tied to the default class names generated for those blocks and it's only 50-ish lines of code:
https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/query-pagination/style.scss

The PHP implementation for the get_query_pagination_arrow is 20 lines of code:

function get_query_pagination_arrow( $block, $is_next ) {
$arrow_map = array(
'none' => '',
'arrow' => array(
'next' => '',
'previous' => '',
),
'chevron' => array(
'next' => '»',
'previous' => '«',
),
);
if ( ! empty( $block->context['paginationArrow'] ) && array_key_exists( $block->context['paginationArrow'], $arrow_map ) && ! empty( $arrow_map[ $block->context['paginationArrow'] ] ) ) {
$pagination_type = $is_next ? 'next' : 'previous';
$arrow_attribute = $block->context['paginationArrow'];
$arrow = $arrow_map[ $block->context['paginationArrow'] ][ $pagination_type ];
$arrow_classes = "wp-block-query-pagination-$pagination_type-arrow is-arrow-$arrow_attribute";
return "<span class='$arrow_classes'>$arrow</span>";
}
return null;
}

It hardcodes the class name and the context entry that is tied to the Query Pagination block.

@cbravobernal
Copy link
Contributor Author

cbravobernal commented Dec 16, 2021

The PR is ready to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Comments Affects the Comments Block - formerly known as Comments Query Loop New Block Suggestion for a new block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Post Comments Pagination Next block
4 participants