-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Merge Comments and Post Comments blocks #41807
Merged
Merged
Changes from 39 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
26f6429
Merge the blocks and remove the old one
DAreRodz 7d13993
Fix comments block type registration
DAreRodz c279c95
Remove gutenberg prefix
DAreRodz 52162af
Fix a problem with multiple styles
DAreRodz 5db0aff
Update some comments
DAreRodz e8631ad
Fix php-lint errors
DAreRodz dd167e3
Move legacy part in edit to its own component
DAreRodz 5161e38
Fix typo
DAreRodz 38a924e
Replace comments_query_loop with comments
DAreRodz 8f84a2c
Improve the render callback's description
DAreRodz 4e2cfed
Fix the HTML returned for the non-legacy version
DAreRodz 378154c
Run npm run docs:build
ockham a190e91
Regenerate fixtures
ockham ff28b3d
Update warning message in the editor
DAreRodz 0195ed5
Fix string closing marks
DAreRodz febc24b
Add a button to switch from legacy to default
DAreRodz 3dfa5e0
Fix `useBlockProps` call after rebase
DAreRodz 35fda82
Add tests for Post Comments block support
DAreRodz 3db2eea
Simplify before/after functions
DAreRodz 5e2893d
Move Post Comments tests into its own describe
DAreRodz 249de8c
Move `createPost` to `requestUtils`
DAreRodz bb6d16b
Add missing newline
DAreRodz a2fcb4a
Add TS to playwright post utils
DAreRodz 47f7ae6
Add test to switch button
DAreRodz 64cc5b4
Update placeholder classname
DAreRodz ff8fe04
Use `setAttributes` to switch from legacy mode
DAreRodz 0ac9b0f
Regenerate fixtures
DAreRodz dc7a11e
Move Warning logic into Post Comments Form component
ockham 2360f68
Deduplicate
ockham 0ed0317
Inline warning
ockham 2afa3ec
Simplify
ockham 6c1ede5
Nicer on the eye
ockham ce8a1b7
A bit nicer still
ockham dc07681
Inlining is fun
ockham 03fbcff
i18n fix
ockham b9b69d2
Only count approved comments
DAreRodz 1e38f4d
Remove unnecessary warning in PHP
DAreRodz f609c85
Add tests for the `legacy` attribute
DAreRodz 8007e53
Fix the PHP render callback
DAreRodz 81cfd7d
Move comment about `setOptions` inside `forEach`
DAreRodz cf790fd
Make `setOptions` util stateless
DAreRodz 2007766
Remove `legacy: false`
DAreRodz 3a23e9f
Clarify "block version"
DAreRodz a93d0c7
Replace unnecessary backticks with single quotes
DAreRodz bef407c
Use `getEditedPostContent`
DAreRodz 85ec8d3
Slightly improve some comments
DAreRodz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/block-library/src/comments/edit/comments-legacy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
AlignmentControl, | ||
BlockControls, | ||
Warning, | ||
useBlockProps, | ||
} from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Placeholder from './placeholder'; | ||
|
||
export default function CommentsLegacy( { | ||
attributes, | ||
setAttributes, | ||
context: { postType, postId }, | ||
} ) { | ||
const { textAlign } = attributes; | ||
|
||
const actions = [ | ||
<Button | ||
key="convert" | ||
onClick={ () => void setAttributes( { legacy: false } ) } | ||
variant="primary" | ||
> | ||
{ __( 'Switch to editable mode' ) } | ||
</Button>, | ||
]; | ||
|
||
const blockProps = useBlockProps( { | ||
className: classnames( { | ||
[ `has-text-align-${ textAlign }` ]: textAlign, | ||
} ), | ||
} ); | ||
|
||
return ( | ||
<> | ||
<BlockControls group="block"> | ||
<AlignmentControl | ||
value={ textAlign } | ||
onChange={ ( nextAlign ) => { | ||
setAttributes( { textAlign: nextAlign } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
|
||
<div { ...blockProps }> | ||
<Warning actions={ actions }> | ||
{ __( | ||
"Comments block: You're currently using this block in legacy mode. " + | ||
'The following is just a placeholder, not a real comment. ' + | ||
'The final styling may differ because it also depends on the current theme. ' + | ||
'For better compatibility with the Block Editor, ' + | ||
'please consider switching the block to its editable mode.' | ||
) } | ||
</Warning> | ||
<Placeholder postId={ postId } postType={ postType } /> | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CommentsInspectorControls from './comments-inspector-controls'; | ||
import CommentsLegacy from './comments-legacy'; | ||
import TEMPLATE from './template'; | ||
|
||
export default function CommentsEdit( props ) { | ||
const { attributes, setAttributes } = props; | ||
const { tagName: TagName, legacy } = attributes; | ||
|
||
const blockProps = useBlockProps(); | ||
const innerBlocksProps = useInnerBlocksProps( blockProps, { | ||
template: TEMPLATE, | ||
} ); | ||
|
||
if ( legacy ) { | ||
return <CommentsLegacy { ...props } />; | ||
} | ||
|
||
return ( | ||
<> | ||
<CommentsInspectorControls | ||
attributes={ attributes } | ||
setAttributes={ setAttributes } | ||
/> | ||
<TagName { ...innerBlocksProps } /> | ||
</> | ||
); | ||
} |
124 changes: 124 additions & 0 deletions
124
packages/block-library/src/comments/edit/placeholder.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { useDisabled } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import CommentsForm from '../../post-comments-form/form'; | ||
|
||
export default function PostCommentsPlaceholder( { postType, postId } ) { | ||
let [ postTitle ] = useEntityProp( 'postType', postType, 'title', postId ); | ||
postTitle = postTitle || __( 'Post Title' ); | ||
|
||
const { avatarURL } = useSelect( | ||
( select ) => | ||
select( blockEditorStore ).getSettings() | ||
.__experimentalDiscussionSettings | ||
); | ||
|
||
const disabledRef = useDisabled(); | ||
|
||
return ( | ||
<div | ||
className="wp-block-comments__legacy-placeholder" | ||
ref={ disabledRef } | ||
> | ||
<h3> | ||
{ | ||
/* translators: %s: Post title. */ | ||
sprintf( __( 'One response to %s' ), postTitle ) | ||
} | ||
</h3> | ||
|
||
<div className="navigation"> | ||
<div className="alignleft"> | ||
<a href="#top">« { __( 'Older Comments' ) }</a> | ||
</div> | ||
<div className="alignright"> | ||
<a href="#top">{ __( 'Newer Comments' ) } »</a> | ||
</div> | ||
</div> | ||
|
||
<ol className="commentlist"> | ||
<li className="comment even thread-even depth-1"> | ||
<article className="comment-body"> | ||
<footer className="comment-meta"> | ||
<div className="comment-author vcard"> | ||
<img | ||
alt="Commenter Avatar" | ||
src={ avatarURL } | ||
className="avatar avatar-32 photo" | ||
height="32" | ||
width="32" | ||
loading="lazy" | ||
/> | ||
<b className="fn"> | ||
<a href="#top" className="url"> | ||
{ __( 'A WordPress Commenter' ) } | ||
</a> | ||
</b>{ ' ' } | ||
<span className="says">{ __( 'says' ) }:</span> | ||
</div> | ||
|
||
<div className="comment-metadata"> | ||
<a href="#top"> | ||
<time dateTime="2000-01-01T00:00:00+00:00"> | ||
{ __( 'January 1, 2000 at 00:00 am' ) } | ||
</time> | ||
</a>{ ' ' } | ||
<span className="edit-link"> | ||
<a | ||
className="comment-edit-link" | ||
href="#top" | ||
> | ||
{ __( 'Edit' ) } | ||
</a> | ||
</span> | ||
</div> | ||
</footer> | ||
|
||
<div className="comment-content"> | ||
<p> | ||
{ __( 'Hi, this is a comment.' ) } | ||
<br /> | ||
{ __( | ||
'To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.' | ||
) } | ||
<br /> | ||
{ __( 'Commenter avatars come from' ) }{ ' ' } | ||
<a href="https://gravatar.com/">Gravatar</a>. | ||
</p> | ||
</div> | ||
|
||
<div className="reply"> | ||
<a | ||
className="comment-reply-link" | ||
href="#top" | ||
aria-label="Reply to A WordPress Commenter" | ||
> | ||
{ __( 'Reply' ) } | ||
</a> | ||
</div> | ||
</article> | ||
</li> | ||
</ol> | ||
|
||
<div className="navigation"> | ||
<div className="alignleft"> | ||
<a href="#top">« { __( 'Older Comments' ) }</a> | ||
</div> | ||
<div className="alignright"> | ||
<a href="#top">{ __( 'Newer Comments' ) } »</a> | ||
</div> | ||
</div> | ||
|
||
<CommentsForm postId={ postId } postType={ postType } /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
@import "./style.scss"; | ||
|
||
.block-library-comments-toolbar__popover .components-popover__content { | ||
min-width: 230px; | ||
} | ||
|
||
.wp-block-comments__legacy-placeholder { | ||
@extend .wp-block-post-comments; | ||
* { | ||
pointer-events: none; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think
__()
(or rather, our string extraction util) is smart enough to handle basic string literal concatenation. See e.g. this test.