From ec11afa3d708243cda815fed2ed38f37be8c7ce3 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Fri, 22 Apr 2022 16:46:47 -0500 Subject: [PATCH 1/2] Improve the warning for Comments Form placeholder --- .../src/post-comments-form/edit.js | 73 ++++++++++++------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/packages/block-library/src/post-comments-form/edit.js b/packages/block-library/src/post-comments-form/edit.js index fbcd99d93f3f4..347b0a7e0ba2b 100644 --- a/packages/block-library/src/post-comments-form/edit.js +++ b/packages/block-library/src/post-comments-form/edit.js @@ -11,10 +11,11 @@ import { BlockControls, Warning, useBlockProps, + store as blockEditorStore, } from '@wordpress/block-editor'; -import { useEntityProp } from '@wordpress/core-data'; +import { useEntityProp, store as coreStore } from '@wordpress/core-data'; import { __, sprintf } from '@wordpress/i18n'; - +import { useSelect } from '@wordpress/data'; /** * Internal dependencies */ @@ -39,7 +40,49 @@ export default function PostCommentsFormEdit( { } ), } ); - const isInSiteEditor = postType === undefined || postId === undefined; + const isSiteEditor = postType === undefined || postId === undefined; + + const { defaultCommentStatus } = useSelect( + ( select ) => + select( blockEditorStore ).getSettings() + .__experimentalDiscussionSettings + ); + + const postTypeSupportsComments = useSelect( ( select ) => + postType + ? !! select( coreStore ).getPostType( postType )?.supports.comments + : false + ); + + let warning = false; + let showPlacholder = true; + + if ( ! isSiteEditor && 'open' !== commentStatus ) { + if ( 'closed' === commentStatus ) { + warning = sprintf( + /* translators: 1: Post type (i.e. "post", "page") */ + __( + 'Post Comments Form block: Comments on this %s are not allowed.' + ), + postType + ); + showPlacholder = false; + } else if ( ! postTypeSupportsComments ) { + warning = sprintf( + /* translators: 1: Post type (i.e. "post", "page") */ + __( + 'Post Comments Form block: Comments for this post type (%s) are not enabled.' + ), + postType + ); + showPlacholder = false; + } else if ( 'open' !== defaultCommentStatus ) { + warning = __( + 'Post Comments Form block: Comments are not enabled.' + ); + showPlacholder = false; + } + } return ( <> @@ -52,29 +95,9 @@ export default function PostCommentsFormEdit( { />
- { ! commentStatus && ! isInSiteEditor && ( - - { __( - 'Post Comments Form block: comments are not enabled for this post type.' - ) } - - ) } - - { 'open' !== commentStatus && ! isInSiteEditor && ( - - { sprintf( - /* translators: 1: Post type (i.e. "post", "page") */ - __( - 'Post Comments Form block: comments to this %s are not allowed.' - ), - postType - ) } - - ) } + { warning && { warning } } - { ( 'open' === commentStatus || isInSiteEditor ) && ( - - ) } + { showPlacholder ? : null }
); From b575b9454c1466547c2b23783dd820ee4e264f21 Mon Sep 17 00:00:00 2001 From: Luis Herranz Date: Mon, 25 Apr 2022 17:01:16 +0200 Subject: [PATCH 2/2] Fix typo on showPlaceholder variable name --- packages/block-library/src/post-comments-form/edit.js | 10 +++++----- packages/block-library/src/post-comments/edit.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/block-library/src/post-comments-form/edit.js b/packages/block-library/src/post-comments-form/edit.js index 347b0a7e0ba2b..24e4599dd46bb 100644 --- a/packages/block-library/src/post-comments-form/edit.js +++ b/packages/block-library/src/post-comments-form/edit.js @@ -55,7 +55,7 @@ export default function PostCommentsFormEdit( { ); let warning = false; - let showPlacholder = true; + let showPlaceholder = true; if ( ! isSiteEditor && 'open' !== commentStatus ) { if ( 'closed' === commentStatus ) { @@ -66,7 +66,7 @@ export default function PostCommentsFormEdit( { ), postType ); - showPlacholder = false; + showPlaceholder = false; } else if ( ! postTypeSupportsComments ) { warning = sprintf( /* translators: 1: Post type (i.e. "post", "page") */ @@ -75,12 +75,12 @@ export default function PostCommentsFormEdit( { ), postType ); - showPlacholder = false; + showPlaceholder = false; } else if ( 'open' !== defaultCommentStatus ) { warning = __( 'Post Comments Form block: Comments are not enabled.' ); - showPlacholder = false; + showPlaceholder = false; } } @@ -97,7 +97,7 @@ export default function PostCommentsFormEdit( {
{ warning && { warning } } - { showPlacholder ? : null } + { showPlaceholder ? : null }
); diff --git a/packages/block-library/src/post-comments/edit.js b/packages/block-library/src/post-comments/edit.js index 52e891e5a8cc4..248922da8b19e 100644 --- a/packages/block-library/src/post-comments/edit.js +++ b/packages/block-library/src/post-comments/edit.js @@ -55,7 +55,7 @@ export default function PostCommentsEdit( { let warning = __( 'Post Comments block: This 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 replacing this block with the "Comments Query Loop" block.' ); - let showPlacholder = true; + let showPlaceholder = true; if ( ! isSiteEditor && 'open' !== commentStatus ) { if ( 'closed' === commentStatus ) { @@ -66,7 +66,7 @@ export default function PostCommentsEdit( { ), postType ); - showPlacholder = false; + showPlaceholder = false; } else if ( ! postTypeSupportsComments ) { warning = sprintf( /* translators: 1: Post type (i.e. "post", "page") */ @@ -75,10 +75,10 @@ export default function PostCommentsEdit( { ), postType ); - showPlacholder = false; + showPlaceholder = false; } else if ( 'open' !== defaultCommentStatus ) { warning = __( 'Post Comments block: Comments are not enabled.' ); - showPlacholder = false; + showPlaceholder = false; } } @@ -104,7 +104,7 @@ export default function PostCommentsEdit( {
{ warning } - { showPlacholder && ( + { showPlaceholder && (