-
Notifications
You must be signed in to change notification settings - Fork 385
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
Add PostFeaturedImage to PrePublishPanel #6563
Add PostFeaturedImage to PrePublishPanel #6563
Conversation
cb979f8
to
6a58cb0
Compare
6a58cb0
to
21498ed
Compare
Hey @arthur791004, thanks for creating this PR. I'm not sure if it was ever intended for one to be able to upload a featured image from the pre-publish panel but given that it is a pre-publish check it would make sense. cc @westonruter - I'm adding this to the v2.1.4 milestone and classifying it as a bug. |
); | ||
} ) } | ||
</Notice> | ||
<PostFeaturedImage |
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 it would be a better user experience to let the featured image check stay in the pre-publish panel after they've selected an image, rather than exiting the panel to edit it in the post settings panel.
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.
Sounds good! Let me think about how to do it
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've made the check always staying in the pre-publish panel and also update the recorded video!
@pierlon Thanks for your reply! Currently, I'm not very for sure but I think the reason might be that this plugin only adds the notice message to Post Setting section, so only adding the notice to PrePublish panel seems to make sense. The potential problem might be if there is new version for PostFeaturedImage, then this plugin should also update to make it consistent. |
const noticeUI = errors ? ( | ||
<Notice | ||
status={ required ? 'warning' : 'notice' } | ||
isDismissible={ false } | ||
> | ||
{ errors.map( ( errorMessage, index ) => { | ||
return ( | ||
<p key={ `error-${ index }` }> | ||
{ errorMessage } | ||
</p> | ||
); | ||
} ) } | ||
</Notice> | ||
) : null; |
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 just noticed that since the plugin is filtering the PostFeaturedImage
component to add the error notice in the Post Settings, we don't need to recreate the notice UI here and instead use the PostFeaturedImage
component as is. The parameter annotations for this component (PrePublishPanel
) and propTypes
object would have to also be adapted of course.
const noticeUI = errors ? ( | |
<Notice | |
status={ required ? 'warning' : 'notice' } | |
isDismissible={ false } | |
> | |
{ errors.map( ( errorMessage, index ) => { | |
return ( | |
<p key={ `error-${ index }` }> | |
{ errorMessage } | |
</p> | |
); | |
} ) } | |
</Notice> | |
) : null; |
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.
Great 👍 I've removed lots of code that doesn't need now!
); | ||
} ) } | ||
</Notice> | ||
<PostFeaturedImage noticeUI={ noticeUI } /> |
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.
Suggestion to go along with comment above:
<PostFeaturedImage noticeUI={ noticeUI } /> | |
<PostFeaturedImage /> |
@arthur791004 Could you also adapt the diff --git a/tests/php/test-class-amp-meta-box.php b/tests/php/test-class-amp-meta-box.php
--- a/tests/php/test-class-amp-meta-box.php (revision 4d9cf3e11d131064ec989986f930c0d3c56d9977)
+++ b/tests/php/test-class-amp-meta-box.php (date 1630021426599)
@@ -166,6 +166,7 @@
'wp-compose',
'wp-data',
'wp-edit-post',
+ 'wp-editor',
'wp-element',
'wp-hooks',
'wp-i18n', |
Codecov Report
@@ Coverage Diff @@
## develop #6563 +/- ##
=============================================
- Coverage 75.77% 75.77% -0.01%
Complexity 6016 6016
=============================================
Files 239 239
Lines 18896 18894 -2
=============================================
- Hits 14319 14317 -2
Misses 4577 4577
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
@arthur791004 Thank you for submitting this PR and spending the time to work on it 🙇.
LGTM!
@pierlon Thanks for your quick reply and help to update the comment 👍 |
if ( required ) { | ||
return [ __( 'Selecting a featured image is required.', 'amp' ) ]; | ||
} | ||
|
||
return [ __( 'Selecting a featured image is recommended for an optimal user experience.', 'amp' ) ]; | ||
return [ __( 'Selecting a featured image is required.', 'amp' ) ]; |
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.
Humm. Why was the message made unconditionally required? If the required
prop is removed, the resulting message should rather be Selecting a featured image is recommended for an optimal user experience.
. Although this message as well should be improved (although not necessarily at this time) per #6075.
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.
In other words, should these lines not be instead replaced with:
return [ __( 'Selecting a featured image is recommended for an optimal user experience.', 'amp' ) ];
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.
There are many scenarios where no featured image neither available nor desired when someone publishes a post, so we shouldn't mandate Google Search's guidelines as requirements.
Indeed, the Featured Image is used as the image
in the Schema.org metadata, and the Guidelines make a post eligible to show up with structured data in Search results. The post will still show up in search results without the extra metadata, although it won't be as well presented.
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.
The idea here is to only let this function validate the image and return a set of validation errors. The text Selecting a featured image is recommended for an optimal user experience.
is not necessarily an error but a reconmmendation, so I removed it from here.
Instead, the component where this function is being used does a check to see if media
is nullable, and if so uses the text Selecting a featured image is recommended for an optimal user experience.
. See https://github.com/arthur791004/amp-wp/blob/1fb801ed0a1fceaffec5087327c391e0f752782d/assets/src/common/components/higher-order/with-featured-image-notice.js#L60-L66.
if ( ! media ) {
const message = __( 'Selecting a featured image is recommended for an optimal user experience.', 'amp' );
noticeUI = createNoticeUI( [ message ], 'notice' );
} else {
const errorMessages = validateFeaturedImage( media, getMinimumFeaturedImageDimensions() );
noticeUI = errorMessages ? createNoticeUI( errorMessages, 'warning' ) : null;
}
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.
Oh, so this “required” message is actually never shown in the plugin currently but is included in validateFeaturedImage()
here for completeness?
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.
Yep.
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.
LGTM!
The only thing that looks a bit off to me is the stats: over 4k lines added. Most of that is the package-lock.json
. I guess it's because of adding the @wordpress/editor
package to the project.
Uninstalled then reinstalled the |
@pierlon This doesn't cherry-pick cleanly into |
Sure. |
Summary
Related to Automattic/wp-calypso#55566
Currently, we can set featured image directly in Post Setting section. If we don't set any featured image and want to publish the post, we will see the notice and encourage to set the featured image. However, we cannot set the featured image immediately at that point. So, adding
PostFeaturedImage
toPrePublishPanel
to make user able to set it immediately.Screenshots
post-featured-image.mov
Checklist