Skip to content
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

Site Editor: Allow editing custom template title #36933

Merged
merged 2 commits into from Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,28 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { TextControl } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';

export default function EditTemplateTitle( { template } ) {
const [ title, setTitle ] = useEntityProp(
'postType',
template.type,
'title',
template.id
);

return (
<TextControl
label={ __( 'Title' ) }
value={ title }
help={ __(
'Give the template a title that indicates its purpose, e.g. "Full Width".'
) }
onChange={ ( newTitle ) => {
setTitle( newTitle || template.slug );
} }
/>
);
}
19 changes: 12 additions & 7 deletions packages/edit-site/src/components/template-details/index.js
Expand Up @@ -24,6 +24,7 @@ import {
} from '../navigation-sidebar/navigation-panel/constants';
import { store as editSiteStore } from '../../store';
import TemplateAreas from './template-areas';
import EditTemplateTitle from './edit-template-title';

export default function TemplateDetails( { template, onClose } ) {
const { title, description } = useSelect(
Expand Down Expand Up @@ -55,13 +56,17 @@ export default function TemplateDetails( { template, onClose } ) {
return (
<div className="edit-site-template-details">
<div className="edit-site-template-details__group">
<Heading
level={ 4 }
weight={ 600 }
className="edit-site-template-details__title"
>
{ title }
</Heading>
{ template.is_custom ? (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I extract this into the custom util method, similar to isTemplateRevertable and isTemplateRemovable?

<EditTemplateTitle template={ template } />
) : (
<Heading
level={ 4 }
weight={ 600 }
className="edit-site-template-details__title"
>
{ title }
</Heading>
) }

{ description && (
<Text
Expand Down