-
Notifications
You must be signed in to change notification settings - Fork 384
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
Prevent ACK state of non-modified validation errors from being lost; update validation error icons #4382
Prevent ACK state of non-modified validation errors from being lost; update validation error icons #4382
Changes from 38 commits
4860ea1
51ce770
5188d56
06bd910
4dbd3e5
f93c9a8
3557314
9c90d82
5c4eb8d
06aba49
26973ae
67b2a3c
a2f7a90
e49d1ea
f257126
e4fd56c
45d21bd
aaac827
2e0e4f4
b1d7a9f
64e47f3
f4595ca
c615be8
8769996
ff8e065
04eacac
bd2dbea
fc6aa7f
d1bbb4e
2ade4b2
93b08b2
0730b75
b85a2e9
335e863
49dc805
145bb49
9f4de59
b27a961
33f19be
34e3e80
5346025
f571c17
4cee087
740a7ef
53c7a49
07b411e
c35663d
0f22a81
ec71188
c4cb9ab
566aa7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#wpadminbar span.amp-icon { | ||
top: 2px; | ||
} | ||
|
||
#wpadminbar .ab-sub-wrapper span.amp-icon { | ||
position: absolute !important; | ||
margin-left: 2px; | ||
padding: initial !important; | ||
} | ||
|
||
body .amp-icon { | ||
/* stylelint-disable font-family-no-missing-generic-family-keyword */ | ||
font: normal 20px/1 dashicons; | ||
} | ||
|
||
/* | ||
* Colors are taken from the official WordPress color palette. | ||
* See https://make.wordpress.org/design/handbook/design-guide/foundations/colors/#auxiliary-hues | ||
*/ | ||
.amp-icon.amp-valid::before { | ||
content: "\f12a"; | ||
|
||
/* Accent Green */ | ||
color: #46b450 !important; | ||
} | ||
|
||
.amp-icon.amp-invalid::before { | ||
content: "\f153"; | ||
|
||
/* Accent Red */ | ||
color: #dc3232 !important; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep the color semantics we had before. This should be |
||
} | ||
|
||
.amp-icon.amp-warning::before { | ||
content: "\f534"; | ||
|
||
/* Accent Orange */ | ||
color: #ffc733 !important; | ||
} | ||
|
||
.ab-icon.amp-icon.amp-link::before { | ||
content: "\f103"; | ||
} | ||
|
||
.amp-icon.amp-link:not(.ab-icon)::before { | ||
content: "\f103"; | ||
|
||
/* Medium Blue */ | ||
color: #00a0d2 !important; | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ domReady( () => { | |
handleFiltering(); | ||
handleSearching(); | ||
setValidationErrorRowsSeenClass(); | ||
handleStatusChange(); | ||
handleRowEvents(); | ||
handleBulkActions(); | ||
watchForUnsavedChanges(); | ||
setupStylesheetsMetabox(); | ||
|
@@ -56,12 +56,14 @@ const addBeforeUnloadPrompt = () => { | |
/** | ||
* Watch for unsaved changes. | ||
* | ||
* Add an beforeunload warning when attempting to leave the page when there are unsaved changes, | ||
* unless the user is pressing the trash link or update button. | ||
* Add an beforeunload warning when there are unsaved changes for the markup or review status. | ||
*/ | ||
const watchForUnsavedChanges = () => { | ||
const onChange = ( event ) => { | ||
if ( event.target.matches( 'select' ) && event.target.getAttribute( 'id' ) !== 'amp_validation_error_type' ) { | ||
if ( | ||
event.target.matches( '.amp-validation-error-status' ) || | ||
event.target.matches( '.amp-validation-error-status-review' ) | ||
) { | ||
Comment on lines
+63
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, but it's the same behavior as the block editor. You can make a change and then either manually undo the change or click the Undo button, and in both cases clicking reload will show the same AYS dialog. So it's not any worse than what users expect elsewhere in WP. |
||
document.getElementById( 'post' ).removeEventListener( 'change', onChange ); | ||
addBeforeUnloadPrompt(); | ||
} | ||
|
@@ -283,32 +285,35 @@ const handleSearching = () => { | |
const updateSelectIcon = ( select ) => { | ||
pierlon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const newOption = select.options[ select.selectedIndex ]; | ||
if ( newOption ) { | ||
const iconSrc = newOption.getAttribute( 'data-status-icon' ); | ||
select.parentNode.querySelector( 'img' ).setAttribute( 'src', iconSrc ); | ||
const color = newOption.getAttribute( 'data-color' ); | ||
select.style.borderColor = color; | ||
} | ||
}; | ||
|
||
/** | ||
* Handles a change in the error status, like from 'Removed' to 'Kept'. | ||
* | ||
* Gets the data-status-icon value from the newly-selected <option>. | ||
* And sets this as the src of the status icon <img>. | ||
* Handles events that may occur for a row. | ||
*/ | ||
const handleStatusChange = () => { | ||
const onChange = ( { event } ) => { | ||
if ( event.target.matches( 'select' ) ) { | ||
updateSelectIcon( event.target ); | ||
} | ||
}; | ||
|
||
const handleRowEvents = () => { | ||
document.querySelectorAll( 'tr[id^="tag-"]' ).forEach( ( row ) => { | ||
const select = row.querySelector( '.amp-validation-error-status' ); | ||
const statusSelect = row.querySelector( '.amp-validation-error-status' ); | ||
const reviewCheckbox = row.querySelector( '.amp-validation-error-status-review' ); | ||
|
||
if ( select ) { | ||
select.addEventListener( 'change', ( event ) => { | ||
onChange( { event, row, select } ); | ||
if ( statusSelect ) { | ||
/* | ||
* Handle a change in the error status, like from 'Removed' to 'Kept'. It gets the data-color value | ||
* from the newly-selected <option> and sets this as the border color of the <select>. | ||
*/ | ||
statusSelect.addEventListener( 'change', ( event ) => { | ||
if ( event.target.matches( 'select' ) ) { | ||
updateSelectIcon( event.target ); | ||
} | ||
} ); | ||
} | ||
|
||
if ( reviewCheckbox ) { | ||
// Toggle the 'new' state for the row depending on the state of approval for the validation error. | ||
reviewCheckbox.addEventListener( 'change', () => row.classList.toggle( 'new' ) ); | ||
} | ||
} ); | ||
}; | ||
|
||
|
@@ -319,9 +324,9 @@ const handleStatusChange = () => { | |
* Also, on unchecking the last checked box, this hides these buttons. | ||
*/ | ||
const handleBulkActions = () => { | ||
const acceptButton = document.querySelector( 'button.action.accept' ); | ||
const rejectButton = document.querySelector( 'button.action.reject' ); | ||
const acceptAndRejectContainer = document.getElementById( 'accept-reject-buttons' ); | ||
const removeButton = document.querySelector( 'button.action.remove' ); | ||
const keepButton = document.querySelector( 'button.action.keep' ); | ||
const acceptAndRejectContainer = document.getElementById( 'remove-keep-buttons' ); | ||
|
||
const onChange = ( event ) => { | ||
let areThereCheckedBoxes; | ||
|
@@ -356,7 +361,7 @@ const handleBulkActions = () => { | |
} ); | ||
|
||
// Handle click on bulk "Remove" button. | ||
acceptButton.addEventListener( 'click', () => { | ||
removeButton.addEventListener( 'click', () => { | ||
Array.prototype.forEach.call( document.querySelectorAll( 'select.amp-validation-error-status' ), ( select ) => { | ||
if ( select.closest( 'tr' ).querySelector( '.check-column input[type=checkbox]' ).checked ) { | ||
select.value = '3'; // See AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS. | ||
|
@@ -367,7 +372,7 @@ const handleBulkActions = () => { | |
} ); | ||
|
||
// Handle click on bulk "Keep" button. | ||
rejectButton.addEventListener( 'click', () => { | ||
keepButton.addEventListener( 'click', () => { | ||
Array.prototype.forEach.call( document.querySelectorAll( 'select.amp-validation-error-status' ), ( select ) => { | ||
if ( select.closest( 'tr' ).querySelector( '.check-column input[type=checkbox]' ).checked ) { | ||
select.value = '2'; // See AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import domReady from '@wordpress/dom-ready'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
domReady( () => { | ||
const errorDetailList = document.querySelector( 'details > dl.detailed' ); | ||
|
||
addAdditionalErrorDetails( errorDetailList ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As opposed to using JS for this, couldn't the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in f571c17. |
||
unwrapErrorDetails( errorDetailList ); | ||
pierlon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} ); | ||
|
||
const addAdditionalErrorDetails = ( errorDetailList ) => { | ||
addStatusDetail( errorDetailList ); | ||
}; | ||
|
||
const addStatusDetail = ( errorDetails ) => { | ||
const validationStatus = document.querySelector( 'span.status-text' ); | ||
|
||
const term = document.createElement( 'dt' ); | ||
term.textContent = __( 'Status', 'amp' ); | ||
|
||
const detail = document.createElement( 'dd' ); | ||
detail.append( validationStatus ); | ||
|
||
errorDetails.prepend( term, detail ); | ||
}; | ||
|
||
const unwrapErrorDetails = ( errorDetailList ) => { | ||
const detailsElement = errorDetailList.parentNode; | ||
detailsElement.parentNode.append( errorDetailList ); | ||
detailsElement.style.display = 'none'; | ||
}; |
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.
Let's keep the color semantics we had before. This should be
#00ff00
.