From eb0fdfb00b997bc86a3a4c444023dcd01f3e957d Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Tue, 23 Aug 2022 14:05:49 +1000
Subject: [PATCH 1/2] Prevent text-decoration from affecting warning
---
.../src/post-comments-count/edit.js | 26 ++++++++++++-------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/packages/block-library/src/post-comments-count/edit.js b/packages/block-library/src/post-comments-count/edit.js
index 2b3d309082495..593f855565274 100644
--- a/packages/block-library/src/post-comments-count/edit.js
+++ b/packages/block-library/src/post-comments-count/edit.js
@@ -17,6 +17,18 @@ import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
import { __ } from '@wordpress/i18n';
+const NoCommentsWarning = ( { style, ...props } ) => {
+ // Text decoration is stripped as it can't be reset as per other styles.
+ const { textDecoration, ...blockStyles } = style || {};
+ return (
+
+
+ { __( 'Post Comments Count block: post not found.' ) }
+
+
+ );
+};
+
export default function PostCommentsCountEdit( {
attributes,
context,
@@ -59,15 +71,11 @@ export default function PostCommentsCountEdit( {
} }
/>
-
- { postId && commentsCount !== undefined ? (
- commentsCount
- ) : (
-
- { __( 'Post Comments Count block: post not found.' ) }
-
- ) }
-
+ { postId && commentsCount !== undefined ? (
+ { commentsCount }
+ ) : (
+
+ ) }
>
);
}
From 91799d2df72a95d1b7149ec9fe6e4f5efaea5823 Mon Sep 17 00:00:00 2001
From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Date: Tue, 23 Aug 2022 15:23:00 +1000
Subject: [PATCH 2/2] Fix block selection
The previous changes broke selection of the block. This refactor allows the block to be selectable again.
---
.../src/post-comments-count/edit.js | 34 +++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/packages/block-library/src/post-comments-count/edit.js b/packages/block-library/src/post-comments-count/edit.js
index 593f855565274..e5d0ec9352eda 100644
--- a/packages/block-library/src/post-comments-count/edit.js
+++ b/packages/block-library/src/post-comments-count/edit.js
@@ -17,18 +17,6 @@ import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
import { __ } from '@wordpress/i18n';
-const NoCommentsWarning = ( { style, ...props } ) => {
- // Text decoration is stripped as it can't be reset as per other styles.
- const { textDecoration, ...blockStyles } = style || {};
- return (
-
-
- { __( 'Post Comments Count block: post not found.' ) }
-
-
- );
-};
-
export default function PostCommentsCountEdit( {
attributes,
context,
@@ -61,6 +49,14 @@ export default function PostCommentsCountEdit( {
} );
}, [ postId ] );
+ const hasPostAndComments = postId && commentsCount !== undefined;
+ const blockStyles = {
+ ...blockProps.style,
+ textDecoration: hasPostAndComments
+ ? blockProps.style?.textDecoration
+ : undefined,
+ };
+
return (
<>
@@ -71,11 +67,15 @@ export default function PostCommentsCountEdit( {
} }
/>
- { postId && commentsCount !== undefined ? (
- { commentsCount }
- ) : (
-
- ) }
+
+ { hasPostAndComments ? (
+ commentsCount
+ ) : (
+
+ { __( 'Post Comments Count block: post not found.' ) }
+
+ ) }
+
>
);
}