-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 (#51961)
- Loading branch information
1 parent
866727e
commit bfb1dcb
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
bfb1dcb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in bfb1dcb.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5398646517
📝 Reported issues:
/test/e2e/specs/editor/various/preview.spec.js