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

Editor: Use hooks instead of HoCs in PostPendingStatusCheck #53389

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions packages/editor/src/components/post-pending-status/check.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';

export function PostPendingStatusCheck( {
hasPublishAction,
isPublished,
children,
} ) {
export function PostPendingStatusCheck( { children } ) {
const { hasPublishAction, isPublished } = useSelect( ( select ) => {
const { isCurrentPostPublished, getCurrentPost } =
select( editorStore );
return {
hasPublishAction:
getCurrentPost()._links?.[ 'wp:action-publish' ] ?? false,
isPublished: isCurrentPostPublished(),
};
}, [] );

if ( isPublished || ! hasPublishAction ) {
return null;
}

return children;
}

export default compose(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compose usage was unnecessary here because we were using only one HoC.

withSelect( ( select ) => {
const { isCurrentPostPublished, getCurrentPostType, getCurrentPost } =
select( editorStore );
return {
hasPublishAction:
getCurrentPost()._links?.[ 'wp:action-publish' ] ?? false,
isPublished: isCurrentPostPublished(),
postType: getCurrentPostType(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to moving from withSelect, we're no longer returning the postType prop since it was not in use.

};
} )
)( PostPendingStatusCheck );
export default PostPendingStatusCheck;