-
Notifications
You must be signed in to change notification settings - Fork 813
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
Email preview: fix sending preview if content in the editor is different from latest in the database #34419
Merged
Merged
Email preview: fix sending preview if content in the editor is different from latest in the database #34419
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/update-email-preview-save-draft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: bugfix | ||
|
||
Fix sending email preview if content in the editor is different from latest in the database. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ import { | |
TextControl, | ||
Icon, | ||
} from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import './email-preview.scss'; | ||
|
@@ -23,15 +24,23 @@ export default function EmailPreview( { isModalOpen, closeModal } ) { | |
const [ emailSending, setEmailSending ] = useState( false ); | ||
const [ errorMessage, setErrorMessage ] = useState( false ); | ||
const postId = useSelect( select => select( 'core/editor' ).getCurrentPostId() ); | ||
const { __unstableSaveForPreview } = useDispatch( editorStore ); | ||
const [ isSmall ] = useBreakpointMatch( 'sm' ); | ||
const { tracks } = useAnalytics(); | ||
|
||
const sendEmailPreview = () => { | ||
const sendEmailPreview = async () => { | ||
tracks.recordEvent( 'jetpack_send_email_preview', { | ||
post_id: postId, | ||
} ); | ||
|
||
setEmailSending( true ); | ||
|
||
// Save post revision so that we send what they see in the editor, and not what previous draft/revision might've saved | ||
// Introduced at GB 16.3 at https://github.com/WordPress/gutenberg/pull/44971 | ||
if ( typeof __unstableSaveForPreview === 'function' ) { | ||
await __unstableSaveForPreview(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
} | ||
|
||
apiFetch( { | ||
path: '/wpcom/v2/send-email-preview/', | ||
method: 'POST', | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@Automattic/jetpack-crew in case you had advice on how to handle Gutenberg functions and backwards compatibility with older WPs in Jetpack; this isn't really issue for .com since we run the latest.
Method introduced in WordPress/gutenberg#44971
It's here, and it's contents are stable so in theory I could just copy all that code here instead.
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.
Jetpack needs to support back to the version of the Gutenberg packages that is bundled in the previous WordPress release, which is currently 6.3.
I guess the case here is that 6.3 (and maybe 6.4 too?) doesn't have any version of the function at all, and you're wanting to copy-paste the implementation into Jetpack so the change you're making here still happens in 6.3? Be sure to include a comment indicating that the back-compat code can be removed when we drop support for the old version. Something along the lines of
// @todo Remove the `if` check and `else` branch once WP 6.4 is the minimum supported version
is fine, you don't have to get too fancy. Just be sure the comment clearly mentions an appropriate WordPress version so we can find it easily via a grep when we're making the PRs like #34210.Or if it's ok that WP 6.3 just doesn't do whatever the new function does, that's fine with us too. Again though a comment mentioning the WP version when the
if
check can be removed would be useful.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!