forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Library: Reinstate manage all template parts page (WordPress#51961)
- Loading branch information
1 parent
33e2c84
commit 02cac31
Showing
7 changed files
with
146 additions
and
20 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
105 changes: 105 additions & 0 deletions
105
packages/edit-site/src/components/page-template-parts/index.js
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
VisuallyHidden, | ||
__experimentalHeading as Heading, | ||
__experimentalVStack as VStack, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore, 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 AddNewTemplate from '../add-new-template'; | ||
import { store as editSiteStore } from '../../store'; | ||
|
||
export default function PageTemplateParts() { | ||
const { records: templateParts } = useEntityRecords( | ||
'postType', | ||
'wp_template_part', | ||
{ | ||
per_page: -1, | ||
} | ||
); | ||
|
||
const { canCreate } = useSelect( ( select ) => { | ||
const { supportsTemplatePartsMode } = | ||
select( editSiteStore ).getSettings(); | ||
return { | ||
postType: select( coreStore ).getPostType( 'wp_template_part' ), | ||
canCreate: ! supportsTemplatePartsMode, | ||
}; | ||
} ); | ||
|
||
const columns = [ | ||
{ | ||
header: __( 'Template Part' ), | ||
cell: ( templatePart ) => ( | ||
<VStack> | ||
<Heading level={ 5 }> | ||
<Link | ||
params={ { | ||
postId: templatePart.id, | ||
postType: templatePart.type, | ||
canvas: 'view', | ||
} } | ||
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={ | ||
canCreate && ( | ||
<AddNewTemplate | ||
templateType={ 'wp_template_part' } | ||
showIcon={ false } | ||
toggleProps={ { variant: 'primary' } } | ||
/> | ||
) | ||
} | ||
> | ||
{ templateParts && ( | ||
<Table data={ templateParts } columns={ columns } /> | ||
) } | ||
</Page> | ||
); | ||
} |
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
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