-
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
Block warning: allow re-editing of HTML #9088
Conversation
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. |
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 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 ); |
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.
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.
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 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'; |
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.
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.
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.
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.)
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. |
So here's a GIF: Steps taken:
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: This follows a separate idea that we've had, of adding such an "exit" bar to the code editor too: What do you think? Easy? Hard? If hard, worth ticketing separately. |
I get what you mean in the GIF, although it is still an improvement over master where it's broken!
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. 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.
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:
This PR attempts to fix The question is whether this PR is a good step towards fixing |
Yep, solid arguments. I think it would be good to ship this, and then look at any additional improvements separately. |
I've tracked the trigger issue in #9304 |
b32e09f
to
3cc9f91
Compare
ac6a5ff
to
2a65971
Compare
ef58acb
to
2affe3d
Compare
2affe3d
to
5e17532
Compare
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.
5e17532
to
716b15a
Compare
@mapk and @youknowriad - is this something we should prioritize to include in Phase 2? |
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. |
It appears there's not much more to do here, so if it's solid where it's at, LGTM. |
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.
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.
That's a good point, @aduth. I wouldn't mind it being included in two places in this case. |
Hey @johngodley What is needed to move this PR onward? Could you give a status update to where the PR is at the moment? |
@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. |
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. |
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.
Leads to:
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:
</p>
- tab out of the editor to trigger an invalid block warningTypes of changes
Potentially breaking feature.
Checklist: