diff --git a/packages/edit-site/src/components/page-patterns/index.js b/packages/edit-site/src/components/page-patterns/index.js index abe4f42defe34..11a9223090484 100644 --- a/packages/edit-site/src/components/page-patterns/index.js +++ b/packages/edit-site/src/components/page-patterns/index.js @@ -36,6 +36,8 @@ import { } from '@wordpress/icons'; import { usePrevious } from '@wordpress/compose'; import { useEntityRecords } from '@wordpress/core-data'; +import { privateApis as editorPrivateApis } from '@wordpress/editor'; +import { privateApis as routerPrivateApis } from '@wordpress/router'; /** * Internal dependencies @@ -71,6 +73,8 @@ import { useAddedBy } from '../page-templates-template-parts/hooks'; const { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock( blockEditorPrivateApis ); +const { usePostActions } = unlock( editorPrivateApis ); +const { useHistory } = unlock( routerPrivateApis ); const templatePartIcons = { header, footer, uncategorized }; const EMPTY_ARRAY = []; @@ -439,17 +443,45 @@ export default function DataviewsPatterns() { return filterSortAndPaginate( patterns, viewWithoutFilters, fields ); }, [ patterns, view, fields, type ] ); - const actions = useMemo( - () => [ + const history = useHistory(); + const onActionPerformed = useCallback( + ( actionId, items ) => { + if ( actionId === 'edit-post' ) { + const post = items[ 0 ]; + history.push( { + postId: post.id, + postType: post.type, + categoryId, + categoryType: type, + canvas: 'edit', + } ); + } + }, + [ history ] + ); + const [ editAction, viewRevisionsAction ] = usePostActions( + onActionPerformed, + [ 'edit-post', 'view-post-revisions' ] + ); + const actions = useMemo( () => { + if ( type === TEMPLATE_PART_POST_TYPE ) { + return [ + editAction, + renameAction, + duplicateTemplatePartAction, + viewRevisionsAction, + resetAction, + deleteAction, + ]; + } + return [ renameAction, duplicatePatternAction, - duplicateTemplatePartAction, exportJSONaction, resetAction, deleteAction, - ], - [] - ); + ]; + }, [ type, editAction, viewRevisionsAction ] ); const onChangeView = useCallback( ( newView ) => { if ( newView.type !== view.type ) { diff --git a/packages/edit-site/src/components/page-patterns/use-patterns.js b/packages/edit-site/src/components/page-patterns/use-patterns.js index b16fddbf81034..8b6c6f26ddd44 100644 --- a/packages/edit-site/src/components/page-patterns/use-patterns.js +++ b/packages/edit-site/src/components/page-patterns/use-patterns.js @@ -40,6 +40,7 @@ const templatePartToPattern = ( templatePart ) => ( { name: createTemplatePartId( templatePart.theme, templatePart.slug ), title: decodeEntities( templatePart.title.rendered ), type: templatePart.type, + _links: templatePart._links, templatePart, } );