Skip to content
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

Block warning: allow re-editing of HTML #9088

Closed
wants to merge 2 commits into from

Conversation

johngodley
Copy link
Contributor

If a block is flagged as invalid then allow it to be re-edited in HTML mode so the content can be fixed. This allows a quicker route to fixing an invalid block if you happen to make a mistake in the HTML.

edit_post_ wordpress_latest _wordpress

Leads to:

edit_post_ wordpress_latest _wordpress

Note that selecting 'edit visually' while in HTML will re-trigger the invalid warning if the problem has not been fixed.

This fixes the issue of the 'edit as HTML' / 'edit visually' block options being available but having no effect in #7743

How has this been tested?

Additional unit test has been added to verify that a block can be re-edited in HTML mode.

To manually test:

  • Add a paragraph block, edit as HTML, and remove the trailing </p> - tab out of the editor to trigger an invalid block warning
  • From the block menu select 'Edit as HTML'
  • Verify that the invalid block warning is removed and the HTML editor is shown with the invalid HTML content
  • Verify that selecting 'Edit visually' from the block menu triggers the invalid block warning again

Types of changes

Potentially breaking feature.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@ZebulanStanphill
Copy link
Member

Nice change! I think this is a good idea. Previously you would have had to use the Undo button to fix a block that you made invalid without potentially losing data (due to issues like #6878) or converting to a Custom HTML block.

On a side note, I feel like the Keep as HTML button should be renamed to Convert to Custom HTML block, or Convert to HTML block, or Keep as HTML block, or something like that. As it is, Keep as HTML is kind of misleading.

@johngodley johngodley changed the title WIP: Block warning: allow re-editing of HTML Block warning: allow re-editing of HTML Aug 21, 2018
@johngodley johngodley removed the [Status] In Progress Tracking issues with work in progress label Aug 21, 2018
Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this feature, and it may be a good option to fix blocks if the user changed them by mistake in the code editor for example.
In the future, we may consider adding an "Edit As HTML" button in the invalid block waring so the user knows this option is available in case the block is valid. Right now this feature is a bit hidden and the user is only aware of this option if the menu is open.


if ( ! isValid ) {
// An error was detected so flip the block back to visual mode so we see the invalid block warning
this.props.onToggleMode( this.props.clientId );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching back to visual mode if the block becomes invalid may cause some troubles. Blur events are very easy to trigger, and the user may be in the invalid state temporarily while in process of writing a valid change.
I would prefer if the switch was not automatic, but I would love other options regarding the UX cc: @jasmussen, @karmatosed.
Another possibility for automatic switching to the visual mode when the block is invalid would be switching when another block is selected/block is unselected. It would also make the user notice the warning, but the switch is not as unexpected as with the blur event.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably didn't explain this well in the description but nothing really changes for the user, and the behaviour is the same as currently.

When the onBlur fires the HTML validation is performed and the block is set as invalid, showing the invalid block message. At this point the block is still in HTML mode, although you don't see this, and the dropdown menu option will be 'Edit visually' (which we don't want).

The extra onToggleMode switches the block to visual mode so the menu will show `Edit as HTML'. The only change is for the menu toggle - nothing will visually change for the user as the block is invalid and will continue to show the invalid block message (i.e. the visual mode is not shown)

@@ -405,9 +405,12 @@ export class BlockListBlock extends Component {
const shouldShowInsertionPoint = ( isPartOfMultiSelection && isFirst ) || ! isPartOfMultiSelection;
const canShowInBetweenInserter = ! isEmptyDefaultBlock && ! isPreviousBlockADefaultEmptyBlock;

// We allow an invalid block to be re-edited in HTML mode
const isValidMode = isValid || mode === 'html';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the variable name suggests that it checks if the mode is valid or not, while the variable contains if the block is valid or we are in HTML mode. Maybe we can call it isValidOrModeIsHtml.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be isValidOrModeIsHTML or isValidOrModeIsHtml? I forgot what the consensus was for acronyms in variable names. (I know id should be id if at the start or Id otherwise, since it is not an acronym but just an abbreviation like var is an abbreviation of variable.)

@johngodley
Copy link
Contributor Author

In the future, we may consider adding an "Edit As HTML" button in the invalid block waring so the user knows this option is available in case the block is valid. Right now this feature is a bit hidden and the user is only aware of this option if the menu is open.

Yep. It came up in discussion in #7743 (comment) where it was decided not to do that right now, but it's worth considering in the future if things change.

@jasmussen
Copy link
Contributor

So here's a GIF:

the issue

Steps taken:

  • Click Edit as HTML
  • Insert a single unclosed <div>
  • Click outside

In master, and in this branch, clicking outside switches back to Visual editing for the block, and it shows the block warning.

I'm not against merging improvements even with that behavior in place, however it seems like the better experience would be that after you start editing in HTML mode and click outside, the block remains in HTML mode, and the warning is only triggered once you explicitly exit HTML mode for that block.

However I see the problem with that too.

Another solution would be to always switch out of HTML mode when you click outside the block, at least then it would be consistent behavior.

A third option would probably be more ideal, though not sure if it's in scope of PR. That is to show the block warning also in HTML mode — it would have to be a warning that doesn't change the size of the block itself, still allows you to continue editing and so on. Mockup:

exit code

This follows a separate idea that we've had, of adding such an "exit" bar to the code editor too:

code editor

What do you think? Easy? Hard? If hard, worth ticketing separately.

@johngodley
Copy link
Contributor Author

I get what you mean in the GIF, although it is still an improvement over master where it's broken!

In master, and in this branch, clicking outside switches back to Visual editing for the block, and it shows the block warning.

In master the block is technically still in HTML mode, but this is hidden. What you see is the invalid block, which displays a visual (and non-editable) render of the block. You can verify this by noting that the dropdown menu on an invalid block shows 'Edit visually', indicating it's in HTML mode.

edit_post_ wordpress_latest _wordpress

This PR contains a change that will switch it to visual mode. Again this is still hidden, but enables the dropdown menu to then show the 'edit as HTML' option.

adding such an "exit" bar to the code editor too:

That seems like a good idea. I'm not sure if the dropdown menu disappears in this case, but either way I think it's a separate improvement. The inability to re-edit HTML will still exist though, as once you've exited the HTML editor the block will be invalid and the 'edit as HTML' option will have no effect.

It seems like there are two issues:

  1. What triggers the invalid block (currently onBlur)
  2. Allow an invalid block to be re-edited (currently broken)

This PR attempts to fix 2 using the current onBlur trigger. It makes no changes to 1.

The question is whether this PR is a good step towards fixing 2? Improving 1 can be done in another PR, and the fix to 2 here should still apply (at this point the change in onBlur here probably won't be needed)

@jasmussen
Copy link
Contributor

Yep, solid arguments. I think it would be good to ship this, and then look at any additional improvements separately.

@johngodley
Copy link
Contributor Author

I've tracked the trigger issue in #9304

@johngodley johngodley requested a review from a team September 6, 2018 12:47
@johngodley johngodley force-pushed the add/block-reedit-invalid branch from b32e09f to 3cc9f91 Compare September 13, 2018 11:47
@johngodley johngodley force-pushed the add/block-reedit-invalid branch from ac6a5ff to 2a65971 Compare October 17, 2018 09:23
@johngodley johngodley force-pushed the add/block-reedit-invalid branch 2 times, most recently from ef58acb to 2affe3d Compare November 1, 2018 12:39
@johngodley johngodley force-pushed the add/block-reedit-invalid branch from 2affe3d to 5e17532 Compare November 12, 2018 13:47
If a block is flagged as containing invalid content then allow it to be re-edited in HTML mode so the content can be fixed.
@johngodley johngodley force-pushed the add/block-reedit-invalid branch from 5e17532 to 716b15a Compare December 4, 2018 13:52
@gziolo
Copy link
Member

gziolo commented Feb 1, 2019

@mapk and @youknowriad - is this something we should prioritize to include in Phase 2?

@youknowriad
Copy link
Contributor

I don't think it needs to be prioritized, this could be considered part of the "tightning up", it's not crucial but good to have.

@gziolo gziolo added this to the 5.1 (Gutenberg) milestone Feb 1, 2019
@mapk
Copy link
Contributor

mapk commented Feb 5, 2019

It appears there's not much more to do here, so if it's solid where it's at, LGTM.

@youknowriad youknowriad removed this from the 5.3 (Gutenberg) milestone Mar 18, 2019
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-wise, this looks and works well.

Two things:

  • Could you rebase to resolve the conflicts?
  • The design of this warning has changed since the pull request was first opened. There's now a separate dropdown menu which appears for an invalid block, in addition to the default block settings menu. I think it's generally okay in that "Edit as HTML" is always in the block settings menu, but I'd be lying if I said it wasn't my first intuition to check under the dropdown menu of the invalid block.

image

@kjellr
Copy link
Contributor

kjellr commented Apr 24, 2019

The design of this warning has changed since the pull request was first opened. There's now a separate dropdown menu which appears for an invalid block, in addition to the default block settings menu. I think it's generally okay in that "Edit as HTML" is always in the block settings menu, but I'd be lying if I said it wasn't my first intuition to check under the dropdown menu of the invalid block.

That's a good point, @aduth. I wouldn't mind it being included in two places in this case.

@paaljoachim
Copy link
Contributor

Hey @johngodley

What is needed to move this PR onward? Could you give a status update to where the PR is at the moment?

@gziolo

@johngodley
Copy link
Contributor Author

@paaljoachim I doubt very much whether this code still works, and it probably requires more than just a rebase. I'm not looking at it currently, but may return in the future. If anyone wants to take it over then that's great.

@youknowriad
Copy link
Contributor

Trying to triage PRs today. Given that we're not investing in this right now and that the PR needs to be rewritten entirely with all the changes in master. I'm going to close this PR for now. Thanks all for your efforts.

@aduth aduth deleted the add/block-reedit-invalid branch March 18, 2020 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.