Skip to content
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

32 changes: 16 additions & 16 deletions assets/src/common/components/pre-publish-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import PropTypes from 'prop-types';
* WordPress dependencies
*/
import { Notice } from '@wordpress/components';
import { PostFeaturedImage } from '@wordpress/editor';
import { PluginPrePublishPanel } from '@wordpress/edit-post';
import { withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
Expand All @@ -27,28 +28,27 @@ import { validateFeaturedImage } from '../helpers';
*/
const PrePublishPanel = ( { featuredMedia, dimensions, required } ) => {
const errors = validateFeaturedImage( featuredMedia, dimensions, required );

if ( ! errors ) {
return null;
}
const noticeUI = errors ? (
<Notice
status={ required ? 'warning' : 'notice' }
isDismissible={ false }
>
{ errors.map( ( errorMessage, index ) => {
return (
<p key={ `error-${ index }` }>
{ errorMessage }
</p>
);
} ) }
</Notice>
) : null;
Copy link
Contributor

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.

Suggested change
const noticeUI = errors ? (
<Notice
status={ required ? 'warning' : 'notice' }
isDismissible={ false }
>
{ errors.map( ( errorMessage, index ) => {
return (
<p key={ `error-${ index }` }>
{ errorMessage }
</p>
);
} ) }
</Notice>
) : null;

Copy link
Contributor Author

@arthur791004 arthur791004 Aug 27, 2021

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!


return (
<PluginPrePublishPanel
title={ __( 'Featured Image', 'amp' ) }
initialOpen="true"
>
<Notice
status={ required ? 'warning' : 'notice' }
isDismissible={ false }
>
{ errors.map( ( errorMessage, index ) => {
return (
<p key={ `error-${ index }` }>
{ errorMessage }
</p>
);
} ) }
</Notice>
<PostFeaturedImage noticeUI={ noticeUI } />
Copy link
Contributor

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:

Suggested change
<PostFeaturedImage noticeUI={ noticeUI } />
<PostFeaturedImage />

</PluginPrePublishPanel>
);
};
Expand Down
Loading