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
Show updated permalink on status bar. #24380
Conversation
@@ -104,8 +107,18 @@ function PostLink( { | |||
<div className="edit-post-post-link__preview-link-container"> | |||
<ExternalLink | |||
className="edit-post-post-link__link" | |||
href={ postLink } |
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.
postlink
is coming from the getCurrentPost
selector's link
property, which in turn comes from the REST API (see). That field is set by the corresponding controller to use WordPress's get_permalink()
function.
It might be worth considering to modify that function, in order to change the behavior for all cases where the permalink is used (including wp-admin Posts screen and Classic Editor), in order to get perfectly consistent behavior everywhere 🤔
onClick={ ( event ) => { | ||
// This shows the permalink in the status bar, | ||
// while uses the postLink to open in a new window. | ||
event.preventDefault(); | ||
window.open( | ||
postLink, | ||
'_blank', | ||
'noreferrer,noopener' | ||
); | ||
} } |
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'd rather not hack the <a href="" />
, since it makes for some really unexpected behavior. As others have elaborated in #41948, the permalink should actually work for drafts as well.
onClick={ ( event ) => { | |
// This shows the permalink in the status bar, | |
// while uses the postLink to open in a new window. | |
event.preventDefault(); | |
window.open( | |
postLink, | |
'_blank', | |
'noreferrer,noopener' | |
); | |
} } |
@@ -104,8 +107,18 @@ function PostLink( { | |||
<div className="edit-post-post-link__preview-link-container"> | |||
<ExternalLink | |||
className="edit-post-post-link__link" | |||
href={ postLink } | |||
href={ isEditable ? permalink : postLink } |
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.
If we do this, we might want to use addQueryArg
to add the preview
bool to permalink
(in case the post is still in draft state).
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 looking good to me overall, but I'd rather not add the onclick
handler.
Since this changes the draft preview behavior quite a bit, I'd like to defer other folks for final approval.
cc/ @youknowriad @mcsf
I'm not super into hacking the What about adding an info text that shows up when the post doesn't have a permalink yet, explaining that the permalink only works once the post is published? 🤔 Other options:
|
👍 I went through the whole flow just to see what's going on:
In my opinion, once the post is scheduled, the link text should point to the post link (one with the slug).
I think this would be a great approach. I'd prefer the link to always point to the permalink and have a text to explain why it's not working yet. |
There is some prior discussion on permalinks here: #21410 (comment). I recommend reading it, as some compromises were made there that are useful to this PR. Essentially, one of the important things to look out for is what kind of guarantees WordPress can make about permalinks, and doing our best not to break that. Looking at what the Classic editor does can also often be useful in this domain.
I tend to agree with this. One thing I'm not a fan of, though, is crafting ad hoc logic for generating permalinks. This puts us at risk of introducing subtle bugs, maintenance difficulties, and in general falling out of sync with the true decision maker (the WP back end): // Using array join prevents undefined/null values
permalink = [ permalinkPrefix, postSlug, permalinkSuffix ].join( '' ); This issue is also present to an extent in #21410, but becomes more apparent here. It's also a direct duplication of what happens inside the
So it's important for this PR to refactor so as to use selector data as directly as possible, even if that requires refactoring selectors. |
As the issue is fairly trivial, I have no mental capacity at this point to look into this. Feel free to supercede this PR! |
Going to close this PR for now. Thanks for your efforts. |
Description
When hovering over the permalink in the document sidebar on the block editor, the status bar should show the updated permalink.
When clicking on the permalink, it should still be able to open the post in a new window (by using the postLink) even though the permalink hasn't been created yet.
See Automattic/wp-calypso#41948 for more details.
How has this been tested?
Tested this in my local wp-env with permalink enabled on settings page.
Screenshots
Types of changes
Bug fix
Checklist: