-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add block warning overwrite #8166
Conversation
f53ed8c
to
c5389dc
Compare
f3204d3
to
e6ff955
Compare
02c6ba8
to
654100d
Compare
654100d
to
f17c6af
Compare
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 @johngodley, that sounds like a good feature to have 👍 I tried to test this and I'm having some problems. Each time I press the action to overwrite nothing happens.
Am I doing something wrong?
Uhh, sorry - my merge conflict resolving went awry. I've fixed the stupid typo and it should now do something! |
d2ecb6a
to
d9e238a
Compare
d9e238a
to
0ee3177
Compare
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 rebased this PR did some tests things seem fine. I only found a problem with blocks with nested children, I provided a possible code change that seems to fix the problem.
This feature is really useful during block development. Feel free to merge it 👍
@@ -90,6 +91,7 @@ const blockToBlocks = ( block ) => rawHandler( { | |||
HTML: block.originalContent, | |||
mode: 'BLOCKS', | |||
} ); | |||
const blockOverwrite = ( { name, attributes } ) => createBlock( name, attributes ); |
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 checked that on blocks with nested children we delete all the children content and we just restart the innerBlocks area.
That can be tested with block https://gist.github.com/jorgefilipecosta/7f0a54193f9d8d28c1514aa2e57a00fc.
this seems fixable with the following line:
const blockOverwrite = ( { name, attributes, innerBlocks } ) => createBlock( name, attributes, innerBlocks );
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, thanks!
I wonder if this could be renamed to something like "Try to recover this block" or something? "Overwrite with valid block" isn't entirely clear (the "valid" bit in particular might be confusing). Love the idea though! |
Good point. I've changed the text to say 'Attempt block recovery'. If that still makes sense then I'll merge |
Pinging @karmatosed regarding the user experience/message. From the code point of view everything looks fine 👍 |
Attempt works for me :) |
Looks like this needs a rebase. Let's rebase and merge. |
This converts the invalid block to a single block of the same type, with any invalid HTML corrected by the block creation process
Also support inner blocks
f2062ad
to
0db0d39
Compare
## Description Adds an option to the invalid block warning menu to fix the problem by re-creating the block with the current content, overwriting anything that is invalid. This was suggested in #7604 This is similar to the 'convert to blocks' option, but ensures the block stays of the same type. Contrast this with 'convert to blocks' which could convert to another block type, and could end in multiple blocks.  In a lot of situations 'overwrite' and 'convert to blocks' will result in the same conversion so it's debatable whether this is a useful enough conversion to include but I'm raising it here for opinion. This is the same overwrite function that used to exist in older versions of Gutenberg. ## How has this been tested? 1. Add a paragraph block 2. Edit block HTML and paste `<p>this is a paragraph</p><blockquote>invalid content</blockquote>` 3. Deselect the block to trigger invalid block warning 4. Pick 'Convert to blocks' 5. Verify that the invalid block is converted to two blocks - a corrected paragraph and a blockquote  6. Reset block HTML to (2) and pick 'Overwrite with valid block' 7. Verify that the invalid block is converted to the first paragraph 'this is a paragraph', with the blockquote removed ## Types of changes New feature for invalid block warning. Should not affect anything else ## Checklist: - [ ] My code is tested. - [ ] My code follows the WordPress code style. <!-- Check code: `npm run lint`, Guidelines: https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/ --> - [ ] My code follows the accessibility standards. <!-- Guidelines: https://make.wordpress.org/core/handbook/best-practices/coding-standards/accessibility-coding-standards/ --> - [ ] My code has proper inline documentation. <!-- Guidelines: https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/javascript/ -->
## Description Adds an option to the invalid block warning menu to fix the problem by re-creating the block with the current content, overwriting anything that is invalid. This was suggested in #7604 This is similar to the 'convert to blocks' option, but ensures the block stays of the same type. Contrast this with 'convert to blocks' which could convert to another block type, and could end in multiple blocks.  In a lot of situations 'overwrite' and 'convert to blocks' will result in the same conversion so it's debatable whether this is a useful enough conversion to include but I'm raising it here for opinion. This is the same overwrite function that used to exist in older versions of Gutenberg. ## How has this been tested? 1. Add a paragraph block 2. Edit block HTML and paste `<p>this is a paragraph</p><blockquote>invalid content</blockquote>` 3. Deselect the block to trigger invalid block warning 4. Pick 'Convert to blocks' 5. Verify that the invalid block is converted to two blocks - a corrected paragraph and a blockquote  6. Reset block HTML to (2) and pick 'Overwrite with valid block' 7. Verify that the invalid block is converted to the first paragraph 'this is a paragraph', with the blockquote removed ## Types of changes New feature for invalid block warning. Should not affect anything else ## Checklist: - [ ] My code is tested. - [ ] My code follows the WordPress code style. <!-- Check code: `npm run lint`, Guidelines: https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/ --> - [ ] My code follows the accessibility standards. <!-- Guidelines: https://make.wordpress.org/core/handbook/best-practices/coding-standards/accessibility-coding-standards/ --> - [ ] My code has proper inline documentation. <!-- Guidelines: https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/javascript/ -->
Description
Adds an option to the invalid block warning menu to fix the problem by re-creating the block with the current content, overwriting anything that is invalid. This was suggested in #7604
This is similar to the 'convert to blocks' option, but ensures the block stays of the same type. Contrast this with 'convert to blocks' which could convert to another block type, and could end in multiple blocks.
In a lot of situations 'overwrite' and 'convert to blocks' will result in the same conversion so it's debatable whether this is a useful enough conversion to include but I'm raising it here for opinion. This is the same overwrite function that used to exist in older versions of Gutenberg.
How has this been tested?
<p>this is a paragraph</p><blockquote>invalid content</blockquote>
Types of changes
New feature for invalid block warning. Should not affect anything else
Checklist: