-
Notifications
You must be signed in to change notification settings - Fork 4k
/
reset-default-template.js
45 lines (43 loc) · 1.04 KB
/
reset-default-template.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
42
43
44
45
/**
* WordPress dependencies
*/
import { MenuGroup, MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
/**
* Internal dependencies
*/
import {
useCurrentTemplateSlug,
useEditedPostContext,
useIsPostsPage,
} from './hooks';
export default function ResetDefaultTemplate( { onClick } ) {
const currentTemplateSlug = useCurrentTemplateSlug();
const isPostsPage = useIsPostsPage();
const { postType, postId } = useEditedPostContext();
const { editEntityRecord } = useDispatch( coreStore );
// The default template in a post is indicated by an empty string.
if ( ! currentTemplateSlug || isPostsPage ) {
return null;
}
return (
<MenuGroup>
<MenuItem
onClick={ async () => {
editEntityRecord(
'postType',
postType,
postId,
{ template: '' },
{ undoIgnore: true }
);
onClick();
} }
>
{ __( 'Use default template' ) }
</MenuItem>
</MenuGroup>
);
}