-
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.
Update to use new Page components added along with Table
- Loading branch information
1 parent
6677423
commit fca8f9d
Showing
15 changed files
with
65 additions
and
197 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
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
113 changes: 25 additions & 88 deletions
113
packages/edit-site/src/components/page-library/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 |
---|---|---|
@@ -1,104 +1,41 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
VisuallyHidden, | ||
__experimentalHeading as Heading, | ||
__experimentalVStack as VStack, | ||
} from '@wordpress/components'; | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore, useEntityRecords } from '@wordpress/core-data'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import { getQueryArgs } from '@wordpress/url'; | ||
|
||
/** | ||
* 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'; | ||
import PatternsList from './patterns-list'; | ||
import useLibrarySettings from './use-library-settings'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
export default function PageTemplates() { | ||
const { records: templateParts } = useEntityRecords( | ||
'postType', | ||
'wp_template_part', | ||
{ | ||
per_page: -1, | ||
} | ||
); | ||
const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis ); | ||
|
||
const { canCreate } = useSelect( ( select ) => { | ||
const { supportsTemplatePartsMode } = | ||
select( editSiteStore ).getSettings(); | ||
return { | ||
postType: select( coreStore ).getPostType( 'wp_template_part' ), | ||
canCreate: ! supportsTemplatePartsMode, | ||
}; | ||
} ); | ||
const DEFAULT_TYPE = 'wp_template_part'; | ||
const DEFAULT_CATEGORY = 'header'; | ||
|
||
const columns = [ | ||
{ | ||
header: __( 'Template Part' ), | ||
cell: ( templatePart ) => ( | ||
<VStack> | ||
<Heading level={ 5 }> | ||
<Link | ||
params={ { | ||
postId: templatePart.id, | ||
postType: templatePart.type, | ||
canvas: 'edit', | ||
} } | ||
> | ||
{ 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 } | ||
/> | ||
), | ||
}, | ||
]; | ||
export default function PageLibrary() { | ||
const { categoryType, categoryId } = getQueryArgs( window.location.href ); | ||
const type = categoryType || DEFAULT_TYPE; | ||
const category = categoryId || DEFAULT_CATEGORY; | ||
const settings = useLibrarySettings(); | ||
|
||
// Wrap everything in a block editor provider. | ||
// This ensures 'styles' that are needed for the previews are synced | ||
// from the site editor store to the block editor store. | ||
return ( | ||
<Page | ||
title={ __( 'Template Parts' ) } | ||
actions={ | ||
canCreate && ( | ||
<AddNewTemplate | ||
templateType={ 'wp_template_part' } | ||
showIcon={ false } | ||
toggleProps={ { variant: 'primary' } } | ||
/> | ||
) | ||
} | ||
> | ||
{ templateParts && ( | ||
<Table data={ templateParts } columns={ columns } /> | ||
) } | ||
</Page> | ||
<ExperimentalBlockEditorProvider settings={ settings }> | ||
<Page className="edit-site-library"> | ||
<PatternsList | ||
type={ type } | ||
categoryId={ category } | ||
label={ __( 'Patterns list' ) } | ||
/> | ||
</Page> | ||
</ExperimentalBlockEditorProvider> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
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
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 was deleted.
Oops, something went wrong.
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