Fix displaying AMP validation error at block level in the Gutenberg editor#1293
Merged
westonruter merged 17 commits intodevelopfrom Aug 1, 2018
Merged
Conversation
added 2 commits
July 30, 2018 12:21
The filter hook name was changed to `editor.BlockEdit` in Gutenberg 3.3. @see https://github.com/WordPress/gutenberg/blob/41fd116ca1f73a9b5c962c66ea0c4aae338ea35e/docs/reference/deprecated.md#330
This was referenced Jul 31, 2018
added 4 commits
July 31, 2018 20:21
On page load, the current post is not initially set up. This commit waits until it is before letting `handleValidationErrorsStateChange()` continue.
Abstracted the "wait" conditional checks into a new method, thereby converting it into one guard clause. Why? This approach improves readability of the `handleValidationErrorsStateChange()` as the intent is clear: when true, wait by bailing out. Then the details of the decision of whether to wait or not is handled elsewhere.
A few changes occurred with this commit: 1. Abstracted the checker. 2. Added the last state declaration on the module itself. 3. Compare the length of the last and current arrays. If not equal, then it changed. <- this one optimizes the checker to avoid running _.isEqual.
Blocks get out of sync in different scenarios. For example, on page load, the block uids will change as the editor loads up and blocks are registered. This commit compares the last known block order to the current block order. If not equal, then it resets the last saved validation errors memory. In doing so, if there are validation errors, then `handleValidationErrorsStateChange()` will continue processing instead of bailing out.
Contributor
Author
|
@westonruter The recent commits fixed 2 issues:
For the last one, the blocks get out of sync. It happens every time when the editor is loading on page load. And I've seen it in other intermittent editing/saving workflow. With these changes, it now checks if the block order changed. If yes, it resets the last validation errors that were previously stored. Can you test it on your machine? @todos: |
…ix/display-validation-error-at-block-level
Gutenberg is removing `uid` and replacing it everywhere with `clientId`. The change is included in 3.4.0 and `uid` will be removed in 3.5.0. @see https://github.com/WordPress/gutenberg/blob/41fd116ca1f73a9b5c962c66ea0c4aae338ea35e/docs/reference/deprecated.md#350 We see the impact of this change as `getBlock()` requires the `clientId` now instead of the `uid`. This commit replaces all references to `uid` with `clientId`. In doing so, it fixes the issue with block-level notifications disappearing when duplicating a block and then saving.
8 tasks
When there are no validation errors, this commit resets the warning notice and stores memory that the notice is reset. This commit also abstracts the warning notice and block level notice resets into two separate methods. This change prompts reuse and moves the details of how to reset into a methods that handle it.
The resetting of block level messages will not be reached when there are no validation errors.
hellofromtonya
commented
Aug 1, 2018
| } catch ( e ) { | ||
| // Clear out block validation errors in case the block sand errors cannot be aligned. | ||
| module.resetBLockNotices(); | ||
| module.resetBlockNotices(); |
Contributor
When a post's AMP toggle is off, the top and block level notices are removed.
westonruter
approved these changes
Aug 1, 2018
Member
|
Great work! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



This PR fixes the problems noted in #1292:
editor.BlockEdit. This filter was changed in Gutenberg 3.3 as noted here:uidtoownProps.clientId. Theidproperty was changed in Gutenberg 3.5.0 to.clientIdas noted here:These two changes result in displaying the AMP validation error at the affected block upon saving or updating:
Handling when blocks get out of sync.
Handling notices when duplicating blocks.
Reset warning notice after removing all affected blocks.
Display block-level notices in native mode or when
force_sanitizationis enabled.Display block-level notices on first loading the post into the editor.
When first opening a post in the editor, the validation notices are displayed. They update when saving.
Remove and disable notice handling when the AMP toggle is off.
When the post's AMP toggle is off, the top and block level notices are removed. It then bails out. When the toggle is turned to on, the notices reappear after saving.
Closes #1292.