-
Notifications
You must be signed in to change notification settings - Fork 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
Editor: Update behavior of notice and preview action #13001
Conversation
Rather than applying as state, we could pass the intended after-save action as an argument to |
This was an attempt to stop the pasting of links with generally noisy qargs by users. I guess the expected behaviour here would be to only include the |
cc7f8d0
to
c63f6a0
Compare
c63f6a0
to
5c80afa
Compare
@aduth thanks for the feedback! What do you think about this new approach? It no longer uses state. Instead, we're passing an argument to |
I may have made an error in suggesting against state. Specifically, I think I overlooked how we're passing URLs to the I don't recall exactly what your original implementation looked like, but I'm guessing assigning and reading from Sorry to flip-flop on my suggestions, and for my delays in revisiting this. |
Will take a look at this tomorrow. Setting the URL is indeed a bit of a wrinkle. I remember originally looking at:
I forget exactly why I didn't go with that originally. |
5c80afa
to
d008cf7
Compare
I opted to re-add Manipulating This should work as originally described. I'll go ahead and flip it back to "Needs Review." |
this.setState( { | ||
previewAction: action | ||
} ); | ||
} |
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.
Quick note: This comparison is helpful if the user does the following:
- Cmd + Click on Preview to open a new tab.
- Come back to the editor and click the Preview link like normal while the other tab is still open.
In that scenario, this.state.previewAction
would still be set to preview
so we're avoiding an extra setState
call.
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.
In that scenario,
this.state.previewAction
would still be set topreview
so we're avoiding an extrasetState
call.
Hmm, kinda goes to highlight that letting the state be long-lived beyond the initial view/preview intent is perhaps a bit fragile. I don't really have a good alternative to suggest, but a little unnerving.
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.
Right - we could use a setTimeout
to eventually revert the state back to null
, but that still feels a bit hacky. Outside of closing the preview window, there isn't a great cue to reset the this.state.previewAction
back to null :(
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 to work well in my testing. Let me know what you think of my remarks, but I'm not opposed to moving forward with merging.
client/post-editor/post-editor.jsx
Outdated
this._previewWindow.focus(); | ||
} else { | ||
this._previewWindow = window.open( this.state.previewUrl, 'WordPress.com Post Preview' ); | ||
this._previewWindow = window.open( | ||
( this.state.previewAction === 'view' ? this.state.post.URL : this.state.previewUrl ), |
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.
Since this ternary expression occurs four separate times, maybe it'd be worth moving to a helper function on the component?
getPreviewUrl() {
const { previewAction, previewUrl, post } = this.state;
if ( 'view' === previewAction ) {
return post.URL;
}
return previewUrl;
}
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.
Good call. Ternary converted to helper function. getPreviewUrl
introduces a tiny bit of shadowing since PostEditStore
has a method with the same name. This naming makes the most sense and hopefully it's still straightforward enough.
this.setState( { | ||
previewAction: action | ||
} ); | ||
} |
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.
In that scenario,
this.state.previewAction
would still be set topreview
so we're avoiding an extrasetState
call.
Hmm, kinda goes to highlight that letting the state be long-lived beyond the initial view/preview intent is perhaps a bit fragile. I don't really have a good alternative to suggest, but a little unnerving.
Just noting I ran into issues with this today. It's a bit awkward to have to tell folks they need to save before they can preview, so I'd love to see this fixed. |
d008cf7
to
dbb6e0f
Compare
@jeremeylduvall This PR needs a rebase |
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 👍
If a post is published with new changes in the editor, the "View" link should still open the published page. The "Preview" link should open the post with the new changes. Resolves: #12829
dbb6e0f
to
e7e3b0d
Compare
This is a first attempt at fixing #12829. It feels a bit hacky tbh. Right now, the "Preview" link in the Editor and the "View" link have the same behavior. This works in most cases, but in specific instances, it produces unexpected behavior. For example:
To decipher when we should show a preview versus the published post, I introduced a new state item
previewAction
that changes according to which action is taken by the user.While testing this out, I also noticed that when we modify the
ExternalUrl
prop ineditor-preview/index.jsx
, we're stripping out thepreview
component. This leads to some counterintuitive behavior. For example, try the following:I would expect the iframe and the external icon URL to show the same content. If we leave in the
preview
piece to the URL, this behavior is fixed. cc @ehg as it looks like you removed it in #5550. I'm not quite clear on the ramifications of leavingpreview
. I didn't see any adverse side effects.To test
GIF
Here's a GIF of the various flows.