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

Add AMP plugin editor sidebar #5589

Merged
merged 148 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
127a7fa
AMP plugin sidebar
johnwatkins0 Nov 10, 2020
b3e3058
Fix ampBroken logic
johnwatkins0 Nov 10, 2020
3a69c9a
Change new validation errors heading text
johnwatkins0 Nov 12, 2020
cedf6f5
AMP plugin sidebar
johnwatkins0 Nov 10, 2020
ee94295
Fix ampBroken logic
johnwatkins0 Nov 10, 2020
e4613b4
Change new validation errors heading text
johnwatkins0 Nov 12, 2020
43ed5b2
Sidebar: update error display logic and add new styles
johnwatkins0 Nov 18, 2020
a52d018
Merge branch 'feature/3821-block-validation-sidebar' of https://githu…
johnwatkins0 Nov 18, 2020
c827669
Pass initially open term ID into URL validation screen
johnwatkins0 Nov 18, 2020
987ab40
Scroll into view
johnwatkins0 Nov 20, 2020
15337e7
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Nov 20, 2020
5ef519d
Update error content text
johnwatkins0 Nov 21, 2020
eea577c
Icon style updates
johnwatkins0 Nov 22, 2020
df4ba1c
Create block sources service class
johnwatkins0 Nov 22, 2020
68f0e1d
Integrate block sources info and add tests
johnwatkins0 Nov 23, 2020
55d3577
Fix JS lint issues
johnwatkins0 Nov 23, 2020
710df98
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Nov 23, 2020
71106ec
Add more Jest coverage for error component
johnwatkins0 Nov 24, 2020
f5040f4
PHPCS
johnwatkins0 Nov 24, 2020
88060a9
PHPStan fix
johnwatkins0 Nov 24, 2020
4096fff
Fix PHPUnit test
johnwatkins0 Nov 24, 2020
9a056bf
Put AMPBlockValidation into index.js
johnwatkins0 Nov 24, 2020
28cd8a3
PHPUnit test fix
johnwatkins0 Nov 24, 2020
3dd14fa
Set screen in validation manager test setup to ensure dependencies load
johnwatkins0 Nov 24, 2020
28f4deb
Fix dependencies array in test
johnwatkins0 Nov 24, 2020
865fb27
Clear current screen in frontend tests
johnwatkins0 Nov 24, 2020
3a0d353
Add PHPUnit tests for BlockSources class
johnwatkins0 Nov 24, 2020
7dd5e89
Fix failing jest tests
johnwatkins0 Nov 24, 2020
384106f
Add tests for toolbar button
johnwatkins0 Nov 25, 2020
d44d874
Add addToolbarButtonToBlock tests
johnwatkins0 Nov 25, 2020
a4b1230
Simplify ValidationErrorStateUpdater
johnwatkins0 Nov 25, 2020
cc1e81b
Attempt to hide __DATA__directory in GitHub
johnwatkins0 Nov 25, 2020
d3f71ea
Minor editor sidebar updates
johnwatkins0 Nov 26, 2020
0f5754c
Increase test coverage for error component
johnwatkins0 Nov 26, 2020
21ae619
Add tests for icons
johnwatkins0 Nov 26, 2020
cf7fb1f
Add missing useMemo dependency
johnwatkins0 Nov 26, 2020
27c37a7
Remove extra set_current_screen in test
johnwatkins0 Nov 26, 2020
69db14e
Only provide block sources if is admin
johnwatkins0 Nov 26, 2020
e11cbfa
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Nov 30, 2020
63ae231
Use HOC to add AMP toolbar button to blocks
johnwatkins0 Nov 30, 2020
cfe19d7
Use SVG files for icons
johnwatkins0 Nov 30, 2020
631eb12
Convert validation error state updater to hook
johnwatkins0 Nov 30, 2020
9f10715
Fix failing PHPUnit test covering script dependencies
johnwatkins0 Nov 30, 2020
8093216
Use LikelyCulpritDetector to generate block sources
johnwatkins0 Nov 30, 2020
b2b5fa7
Remove unused constants
johnwatkins0 Nov 30, 2020
f1740df
Minor editor sidebar logic and style updates
johnwatkins0 Nov 30, 2020
7c7ad4d
Fix param type
johnwatkins0 Nov 30, 2020
0c232e8
Skip tests if version is insufficient
johnwatkins0 Nov 30, 2020
5270e5f
Mark more tests skipped
johnwatkins0 Nov 30, 2020
5719556
Add kept error icon and update HTML icon
johnwatkins0 Dec 1, 2020
7f3e8ab
Add editor support service
johnwatkins0 Dec 1, 2020
7187026
Fix test failure due to missing service
johnwatkins0 Dec 1, 2020
5b9455b
Remove obsolete tests
johnwatkins0 Dec 1, 2020
470e6bc
Style updates
johnwatkins0 Dec 2, 2020
7a87941
Enhanced retrieval of error sources
johnwatkins0 Dec 2, 2020
27241b8
Fix incorrect attributes
johnwatkins0 Dec 3, 2020
554ebf7
Style adjustments
johnwatkins0 Dec 3, 2020
6ef589c
Editor sidebar: fix failing jest tests
johnwatkins0 Dec 3, 2020
07bb502
Update format of translator comments
johnwatkins0 Dec 3, 2020
d5631a1
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Dec 7, 2020
eeaa4c7
Plugin sidebar style updates
johnwatkins0 Dec 7, 2020
46a204e
Add AMP UUID
johnwatkins0 Dec 9, 2020
7792450
Move AMP UUID effect to block validation script
johnwatkins0 Dec 9, 2020
1b7d244
Fix Jest mock
johnwatkins0 Dec 9, 2020
b142dcf
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Dec 9, 2020
9be8ba8
Plugin sidebar modifications
johnwatkins0 Dec 10, 2020
7460281
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Dec 14, 2020
03f7a61
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Dec 15, 2020
4bd0905
Editor sidebar style updates
johnwatkins0 Dec 15, 2020
eed3458
Remove term_id form URL after autoscrolling to prevent repeat on update
johnwatkins0 Dec 15, 2020
e486756
Remove amp uuid
johnwatkins0 Dec 16, 2020
c2d61b7
PHPCS fix
johnwatkins0 Dec 16, 2020
ad71b5e
Unit test fix
johnwatkins0 Dec 16, 2020
228cb81
Unit test fix
johnwatkins0 Dec 16, 2020
e705a01
PHPUnit fix
johnwatkins0 Dec 16, 2020
cdad327
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Dec 16, 2020
88b2b5f
Remove useInlineData in favor of webpack externals approach
johnwatkins0 Dec 16, 2020
8c6d326
Disable block soruces below WP 5.5
johnwatkins0 Dec 16, 2020
ccda9e3
Style updates for validation errors panel body
johnwatkins0 Dec 16, 2020
781ccec
Increase JS test coverage
johnwatkins0 Dec 16, 2020
d829e71
Increase test coverage for EditorSupport
johnwatkins0 Dec 16, 2020
3581512
PHPCS fix
johnwatkins0 Dec 16, 2020
8647ad0
Style updates
johnwatkins0 Dec 16, 2020
a58c3bd
Adjust tests to handle different WP versions
johnwatkins0 Dec 16, 2020
b90f387
Unset current screen global after use
johnwatkins0 Dec 16, 2020
4d66cff
Unset wp_scripts global after use in test
johnwatkins0 Dec 16, 2020
aebeadc
Fall back to block slug if blockSources is not available
johnwatkins0 Dec 16, 2020
cbf1e51
Undo change to amp_should_use_new_onboarding
johnwatkins0 Dec 16, 2020
6785cf5
Add Gutenberg version check in test
johnwatkins0 Dec 16, 2020
a5aa07c
Remove test that fails in action envrionment only
johnwatkins0 Dec 16, 2020
d643177
Second attempt at increasing EditorSupport class test coverage
johnwatkins0 Dec 17, 2020
fc84d51
Increase PHPUnit test coverage
johnwatkins0 Dec 17, 2020
998f1d1
Fix test for Actions environment
johnwatkins0 Dec 17, 2020
69dd546
Add tests for useValidationErrorStateUpdates
johnwatkins0 Dec 17, 2020
81fa246
Make use of .phpstorm.meta.php to provide typing info
westonruter Dec 18, 2020
5d52612
Account for mu-plugins being present on test environment
westonruter Dec 18, 2020
6e801ca
Amend phpdoc and remove unused use statements
westonruter Dec 18, 2020
e562eb9
Mark skipped instead of returning in test_enqueue_block_validation
westonruter Dec 18, 2020
08bc3ee
Show errors if post is not auto-draft
johnwatkins0 Dec 18, 2020
db11545
Convert toggle function into actual class method
westonruter Dec 20, 2020
b146882
Simplify conditions in maybeInitiallyOpenRow
westonruter Dec 20, 2020
514182c
Utilize location.hash instead of query param for validation error det…
westonruter Dec 20, 2020
cdb0bd2
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Dec 21, 2020
a96ba65
Set URL global in Jest environment
johnwatkins0 Dec 21, 2020
ff49b62
Use option chaining to prevent test failure
johnwatkins0 Dec 21, 2020
59bcd96
Remove JS dependency from array in test
johnwatkins0 Dec 21, 2020
b9d332b
Adjust icon color
johnwatkins0 Dec 21, 2020
8b36b10
Remove icon style adjustment
johnwatkins0 Dec 21, 2020
d32fe9d
Remove debug line
johnwatkins0 Dec 21, 2020
2480c14
Make props required in propTypes checks
johnwatkins0 Dec 22, 2020
d5eff39
Use a different format for translators comments.
johnwatkins0 Dec 22, 2020
47d9c0d
Add space before comment
johnwatkins0 Dec 22, 2020
6e54b50
Use args instead of props in docblock
johnwatkins0 Dec 22, 2020
eb8ef36
Pass empty array as second argument to useSelect
johnwatkins0 Dec 22, 2020
fcbf25a
Several minor updates to text, formatting, and comments
johnwatkins0 Dec 22, 2020
0003d78
PHPCS fixes
johnwatkins0 Dec 22, 2020
8aa1809
Add todo comment
johnwatkins0 Dec 23, 2020
bbb0e49
Apply array_values to filtered array to reset indexes
johnwatkins0 Dec 23, 2020
cd68eff
Eliminate use of plugin Title
johnwatkins0 Dec 23, 2020
cbc69c8
Reduce condition nesting
johnwatkins0 Dec 23, 2020
7617125
Add comment to convertErrorSourcesToArray
johnwatkins0 Dec 23, 2020
62d413d
Adjust condition in which the pre-saved message shows
johnwatkins0 Dec 24, 2020
f47f7d7
Merge remote-tracking branch 'origin/develop' into feature/3821-block…
johnwatkins0 Dec 28, 2020
f4f9132
Remove unneeded className attribute
johnwatkins0 Dec 28, 2020
b50fdcd
Remove unneeded className attribute
johnwatkins0 Dec 28, 2020
94311fe
Provide constants from PHP
johnwatkins0 Dec 28, 2020
564d45a
Merge branch 'feature/3821-block-validation-sidebar' of https://githu…
johnwatkins0 Dec 28, 2020
0398731
Remove debug code
johnwatkins0 Dec 28, 2020
7929bd1
Avoid passing clientId prop to child component that doesn't render if…
johnwatkins0 Dec 28, 2020
5c641a4
Fix import
johnwatkins0 Dec 28, 2020
cec5fbf
Remove unneeded import
johnwatkins0 Dec 28, 2020
c8cb413
Remove unneeded export
johnwatkins0 Dec 28, 2020
8ff3949
Use core ExternalLink component instead of custom SVG
johnwatkins0 Dec 28, 2020
eece73a
Merge branch 'feature/3821-block-validation-sidebar' of https://githu…
johnwatkins0 Dec 28, 2020
9d8ad14
Fix import block comments
johnwatkins0 Dec 28, 2020
6a3df3f
Fix import comments
johnwatkins0 Dec 28, 2020
af1dc4d
Minor comment fixes
johnwatkins0 Dec 28, 2020
e3721ec
Add Services::has method
johnwatkins0 Dec 28, 2020
473f6ab
Merge branch 'feature/3821-block-validation-sidebar' of https://githu…
johnwatkins0 Dec 28, 2020
31278f2
Apply suggestions from code review
johnwatkins0 Dec 28, 2020
b1a6a11
Handle case where error has no type
johnwatkins0 Dec 28, 2020
1d6a0a3
Open error when its block icon is clicked
johnwatkins0 Dec 28, 2020
29cf878
AMP block toolbar button: prevent closing error if already opened
johnwatkins0 Dec 29, 2020
66666f0
Merge branch 'develop' of github.com:ampproject/amp-wp into feature/3…
westonruter Dec 30, 2020
ec509b8
Add missing class to amp-toolbar-icon
westonruter Dec 30, 2020
8f5fbb8
Expand all validation errors associatd with a block and ensure in vie…
westonruter Dec 30, 2020
c1b5b86
Prevent invalid-block-outline from causing block to be unclickable
westonruter Dec 30, 2020
96c1a96
Further refine messaging related to validation issues
westonruter Dec 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/images/amp-css-error-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/images/amp-js-error-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions assets/images/amp-new-tab-icon.svg

This file was deleted.

4 changes: 4 additions & 0 deletions assets/src/block-validation/__mocks__/amp-block-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ module.exports = {
},
themeName: 'Test theme',
themeSlug: 'test-theme',
VALIDATION_ERROR_NEW_REJECTED_STATUS: 0,
VALIDATION_ERROR_NEW_ACCEPTED_STATUS: 1,
VALIDATION_ERROR_ACK_REJECTED_STATUS: 2,
VALIDATION_ERROR_ACK_ACCEPTED_STATUS: 3,
};
8 changes: 7 additions & 1 deletion assets/src/block-validation/amp-toolbar-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@ import { PLUGIN_NAME, SIDEBAR_NAME } from '.';
* AMP button displaying in the block toolbar.
*
* @param {Object} props Component props.
* @param {string} props.clientId Block Client ID.
* @param {number} props.count The number of errors associated with the block.
*/
export function AMPToolbarButton( { count } ) {
export function AMPToolbarButton( { clientId, count } ) {
const { openGeneralSidebar } = useDispatch( 'core/edit-post' );

return (
<BlockControls>
<ToolbarButton
onClick={ () => {
openGeneralSidebar( `${ PLUGIN_NAME }/${ SIDEBAR_NAME }` );
// eslint-disable-next-line @wordpress/react-no-unsafe-timeout
setTimeout( () => {
document.querySelector( `.error-${ clientId }:not(.is-opened) button` )?.click();
} );
} }
>
<ToolbarIcon count={ count } />
Expand All @@ -38,5 +43,6 @@ export function AMPToolbarButton( { count } ) {
);
}
AMPToolbarButton.propTypes = {
clientId: PropTypes.string.isRequired,
count: PropTypes.number.isRequired,
};
6 changes: 0 additions & 6 deletions assets/src/block-validation/constants.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
// See \AMP_Validation_Error_Taxonomy class in PHP.
export const VALIDATION_ERROR_NEW_REJECTED_STATUS = 0;
export const VALIDATION_ERROR_NEW_ACCEPTED_STATUS = 1;
export const VALIDATION_ERROR_ACK_REJECTED_STATUS = 2;
export const VALIDATION_ERROR_ACK_ACCEPTED_STATUS = 3;

// See \AMP_Validation_Manager::VALIDITY_REST_FIELD_NAME in PHP.
export const AMP_VALIDITY_REST_FIELD_NAME = 'amp_validity';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if these constants should instead be supplied via amp-block-validation. That would lessen the burden of maintaining them if one of the values were to change in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 94311fe, except amp_validity, which is going to be removed in #5741.

24 changes: 9 additions & 15 deletions assets/src/block-validation/error/error-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
* External dependencies
*/
import PropTypes from 'prop-types';
import { blockSources } from 'amp-block-validation';
import {
blockSources,
VALIDATION_ERROR_ACK_ACCEPTED_STATUS,
VALIDATION_ERROR_ACK_REJECTED_STATUS,
VALIDATION_ERROR_NEW_ACCEPTED_STATUS,
VALIDATION_ERROR_NEW_REJECTED_STATUS,
} from 'amp-block-validation';

/**
* WordPress dependencies
Expand All @@ -12,12 +18,6 @@ import { sprintf, __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import {
VALIDATION_ERROR_ACK_ACCEPTED_STATUS,
VALIDATION_ERROR_ACK_REJECTED_STATUS,
VALIDATION_ERROR_NEW_ACCEPTED_STATUS,
VALIDATION_ERROR_NEW_REJECTED_STATUS,
} from '../constants';
import AMPAlert from '../../../images/amp-alert.svg';
import AMPDelete from '../../../images/amp-delete.svg';
import { getErrorSourceTitle } from './get-error-source-title';
Expand Down Expand Up @@ -145,10 +145,8 @@ MarkupStatus.propTypes = {
/**
* @param {Object} props
* @param {string} props.blockTypeTitle Title of the block type.
* @param {string} props.clientId Block ID.
*/
function BlockType( { blockTypeTitle, clientId } ) {
if ( clientId ) {
function BlockType( { blockTypeTitle } ) {
return (
<>
<dt>
Expand All @@ -162,12 +160,8 @@ function BlockType( { blockTypeTitle, clientId } ) {
</>
);
}

return null;
}
BlockType.propTypes = {
blockTypeTitle: PropTypes.string,
clientId: PropTypes.string,
};

/**
Expand Down Expand Up @@ -207,7 +201,7 @@ export function ErrorContent( { blockType, clientId, status, title, error: { sou
</>
)
}
<BlockType blockTypeTitle={ blockTypeTitle } clientId={ clientId } />
{ clientId && <BlockType blockTypeTitle={ blockTypeTitle } /> }
<ErrorSource blockTypeName={ blockTypeName } clientId={ clientId } sources={ sources } />
<MarkupStatus status={ status } />
</dl>
Expand Down
10 changes: 4 additions & 6 deletions assets/src/block-validation/error/error-panel-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import PropTypes from 'prop-types';
import { VALIDATION_ERROR_ACK_REJECTED_STATUS, VALIDATION_ERROR_NEW_REJECTED_STATUS } from 'amp-block-validation';

/**
* WordPress dependencies
Expand All @@ -13,11 +14,6 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import AMPAlert from '../../../images/amp-alert.svg';

/**
* Internal dependencies
*/
import { VALIDATION_ERROR_ACK_REJECTED_STATUS, VALIDATION_ERROR_NEW_REJECTED_STATUS } from '../constants';
import { ErrorTypeIcon } from './error-type-icon';

/**
Expand All @@ -38,9 +34,11 @@ export function ErrorPanelTitle( { blockType, title, error: { type }, status } )
return (
<>
<div className="amp-error__icons">
<div className={ `amp-error__error-type-icon amp-error__error-type-icon--${ type.replace( /_/g, '-' ) }` }>
{ type && (
<div className={ `amp-error__error-type-icon amp-error__error-type-icon--${ type?.replace( /_/g, '-' ) }` }>
Copy link
Member

Choose a reason for hiding this comment

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

Optional chaining is unnecessary here since type && ensures it is defined, no?

Suggested change
<div className={ `amp-error__error-type-icon amp-error__error-type-icon--${ type?.replace( /_/g, '-' ) }` }>
<div className={ `amp-error__error-type-icon amp-error__error-type-icon--${ type.replace( /_/g, '-' ) }` }>

<ErrorTypeIcon type={ type } />
</div>
) }
{ blockType?.icon && (
<div className="amp-error__block-type-icon">
<BlockIcon icon={ blockType.icon } />
Expand Down
20 changes: 9 additions & 11 deletions assets/src/block-validation/error/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
* External dependencies
*/
import PropTypes from 'prop-types';
import {
VALIDATION_ERROR_ACK_ACCEPTED_STATUS,
VALIDATION_ERROR_ACK_REJECTED_STATUS,
} from 'amp-block-validation';

/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { PanelBody, Button } from '@wordpress/components';
import { PanelBody, Button, ExternalLink } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import {
AMP_VALIDITY_REST_FIELD_NAME,
VALIDATION_ERROR_ACK_ACCEPTED_STATUS,
VALIDATION_ERROR_ACK_REJECTED_STATUS,
} from '../constants';
import { NewTabIcon } from '../icon';
import { AMP_VALIDITY_REST_FIELD_NAME } from '../constants';
import { ErrorPanelTitle } from './error-panel-title';
import { ErrorContent } from './error-content';

Expand Down Expand Up @@ -50,7 +49,7 @@ export function Error( { clientId, status, term_id: termId, ...props } ) {
return (
<li className="amp-error-container">
<PanelBody
className={ `amp-error amp-error--${ reviewed ? 'reviewed' : 'new' }` }
className={ `amp-error amp-error--${ reviewed ? 'reviewed' : 'new' }${ clientId ? ` error-${ clientId }` : '' }` }
title={
<ErrorPanelTitle { ...props } blockType={ blockType } status={ status } />
}
Expand All @@ -70,15 +69,14 @@ export function Error( { clientId, status, term_id: termId, ...props } ) {
{ __( 'Select block', 'amp' ) }
</Button>
) }
<a
<ExternalLink
href={ detailsUrl.href }
target="_blank"
Copy link
Member

Choose a reason for hiding this comment

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

Instead of _blank we may want this to be a consistent name like validated-url-post-${ postId } so that each of the View Details links will be routed to the same tab.

rel="noreferrer"
className="amp-error__details-link"
>
{ __( 'View details', 'amp' ) }
<NewTabIcon />
</a>
</ExternalLink>
</div>

</PanelBody>
Expand Down
13 changes: 6 additions & 7 deletions assets/src/block-validation/error/test/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
*/
import { act } from 'react-dom/test-utils';
import { noop } from 'lodash';
import {
VALIDATION_ERROR_ACK_ACCEPTED_STATUS,
VALIDATION_ERROR_ACK_REJECTED_STATUS,
VALIDATION_ERROR_NEW_ACCEPTED_STATUS,
VALIDATION_ERROR_NEW_REJECTED_STATUS,
} from 'amp-block-validation';

/**
* WordPress dependencies
*/
import { render } from '@wordpress/element';
import { dispatch, select } from '@wordpress/data';
import { registerBlockType, createBlock } from '@wordpress/blocks';
import '@wordpress/editor';

/**
* Internal dependencies
*/
import { Error } from '..';
import {
VALIDATION_ERROR_ACK_ACCEPTED_STATUS,
VALIDATION_ERROR_ACK_REJECTED_STATUS,
VALIDATION_ERROR_NEW_ACCEPTED_STATUS,
VALIDATION_ERROR_NEW_REJECTED_STATUS,
} from '../../constants';
import { createStore } from '../../store';

let container, pluginBlock, themeBlock, coreBlock, unknownBlock;
Expand Down
10 changes: 1 addition & 9 deletions assets/src/block-validation/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import PropTypes from 'prop-types';
*/
import AMPToolbarIcon from '../../images/amp-icon-toolbar.svg';
import AMPToolbarIconBroken from '../../images/amp-toolbar-icon-broken.svg';
import AMPNewTabIcon from '../../images/amp-new-tab-icon.svg';

/**
* Plugin icon.
Expand All @@ -33,7 +32,7 @@ IconSVG.propTypes = {
* @param {Object} props
* @param {boolean} props.hasBadge Whether the icon is showing a number.
*/
export function BrokenIconSVG( { hasBadge } ) {
function BrokenIconSVG( { hasBadge } ) {
return (
<span className={ `amp-toolbar-broken-icon${ hasBadge ? ' amp-toolbar-broken-icon--has-badge' : '' }` } >
<AMPToolbarIconBroken />
Expand Down Expand Up @@ -76,10 +75,3 @@ ToolbarIcon.propTypes = {
export function MoreMenuIcon() {
return <IconSVG hasBadge={ false } />;
}

/**
* An icon indicating that a link opens in a new tab.
*/
export function NewTabIcon() {
return <AMPNewTabIcon />;
}
12 changes: 5 additions & 7 deletions assets/src/block-validation/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { ToggleControl, PanelBody } from '@wordpress/components';
import { ToggleControl, PanelBody, ExternalLink } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
Expand All @@ -14,7 +14,6 @@ import AMPValidationErrorsIcon from '../../images/amp-validation-errors.svg';
import AMPValidationErrorsKeptIcon from '../../images/amp-validation-errors-kept.svg';
import { Error } from './error';
import { BLOCK_VALIDATION_STORE_KEY } from './store';
import { NewTabIcon } from './icon';
import { AMP_VALIDITY_REST_FIELD_NAME } from './constants';

/**
Expand Down Expand Up @@ -100,10 +99,9 @@ export function Sidebar() {

<p>
{ reviewLink && (
<a href={ reviewLink } className="amp-sidebar__review-link" target="_blank" rel="noreferrer">
<ExternalLink href={ reviewLink } className="amp-sidebar__review-link">
Copy link
Member

Choose a reason for hiding this comment

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

{ __( 'View technical details', 'amp' ) }
<NewTabIcon />
</a>
</ExternalLink>
) }
</p>
</div>
Expand All @@ -122,7 +120,7 @@ export function Sidebar() {
) }

{
! saved && (
! saved && 0 === validationErrors.length && (
<PanelBody opened={ true }>
<p>
{ __( 'The permalink will be checked for validation issues when the post is saved.', 'amp' ) }
westonruter marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -138,7 +136,7 @@ export function Sidebar() {
</PanelBody>
) }

{ saved && 0 < validationErrors.length && (
{ 0 < validationErrors.length && (
0 < displayedErrors.length ? (
<ul>
{ displayedErrors.map( ( validationError, index ) => (
Expand Down
4 changes: 2 additions & 2 deletions assets/src/block-validation/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import { registerStore } from '@wordpress/data';

/**
* Internal dependencies
* External dependencies
*/
import {
VALIDATION_ERROR_ACK_ACCEPTED_STATUS,
VALIDATION_ERROR_ACK_REJECTED_STATUS,
VALIDATION_ERROR_NEW_ACCEPTED_STATUS,
VALIDATION_ERROR_NEW_REJECTED_STATUS,
} from './constants';
} from 'amp-block-validation';

export const BLOCK_VALIDATION_STORE_KEY = 'amp/block-validation';

Expand Down
4 changes: 3 additions & 1 deletion assets/src/block-validation/test/icon.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/**
* External dependencies
*/
import { act } from 'react-dom/test-utils';

/**
* WordPress dependencies
*/
import { render } from '@wordpress/element';
import { act } from 'react-dom/test-utils';

/**
* Internal dependencies
*/
Expand Down
7 changes: 4 additions & 3 deletions assets/src/block-validation/test/store.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/**
* Internal dependencies
*/
/**
* WordPress dependencies
*/
import { dispatch, select } from '@wordpress/data';

/**
* Internal dependencies
*/
import { BLOCK_VALIDATION_STORE_KEY, createStore, INITIAL_STATE } from '../store';
import { rawValidationErrors } from './__data__/raw-validation-errors';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function useValidationErrorStateUpdates() {
validationErrorsFromPost: select( 'core/editor' ).getEditedPostAttribute( AMP_VALIDITY_REST_FIELD_NAME )?.results || [],
} ), [] );

/**
/*
* Runs an equality check when validation errors are received before running the heavier effect.
*/
useEffect( () => {
Expand All @@ -96,7 +96,7 @@ export function useValidationErrorStateUpdates() {
}
}, [ trackedValidationErrorsFromPost, validationErrorsFromPost ] );

/**
/*
* Adds clientIds to the validation errors that are associated with blocks.
*/
useEffect( () => {
Expand Down
Loading