diff --git a/packages/edit-site/src/components/page-patterns/dataviews-pattern-actions.js b/packages/edit-site/src/components/page-patterns/dataviews-pattern-actions.js index 12a2b99e7dbcbe..afa69e9752c5b4 100644 --- a/packages/edit-site/src/components/page-patterns/dataviews-pattern-actions.js +++ b/packages/edit-site/src/components/page-patterns/dataviews-pattern-actions.js @@ -11,14 +11,11 @@ import { downloadBlob } from '@wordpress/blob'; import { __, _x, sprintf } from '@wordpress/i18n'; import { Button, - TextControl, __experimentalHStack as HStack, __experimentalVStack as VStack, __experimentalText as Text, } from '@wordpress/components'; -import { store as coreStore } from '@wordpress/core-data'; import { useDispatch } from '@wordpress/data'; -import { useState } from '@wordpress/element'; import { store as noticesStore } from '@wordpress/notices'; import { decodeEntities } from '@wordpress/html-entities'; import { store as reusableBlocksStore } from '@wordpress/reusable-blocks'; @@ -91,92 +88,6 @@ export const exportJSONaction = { }, }; -export const renameAction = { - id: 'rename-pattern', - label: __( 'Rename' ), - isEligible: ( item ) => { - const isTemplatePart = item.type === TEMPLATE_PART_POST_TYPE; - const isUserPattern = item.type === PATTERN_TYPES.user; - const isCustomPattern = - isUserPattern || ( isTemplatePart && item.isCustom ); - const hasThemeFile = isTemplatePart && item.templatePart.has_theme_file; - return isCustomPattern && ! hasThemeFile; - }, - RenderModal: ( { items, closeModal } ) => { - const [ item ] = items; - const [ title, setTitle ] = useState( () => item.title ); - const { editEntityRecord, saveEditedEntityRecord } = - useDispatch( coreStore ); - const { createSuccessNotice, createErrorNotice } = - useDispatch( noticesStore ); - async function onRename( event ) { - event.preventDefault(); - try { - await editEntityRecord( 'postType', item.type, item.id, { - title, - } ); - // Update state before saving rerenders the list. - setTitle( '' ); - closeModal(); - // Persist edited entity. - await saveEditedEntityRecord( 'postType', item.type, item.id, { - throwOnError: true, - } ); - createSuccessNotice( - item.type === TEMPLATE_PART_POST_TYPE - ? __( 'Template part renamed.' ) - : __( 'Pattern renamed.' ), - { type: 'snackbar' } - ); - } catch ( error ) { - const fallbackErrorMessage = - item.type === TEMPLATE_PART_POST_TYPE - ? __( - 'An error occurred while renaming the template part.' - ) - : __( 'An error occurred while renaming the pattern.' ); - const errorMessage = - error.message && error.code !== 'unknown_error' - ? error.message - : fallbackErrorMessage; - createErrorNotice( errorMessage, { type: 'snackbar' } ); - } - } - return ( -
- - - - - - - -
- ); - }, -}; - const canDeleteOrReset = ( item ) => { const isTemplatePart = item.type === TEMPLATE_PART_POST_TYPE; const isUserPattern = item.type === PATTERN_TYPES.user; diff --git a/packages/edit-site/src/components/page-patterns/index.js b/packages/edit-site/src/components/page-patterns/index.js index 4ac966acbd20b9..4299a67a14c2fa 100644 --- a/packages/edit-site/src/components/page-patterns/index.js +++ b/packages/edit-site/src/components/page-patterns/index.js @@ -48,7 +48,6 @@ import { } from '../../utils/constants'; import { exportJSONaction, - renameAction, resetAction, deleteAction, duplicatePatternAction, @@ -391,30 +390,32 @@ export default function DataviewsPatterns() { }, [ history, categoryId, type ] ); - const [ editAction, viewRevisionsAction ] = usePostActions( - type, + const templatePartActions = usePostActions( + TEMPLATE_PART_POST_TYPE, + onActionPerformed + ); + const patternActions = usePostActions( + PATTERN_TYPES.user, onActionPerformed ); const actions = useMemo( () => { if ( type === TEMPLATE_PART_POST_TYPE ) { return [ - editAction, - renameAction, + ...templatePartActions, duplicateTemplatePartAction, - viewRevisionsAction, resetAction, deleteAction, ].filter( Boolean ); } return [ - renameAction, + ...patternActions, duplicatePatternAction, exportJSONaction, resetAction, deleteAction, ].filter( Boolean ); - }, [ type, editAction, viewRevisionsAction ] ); + }, [ type, templatePartActions, patternActions ] ); const onChangeView = useCallback( ( newView ) => { if ( newView.type !== view.type ) {