-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6563 from arthur791004/add/post-featured-image-in…
…-pre-publish-panel Add PostFeaturedImage to PrePublishPanel
- Loading branch information
Showing
8 changed files
with
4,183 additions
and
666 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,27 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
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'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { validateFeaturedImage } from '../helpers'; | ||
|
||
/** | ||
* Conditionally adds a notice to the pre-publish panel for the featured image. | ||
* Adds a pre-publish panel containing the featured image selection component. | ||
* | ||
* @param {Object} props Component props. | ||
* @param {Object} props.featuredMedia Media object. | ||
* @param {Array} props.dimensions Required image dimensions. | ||
* @param {boolean} props.required Whether selecting a featured image is required. | ||
* @return {Function} Either a plain pre-publish panel, or the panel with a featured image notice. | ||
* Note: The `PostFeaturedImage` component would have already been filtered to include | ||
* any notices for the featured image so there is no need to recreate them here. | ||
* | ||
* @return {Function} A pre-publish panel containing the featured image selection component. | ||
*/ | ||
const PrePublishPanel = ( { featuredMedia, dimensions, required } ) => { | ||
const errors = validateFeaturedImage( featuredMedia, dimensions, required ); | ||
|
||
if ( ! errors ) { | ||
return null; | ||
} | ||
|
||
const PrePublishPanel = () => { | ||
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 /> | ||
</PluginPrePublishPanel> | ||
); | ||
}; | ||
|
||
PrePublishPanel.propTypes = { | ||
featuredMedia: PropTypes.object, | ||
dimensions: PropTypes.shape( { | ||
width: PropTypes.number.isRequired, | ||
height: PropTypes.number.isRequired, | ||
} ), | ||
required: PropTypes.bool, | ||
}; | ||
|
||
export default withSelect( ( select ) => { | ||
const currentPost = select( 'core/editor' ).getCurrentPost(); | ||
const editedFeaturedMedia = select( 'core/editor' ).getEditedPostAttribute( 'featured_media' ); | ||
const featuredMedia = currentPost.featured_media || editedFeaturedMedia; | ||
|
||
return { | ||
featuredMedia: featuredMedia ? select( 'core' ).getMedia( featuredMedia ) : null, | ||
}; | ||
} )( PrePublishPanel ); | ||
export default PrePublishPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.