-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathcheck.js
41 lines (36 loc) · 1.09 KB
/
check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import PostTypeSupportCheck from '../post-type-support-check';
import { store as editorStore } from '../../store';
/**
* Wrapper component that renders its children if the post has more than one revision.
*
* @param {Object} props Props.
* @param {React.ReactNode} props.children Children to be rendered.
*
* @return {React.ReactNode} Rendered child components if post has more than one revision, otherwise null.
*/
function PostLastRevisionCheck( { children } ) {
const { lastRevisionId, revisionsCount } = useSelect( ( select ) => {
const { getCurrentPostLastRevisionId, getCurrentPostRevisionsCount } =
select( editorStore );
return {
lastRevisionId: getCurrentPostLastRevisionId(),
revisionsCount: getCurrentPostRevisionsCount(),
};
}, [] );
if ( ! lastRevisionId || revisionsCount < 2 ) {
return null;
}
return (
<PostTypeSupportCheck supportKeys="revisions">
{ children }
</PostTypeSupportCheck>
);
}
export default PostLastRevisionCheck;