-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to rename pages in site editor without title block #54648
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,11 +51,7 @@ export default function TrashPageMenuItem( { postId, onRemove } ) { | |
} | ||
return ( | ||
<> | ||
<MenuItem | ||
onClick={ () => removePage() } | ||
isDestructive | ||
variant="secondary" | ||
> | ||
<MenuItem onClick={ () => removePage() } isDestructive> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change meant to be part of this PR? I didn't see it mentioned in the description... |
||
{ __( 'Move to Trash' ) } | ||
</MenuItem> | ||
</> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,10 @@ import { store as coreStore } from '@wordpress/core-data'; | |
import { store as noticesStore } from '@wordpress/notices'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { TEMPLATE_POST_TYPE } from '../../utils/constants'; | ||
|
||
export default function RenameMenuItem( { template, onClose } ) { | ||
const title = decodeEntities( template.title.rendered ); | ||
export default function RenameMenuItem( { item, onClose } ) { | ||
const title = decodeEntities( | ||
typeof item.title === 'string' ? item.title : item.title.rendered | ||
); | ||
const [ editedTitle, setEditedTitle ] = useState( title ); | ||
const [ isModalOpen, setIsModalOpen ] = useState( false ); | ||
|
||
|
@@ -33,15 +30,15 @@ export default function RenameMenuItem( { template, onClose } ) { | |
const { createSuccessNotice, createErrorNotice } = | ||
useDispatch( noticesStore ); | ||
|
||
if ( template.type === TEMPLATE_POST_TYPE && ! template.is_custom ) { | ||
if ( item.type === 'wp_template' && ! item.is_custom ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we not using the |
||
return null; | ||
} | ||
|
||
async function onTemplateRename( event ) { | ||
async function onItemRename( event ) { | ||
event.preventDefault(); | ||
|
||
try { | ||
await editEntityRecord( 'postType', template.type, template.id, { | ||
await editEntityRecord( 'postType', item.type, item.id, { | ||
title: editedTitle, | ||
} ); | ||
|
||
|
@@ -53,29 +50,21 @@ export default function RenameMenuItem( { template, onClose } ) { | |
// Persist edited entity. | ||
await saveSpecifiedEntityEdits( | ||
'postType', | ||
template.type, | ||
template.id, | ||
item.type, | ||
item.id, | ||
[ 'title' ], // Only save title to avoid persisting other edits. | ||
{ | ||
throwOnError: true, | ||
} | ||
); | ||
|
||
createSuccessNotice( | ||
template.type === TEMPLATE_POST_TYPE | ||
? __( 'Template renamed.' ) | ||
: __( 'Template part renamed.' ), | ||
{ | ||
type: 'snackbar', | ||
} | ||
); | ||
createSuccessNotice( __( 'Name updated' ), { | ||
type: 'snackbar', | ||
} ); | ||
} catch ( error ) { | ||
const fallbackErrorMessage = | ||
template.type === TEMPLATE_POST_TYPE | ||
? __( 'An error occurred while renaming the template.' ) | ||
: __( | ||
'An error occurred while renaming the template part.' | ||
); | ||
const fallbackErrorMessage = __( | ||
'An error occurred while updating the name' | ||
); | ||
const errorMessage = | ||
error.message && error.code !== 'unknown_error' | ||
? error.message | ||
|
@@ -103,7 +92,7 @@ export default function RenameMenuItem( { template, onClose } ) { | |
} } | ||
overlayClassName="edit-site-list__rename-modal" | ||
> | ||
<form onSubmit={ onTemplateRename }> | ||
<form onSubmit={ onItemRename }> | ||
<VStack spacing="5"> | ||
<TextControl | ||
__nextHasNoMarginBottom | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,30 +20,26 @@ import { store as editSiteStore } from '../../../store'; | |
import SidebarCard from '../sidebar-card'; | ||
import PageContent from './page-content'; | ||
import PageSummary from './page-summary'; | ||
import PageActions from './page-actions'; | ||
|
||
export default function PagePanels() { | ||
const { id, type, hasResolved, status, date, password, title, modified } = | ||
useSelect( ( select ) => { | ||
const { getEditedPostContext } = select( editSiteStore ); | ||
const { getEditedEntityRecord, hasFinishedResolution } = | ||
select( coreStore ); | ||
const context = getEditedPostContext(); | ||
const queryArgs = [ 'postType', context.postType, context.postId ]; | ||
const page = getEditedEntityRecord( ...queryArgs ); | ||
return { | ||
hasResolved: hasFinishedResolution( | ||
'getEditedEntityRecord', | ||
queryArgs | ||
), | ||
title: page?.title, | ||
id: page?.id, | ||
type: page?.type, | ||
status: page?.status, | ||
date: page?.date, | ||
password: page?.password, | ||
modified: page?.modified, | ||
}; | ||
}, [] ); | ||
const { page, hasResolved } = useSelect( ( select ) => { | ||
const { getEditedPostContext } = select( editSiteStore ); | ||
const { getEditedEntityRecord, hasFinishedResolution } = | ||
select( coreStore ); | ||
const context = getEditedPostContext(); | ||
const queryArgs = [ 'postType', context.postType, context.postId ]; | ||
const record = getEditedEntityRecord( ...queryArgs ); | ||
return { | ||
hasResolved: hasFinishedResolution( | ||
'getEditedEntityRecord', | ||
queryArgs | ||
), | ||
page: record, | ||
}; | ||
}, [] ); | ||
|
||
const { id, type, status, date, password, title, modified } = page; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! We just need to make sure that if page doesn't exist this doesn't throw any errors. |
||
|
||
if ( ! hasResolved ) { | ||
return null; | ||
|
@@ -55,6 +51,7 @@ export default function PagePanels() { | |
<SidebarCard | ||
title={ decodeEntities( title ) } | ||
icon={ pageIcon } | ||
actions={ <PageActions page={ page } /> } | ||
description={ | ||
<VStack> | ||
<Text> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { DropdownMenu, MenuGroup } from '@wordpress/components'; | ||
import { moreVertical } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import RenameMenuItem from '../../rename-menu-item'; | ||
|
||
export default function Actions( { page } ) { | ||
return ( | ||
<DropdownMenu | ||
icon={ moreVertical } | ||
label={ __( 'Actions' ) } | ||
className="edit-site-template-card__actions" | ||
toggleProps={ { isSmall: true } } | ||
> | ||
{ ( { onClose } ) => ( | ||
<MenuGroup> | ||
<RenameMenuItem item={ page } onClose={ onClose } /> | ||
</MenuGroup> | ||
) } | ||
</DropdownMenu> | ||
); | ||
} |
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.
Is there a reason to change this prop? If possible its always better to pass simpler props as it prevents unnecessary rerenders in the component.