Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: -3 B (0%) Total Size: 2.41 MB
ℹ️ View Unchanged
|
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR!
I've looked at the code for the two blocks, and they seem a bit redundant. In fact, the Warning component shouldn't be displayed at all, so I think I can remove it. Can't we simplify it to the following? However, I haven't tested it, so I'd appreciate it if you could check if it works properly.
diff --git a/packages/block-library/src/post-comments-count/edit.js b/packages/block-library/src/post-comments-count/edit.js
index 58ce64e680..dec83b99b5 100644
--- a/packages/block-library/src/post-comments-count/edit.js
+++ b/packages/block-library/src/post-comments-count/edit.js
@@ -9,13 +9,11 @@ import clsx from 'clsx';
import {
AlignmentControl,
BlockControls,
- Warning,
useBlockProps,
} from '@wordpress/block-editor';
import { useState, useEffect } from '@wordpress/element';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
-import { __ } from '@wordpress/i18n';
export default function PostCommentsCountEdit( {
attributes,
@@ -57,14 +55,6 @@ export default function PostCommentsCountEdit( {
: undefined,
};
- if ( ! postId ) {
- return (
- <div { ...blockProps }>
- <p>0</p>
- </div>
- );
- }
-
return (
<>
<BlockControls group="block">
@@ -76,13 +66,7 @@ export default function PostCommentsCountEdit( {
/>
</BlockControls>
<div { ...blockProps } style={ blockStyles }>
- { hasPostAndComments ? (
- commentsCount
- ) : (
- <Warning>
- { __( 'Post Comments Count block: post not found.' ) }
- </Warning>
- ) }
+ { hasPostAndComments ? commentsCount : '0' }
</div>
</>
);
diff --git a/packages/block-library/src/post-comments-link/edit.js b/packages/block-library/src/post-comments-link/edit.js
index 4821f7cdf8..0a277ab525 100644
--- a/packages/block-library/src/post-comments-link/edit.js
+++ b/packages/block-library/src/post-comments-link/edit.js
@@ -9,7 +9,6 @@ import clsx from 'clsx';
import {
AlignmentControl,
BlockControls,
- Warning,
useBlockProps,
} from '@wordpress/block-editor';
import { useState, useEffect } from '@wordpress/element';
@@ -59,31 +58,6 @@ function PostCommentsLinkEdit( { context, attributes, setAttributes } ) {
[ postType, postId ]
);
- if ( ! postId ) {
- return (
- <div { ...blockProps }>
- <a
- href="#post-comments-link-pseudo-link"
- onClick={ ( event ) => event.preventDefault() }
- >
- { __( 'No comments' ) }
- </a>
- </div>
- );
- }
-
- if ( ! post ) {
- return (
- <div { ...blockProps }>
- <Warning>
- { __( 'Post Comments Link block: post not found.' ) }
- </Warning>
- </div>
- );
- }
-
- const { link } = post;
-
let commentsText;
if ( commentsCount !== undefined ) {
const commentsNumber = parseInt( commentsCount );
@@ -111,17 +85,20 @@ function PostCommentsLinkEdit( { context, attributes, setAttributes } ) {
</BlockControls>
<div { ...blockProps }>
- { link && commentsText !== undefined ? (
+ { post?.link && commentsText !== undefined ? (
<a
- href={ link + '#comments' }
+ href={ post?.link + '#comments' }
onClick={ ( event ) => event.preventDefault() }
>
{ commentsText }
</a>
) : (
- <Warning>
- { __( 'Post Comments Link block: post not found.' ) }
- </Warning>
+ <a
+ href="#post-comments-link-pseudo-link"
+ onClick={ ( event ) => event.preventDefault() }
+ >
+ { __( 'No comments' ) }
+ </a>
) }
</div>
</>|
@t-hamano |
What?
Closes #73179
Why?
How?
Add fallback text to prevent the warning from being displayed when postId does not exist.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Before
comment-link.mp4
After
post-comment.mp4