-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Template list add rename action #36879
Conversation
Size Change: +379 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
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.
packages/edit-site/src/components/list/actions/rename-menu-item.js
Outdated
Show resolved
Hide resolved
Thanks for testing, @talldan. I also noticed that focused state and delete button styles don't work well side by side. |
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.
Thank you for working on this!
I'm wondering if it's possible (or should) to allow changing the template's area so that we could reuse the same modal for creating the template part 🤔 .
<> | ||
<MenuItem | ||
onClick={ () => { | ||
setIsModalOpen( true ); |
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.
Why not calling onClose
here once the modal is opened?
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.
Calling onClose
here will unmount dropdown, so modal is never rendered.
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.
I see. Then why aren't we rendering the modal outside of the dropdown?
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.
No strong preference for this. I just thought having a separate component would be a little cleaner. Happy to move logic in the main file. Probably going to save a few lines of code as well :)
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.
BTW, I don't think we should be closing the modal for accessibility reasons. Closing the modal should move focus back to the Rename button again.
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.
I also like that behavior but wasn't sure if it was accessibility improvement.
onRequestClose={ () => { | ||
setIsModalOpen( false ); | ||
} } | ||
overlayClassName="edit-site-template__modal" |
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.
Nit: Should probably rename this to something like edit-site-list__rename-modal
for disambiguation.
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.
Change the class.
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.
Change the class.
<TextControl | ||
label={ __( 'Name' ) } | ||
value={ title } | ||
onChange={ setTitle } |
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.
This should be required
to avoid renaming it to an empty title.
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.
Done.
title={ __( 'Rename template' ) } | ||
closeLabel={ __( 'Close' ) } | ||
onRequestClose={ () => { | ||
setIsModalOpen( false ); |
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.
This seems a little weird to me, as I'd imagine closing the modal would also remove previously edited title. I believe that's the side-effect of using useEntityProp
on every change? We could create a new state and reset it every time the modal is opened though.
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.
Changed to use state.
onClose(); | ||
|
||
// Persist edited entity. | ||
await saveEditedEntityRecord( 'postType', template.type, template.id ); |
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.
We should probably also add a isLoading
state and set isBusy
to the submit button. And once the change is saved, we can then close the modal and potentially display success or error notices as in #36808.
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.
I don't think there's a need for the busy state. I'm closing the modal before the HTTP request is made to persist changes. So there shouldn't be a visible busy state.
I've updated the code to display notices.
P.S. There should be an easier way to use try/catch
with actions.
8d6c48b
to
802a14b
Compare
Nice! I noticed one peculiar interaction: If you open the rename modal, the input value = the current template name which makes sense. If you then cancel and immediately re-open, the input value is empty. Just a minor detail but would be nice to fix if possible. I also noticed that I am able to rename custom primary templates (front-page, archive, search etc). I don't think we should allow this as it creates potential for folks to confuse themselves. Only from-scratch Agree that we should remove the border on the delete button. We can do that separately though. |
Thanks for catching those issues, @jameskoster. They should be fixed now.
Sounds good. |
The input issue is fixed 👍 I'm still able to rename my search / front-page templates though. |
Ahh the 3 dot menu does not show on core templates only on user or theme created templates. I made a template Archive and noticed the 3 dots show up. This is what I see: Good to hear that the red border will be removed! -- EDIT: Which seems like a fitting text. |
It looks like I forgot to add |
cd92f84
to
1d68794
Compare
@jameskoster, the custom template issue should be fixed now. |
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.
Seems to be working correctly now! :)
1d68794
to
63719ab
Compare
* Site Editor: Template list add rename action * Update modal class * Address feedback * Only allow renaming of user created templates * Fix empty title issue * Fix condition * Use is_custom
Description
Part of #36773.
Adds new "Rename" action to the template list that will display modal. The modal design matches "Create new template" and "Add to Reusable blocks" modal designs.
Notes
How has this been tested?
Screenshots
Types of changes
Enhancement
Checklist:
*.native.js
files for terms that need renaming or removal).