-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
86 lines (82 loc) · 1.8 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* WordPress dependencies
*/
import {
VisuallyHidden,
__experimentalHeading as Heading,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useEntityRecords } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import Page from '../page';
import Table from '../table';
import Link from '../routes/link';
import AddedBy from '../list/added-by';
import TemplateActions from '../template-actions';
import AddNewTemplatePart from './add-new-template-part';
export default function PageTemplateParts() {
const { records: templateParts } = useEntityRecords(
'postType',
'wp_template_part',
{
per_page: -1,
}
);
const columns = [
{
header: __( 'Template Part' ),
cell: ( templatePart ) => (
<VStack>
<Heading as="h3" level={ 5 }>
<Link
params={ {
postId: templatePart.id,
postType: templatePart.type,
canvas: 'edit',
} }
state={ { backPath: '/wp_template_part/all' } }
>
{ decodeEntities(
templatePart.title?.rendered ||
templatePart.slug
) }
</Link>
</Heading>
</VStack>
),
maxWidth: 400,
},
{
header: __( 'Added by' ),
cell: ( templatePart ) => (
<AddedBy
postType={ templatePart.type }
postId={ templatePart.id }
/>
),
},
{
header: <VisuallyHidden>{ __( 'Actions' ) }</VisuallyHidden>,
cell: ( templatePart ) => (
<TemplateActions
postType={ templatePart.type }
postId={ templatePart.id }
/>
),
},
];
return (
<Page
title={ __( 'Template Parts' ) }
actions={ <AddNewTemplatePart /> }
>
{ templateParts && (
<Table data={ templateParts } columns={ columns } />
) }
</Page>
);
}