-
Notifications
You must be signed in to change notification settings - Fork 6
Bug fix β faulty title collision caused by autosave #88
Conversation
|
||
export default function PatternManagerMetaControls() { | ||
const { postMeta, title } = useEditedPostData(); | ||
const { currentName } = useSavedPostData(); |
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 is a new hook that I think could make sense to keep. The saved data is inherently different from the edited data since we are editing data directly (via editPost
for example) as values change.
The saved and edited data won't necessarily match until the post is actually saved.
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.
Looks good so far. It keeps the same level of abstraction as useEditedPostData()
@@ -56,6 +59,7 @@ export default function PatternManagerMetaControls() { | |||
postMeta={ postMeta } | |||
handleChange={ updatePostMeta } | |||
errorMessage={ errorMessage } | |||
currentName={ currentName } |
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.
Passing in currentName
here behaves somewhat like a ref for our purposes.
const savedPatternName = useSelect( ( select: SelectQuery ) => { | ||
return select( 'core/editor' ).getCurrentPostAttribute( 'meta' )?.name; | ||
}, [] ); |
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 is no longer needed β the new hook uses this call to get currentName
.
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.
Yes!!
I think we should consider rethinking the passing of For example, instead of this: <KeywordsPanel
postMeta={ postMeta }
handleChange={ updatePostMeta }
/>
<DescriptionPanel
postMeta={ postMeta }
handleChange={ updatePostMeta }
/> ...we could do something like this: <KeywordsPanel
keywords={ metaKeywords }
handleChange={ updatePostMeta }
/>
<DescriptionPanel
description={ metaDescription }
handleChange={ updatePostMeta }
/> Or we could also use context instead of passing these props around. |
Interesting! I'll look at this later today if that's alright. |
Of course! No rush on this one β I only noticed from running my demo a bunch of times. |
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.
Hi @mike-day,
Really nice fix. With your 'How to test' steps, there's no title collision message anymore:
Good idea. The components should only accept the meta value they need, not all of I'd say it's fine to keep passing them as props, instead of putting them in global context. |
Cool, I think it will be a bit cleaner that way! I am going to complete that work in a new PR after merging this one. |
That's right, good catch. |
@@ -46,7 +50,7 @@ export default function TitlePanel( { | |||
'pattern-manager' | |||
) } | |||
value={ title } | |||
onChange={ ( newTitle: PostMeta[ 'title' ] ) => { | |||
onChange={ ( newTitle: typeof 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.
Nice one, I wouldn't have thought of that
Currently, there is a tricky little bug involving autosave that is annoying to recreate π
Lets say that you rename a pattern but do not click save, opting instead to change other meta values. But then you change your mind about renaming the pattern, deciding instead to stick with the title you already had.
Upon retyping the old pattern title, if autosave has saved your work, the initial title will improperly error as a name collision.
This PR corrects that by getting the
currentName
(equivalent to the slug) fromgetCurrentPostAttribute
for checking against the title. Using this method avoids needing to use a ref, but works in a similar way.How to test
Update Pattern