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

Update editor sidebar validation notifications #5929

Merged
merged 34 commits into from
Mar 19, 2021

Conversation

delawski
Copy link
Collaborator

@delawski delawski commented Feb 25, 2021

Summary

Fixes #5304
Relates to #5741

This PR updates the look and feel of the AMP sidebar, most notably the validation notifications area.

List of collapsed errors:

Screenshot 2021-03-17 at 16 07 32

Expanded error with a long message:

Screenshot 2021-03-17 at 16 07 46

Here are the most important changes included in this PR:

  • Extract the logic that determines the messaging in the sidebar from the <Sidebar /> component into the new amp-validation-status components (<AMPValidationStatusNotification /> and <AMPRevalidateNotification />).
  • Introduce a generic <SidebarNotification /> component (along with a dedicated container component).
  • Make the error title in the panel title more compact when collapsed and more descriptive when expanded.
  • Use the text-overflow: ellipsis property for error title when collapsed.
  • Remove the now redundant title from the error content area (title in full is already part of the panel title).
  • Add an icon to the block type component in the error content area.
  • Mark only the "kept" errors with a red left border and remove the exclamation mark from the error panel title.
  • Mark new errors with a light grey background and bold font.
  • Use a white background and a regular font-weight for the reviewed errors.
  • Clean up the CSS and use alphabetical ordering for properties.
  • Extract amp-error-related CSS to a separate stylesheet.
  • Use classname-based CSS selectors for the errors list and list items.
  • Don't escape error message title so that HTML tags like <code> are properly rendered.

The new components are meant to be reused in the Pre-Publish Dialogue and in the general Sidebar, in the AMP section.

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@delawski delawski added this to the v2.1 milestone Feb 25, 2021
@delawski delawski self-assigned this Feb 25, 2021
@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Merging #5929 (a1e079a) into develop (3d4e967) will increase coverage by 0.12%.
The diff coverage is 85.29%.

❗ Current head a1e079a differs from pull request most recent head 17ef326. Consider uploading reports for the commit 17ef326 to get more accurate results
Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #5929      +/-   ##
=============================================
+ Coverage      75.28%   75.41%   +0.12%     
- Complexity      5722     5735      +13     
=============================================
  Files            214      218       +4     
  Lines          17283    17362      +79     
=============================================
+ Hits           13012    13094      +82     
+ Misses          4271     4268       -3     
Flag Coverage Δ Complexity Δ
javascript 80.05% <89.18%> (+0.60%) 0.00 <0.00> (ø)
php 75.22% <80.64%> (+0.09%) 0.00 <13.00> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...ts/src/block-validation/error/error-panel-title.js 100.00% <ø> (ø) 0.00 <0.00> (ø)
...udes/sanitizers/class-amp-core-theme-sanitizer.php 35.87% <0.00%> (-0.26%) 229.00 <1.00> (+1.00) ⬇️
includes/sanitizers/class-amp-meta-sanitizer.php 79.79% <0.00%> (ø) 35.00 <0.00> (ø)
assets/src/block-validation/store.js 94.73% <66.66%> (-5.27%) 0.00 <0.00> (ø)
...n/amp-validation-status/revalidate-notification.js 80.00% <80.00%> (ø) 0.00 <0.00> (?)
src/Transformer/DetermineHeroImages.php 91.04% <90.19%> (+38.66%) 25.00 <12.00> (+12.00)
...k-validation/use-validation-error-state-updates.js 85.07% <92.85%> (+0.56%) 0.00 <0.00> (ø)
...ck-editor/components/sidebar-notification/index.js 100.00% <100.00%> (ø) 0.00 <0.00> (?)
...ation/amp-validation-status/status-notification.js 100.00% <100.00%> (ø) 0.00 <0.00> (?)
assets/src/block-validation/error/error-content.js 93.54% <100.00%> (ø) 0.00 <0.00> (ø)
... and 11 more

@github-actions
Copy link
Contributor

github-actions bot commented Feb 25, 2021

Plugin builds for 17ef326 are ready 🛎️!

Base automatically changed from feature/2069-async-url-validation to develop March 2, 2021 03:25
@westonruter
Copy link
Member

@delawski FYI: There's a conflict now with develop.

@delawski
Copy link
Collaborator Author

delawski commented Mar 2, 2021

@delawski FYI: There's a conflict now with develop.

Thanks for the heads-up. I'll take care of the conflicts when working on the few updates that are still on my todo list for this PR.

@jwold
Copy link
Collaborator

jwold commented Mar 2, 2021

  1. @delawski for error handling what is an example of what an error might say?
  2. Assuming you then need a UI displaying that error. Correct?

@delawski
Copy link
Collaborator Author

delawski commented Mar 4, 2021

  1. For error handling what is an example of what an error might say?

Here's an example of an error message returned by the backend:

Screenshot 2021-02-26 at 14 58 04

  1. Assuming you then need a UI displaying that error. Correct?

Correct.

delawski added 4 commits March 8, 2021 11:59
# Conflicts:
#	assets/src/block-validation/sidebar.js
On the build step, I was getting the following error thrown by the `block-validation/icon.js`:

```
Property value of ObjectProperty expected node to be of a type ["Expression","PatternLike"] but instead got "JSXExpressionContainer"
```

Cleaning up the `amp-logo-icon.svg` markup and passing it through svgomg fixed the issue.
@delawski
Copy link
Collaborator Author

delawski commented Mar 8, 2021

@westonruter @jwold With 543ab48 and c37125e a loading state and an API errors handling have been added to the sidebar notification area:

sidebar-api-error.mov

The error message displayed in the notification is whatever the REST endpoint returns. This might be improved over time. However, since such API-level errors are rather rare I wouldn't worry about that too much at this point.

@jwold
Copy link
Collaborator

jwold commented Mar 9, 2021

This is perfect for now. Great job @delawski !

…304-validation-notifications

* 'develop' of github.com:ampproject/amp-wp: (77 commits)
  Summarize cleaned markdown file count
  Indicate WP_CLI::error() among earlyTerminatingMethodCalls
  Revert change to WORDPRESS_DB_USER
  Remove sizereport.config.js
  Rename env file
  Move duplicate env vars to file
  Supply WP related env vars to CLI container as well
  Debug wp config
  Remove --quiet flag
  Use alternative method to execute SQL command
  Create db before ensuring connection to WordPress
  Debug mysql command
  Disable pseudo-tty allocation for docker-compose command
  Use latest WP image for local env; create database during env setup
  Update workflow name
  Use alternative workflow ID
  Rename workflow
  Don't run workflow if certain files change
  Cancel any previous queued or in-progress workflow runs on push to a branch
  Reduce specificity of CSS selector
  ...
@westonruter
Copy link
Member

Sorry for the delay in reviewing.

@delawski For validation errors which are reviewed, could you add a white left-border or add additional padding so that the unreviewed and reviewed have consistent alignment:

image

@westonruter
Copy link
Member

@delawski Also, where did the link go to access the Validated URL screen? There should be a details link still.

@westonruter
Copy link
Member

The error titles can be much longer than just “invalid element”, especially when translated. Currently the client-side logic is doing something hacky by truncating the title at the first colon. So instead of Invalid element: <code>bad</code> it becomes just Invalid element. This doesn't always work, for example:

image

I think we need to:

  • Discontinue the truncation at the colon.
  • Not have “kept” label spelled out. Having just the icon should be fine because they can expand to understand what the icon means.

Here's a more extreme example of how long the titles can be:

image

Naturally the <code> markup should not be getting escaped in this scenario.

Comment on lines 116 to 123
if ( isEditedPostNew ) {
return (
<SidebarNotification
icon={ <StatusIcon /> }
message={ __( 'Validation will be checked upon saving.', 'amp' ) }
/>
);
}
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 make sense to move this condition up to be the first after the isFetchingErrors conditional?

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense, yes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done in 56ceb8c.

@pierlon
Copy link
Contributor

pierlon commented Mar 19, 2021

Would it make sense adding titles for each section? At the moment they seem bare and the user may not immediately know what they're looking at.

image

@pierlon
Copy link
Contributor

pierlon commented Mar 19, 2021

While testing this I found given a HTML block with the content <?php, a validation error is only raised when it is the first block on the page, which is weird. Here's an example:

potential_bug.mp4

@pierlon
Copy link
Contributor

pierlon commented Mar 19, 2021

Bug replicated on the develop branch as well, so it's not from this PR. Will investigate.

</PanelBody>
)
{ hasReviewedValidationErrors && (
<div className="amp-sidebar__options">
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to place this above the list of errors? One would potentially have to scroll all the way down to see this button (due to viewport constraints or having many errors).

Copy link
Member

Choose a reason for hiding this comment

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

The idea is that this would be clicked infrequently. The main thing a user will care about are the unreviewed issues. The link to show all is there just for curiosity.

@westonruter
Copy link
Member

Would it make sense adding titles for each section? At the moment they seem bare and the user may not immediately know what they're looking at.

Maybe the entire sidebar should be called "AMP Validation" instead of just "AMP" for now?

@pierlon
Copy link
Contributor

pierlon commented Mar 19, 2021

Maybe the entire sidebar should be called "AMP Validation" instead of just "AMP" for now?

That could work as well.

@westonruter
Copy link
Member

While testing this I found given a HTML block with the content <?php, a validation error is only raised when it is the first block on the page, which is weird. Here's an example:

@pierlon It's simply because your <script> tag was not closed properly. If I look at the non-AMP version the syntax highlighting indicates as such:

image

Also see this example code:

<?php

use AmpProject\Dom\Document;

$script_first = '<div>
	<script</script>
	<?php
	?>
</div>';

$pi_first = '<div>
	<?php
	?>
	<script</script>
</div>';

$script_first_doc = Document::fromHtmlFragment( $script_first );
$pi_first_doc = Document::fromHtmlFragment( $pi_first );

echo "## script_first_doc\n";
echo $script_first_doc->saveHTML( $script_first_doc->body );

echo "\n\n";

echo "## pi_first_doc\n";
echo $pi_first_doc->saveHTML( $pi_first_doc->body );

Output:

## script_first_doc
<body><div>
	<script>
	<?php
	?>
</script></div></body>

## pi_first_doc
<body><div>
	<?php ?>
	<script>
</script></div></body>

Notice the PHP processing instruction gets rendered inside the script in the first example, and the PHP PI is there considered text content not markup. So it is not a separate validation error.

@westonruter
Copy link
Member

Maybe the entire sidebar should be called "AMP Validation" instead of just "AMP" for now?

I've made this change:

Screen Shot 2021-03-18 at 23 01 45 Screen Shot 2021-03-18 at 23 02 01

In the future when/if we add non-validation stuff to the sidebar, we can change it back to "AMP".

@westonruter
Copy link
Member

@delawski Would you open a new issue for adding the pre-publish panel?

@delawski
Copy link
Collaborator Author

@pierlon @westonruter I've addressed your feedback. I think the only thing left to do is to update the unit tests for the StatusNotification which I'll do shortly.

Would you open a new issue for adding the pre-publish panel?

Yes, I'll create a single ticket for the pre-publish panel and for the panel in the document sidebar.

Comment on lines 36 to 37
const blockDetails = clientId ? select( 'core/block-editor' ).getBlock( clientId ) : null;
if ( clientId && ! blockDetails ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As in aa668d0, we could get here just the block name instead of the entire block object, i.e.

Suggested change
const blockDetails = clientId ? select( 'core/block-editor' ).getBlock( clientId ) : null;
if ( clientId && ! blockDetails ) {
if ( clientId && ! select( 'core/block-editor' ).getBlockName( clientId ) ) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When I think about it, we could actually replace the entire loop with find method like

-		let _hasErrorsFromRemovedBlocks = false;
-		for ( const validationError of select( BLOCK_VALIDATION_STORE_KEY ).getValidationErrors() ) {
-			const { clientId } = validationError;
-			const blockDetails = clientId ? select( 'core/block-editor' ).getBlock( clientId ) : null;
-			if ( clientId && ! blockDetails ) {
-				_hasErrorsFromRemovedBlocks = true;
-				break;
-			}
-		}
-
-		return {
-			hasErrorsFromRemovedBlocks: _hasErrorsFromRemovedBlocks,
+		const errors = select( BLOCK_VALIDATION_STORE_KEY ).getValidationErrors();
+
+		return {
+			hasErrorsFromRemovedBlocks: Boolean( errors.find( ( { clientId } ) => clientId && ! select( 'core/block-editor' ).getBlockName( clientId ) ) ),

But I guess it might not be as readable as the loop.

Copy link
Member

Choose a reason for hiding this comment

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

I like that latter suggestion. Go ahead with it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good, it's done (in an even shorter form) in 17ef326.

@delawski
Copy link
Collaborator Author

The unit tests should now be good (see: 4794812).

Would you open a new issue for adding the pre-publish panel?

Yes, I'll create a single ticket for the pre-publish panel and for the panel in the document sidebar.

Here's the follow-up ticket: #5997

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

A thing of beauty!

It is a gift!

@pierlon
Copy link
Contributor

pierlon commented Mar 19, 2021

@pierlon It's simply because your <script> tag was not closed properly...

Ah that makes sense. Thanks for solving the mystery @westonruter 🔍.

Copy link
Contributor

@pierlon pierlon left a comment

Choose a reason for hiding this comment

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

Marvelous work done here 🏆.

Comment on lines +33 to +35
hasErrorsFromRemovedBlocks: Boolean( select( BLOCK_VALIDATION_STORE_KEY ).getValidationErrors().find(
( { clientId } ) => clientId && ! select( 'core/block-editor' ).getBlockName( clientId ) ),
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nicely done 👍

@westonruter westonruter merged commit bcd47bf into develop Mar 19, 2021
@westonruter westonruter deleted the feature/5304-validation-notifications branch March 19, 2021 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add explainer to warning notice when validation errors are displayed
4 participants