Repository navigation
Add buttons to copy error details to clipboard - #5500
Conversation
|
Plugin builds for 47fc7be are ready 🛎️!
|
| row.classList.toggle( 'new', ! markingAsReviewed ); | ||
| addBeforeUnloadPrompt(); | ||
| } | ||
| getURLValidationTableRows( { checkedOnly: true } ).forEach( ( row ) => { |
There was a problem hiding this comment.
This is a tangential change. I found myself copying pasting this code (which is from another PR I worked on recently) and instead created the getURLValidationTableRows helper function.
| @@ -0,0 +1,61 @@ | |||
| /** | |||
There was a problem hiding this comment.
Alternatively you could use clipboard.js (which comes bundled with WordPress), but this approach is also fine 👍.
There was a problem hiding this comment.
Good suggestion. I didn't think of this. I've refactored out the wheel-reinvention in 61e571a
| esc_html__( 'Details', 'amp' ) | ||
| ); | ||
|
|
||
| $json = json_decode( $term->description, true ); |
There was a problem hiding this comment.
So for a single error the JSON would look like:
{
"code": "DISALLOWED_TAG",
"node_attributes": {
"src": "https:\/\/wordpressdev.lndo.site\/content\/themes\/twentytwentyone\/assets\/js\/primary-navigation.js?ver=__normalized__",
"id": "twenty-twenty-one-primary-navigation-script-js"
},
"node_name": "script",
"node_type": 1,
"parent_name": "body",
"type": "js_error",
"status": "Removed"
}For the node_type field, I'm wondering if we should get the XML constant name from the value and use that instead. By itself, the constant value wouldn't be of much use and would require the person having to lookup the constants themselves. For reference, here's the list:
There was a problem hiding this comment.
We could reflect the XMLReader class and obtain the constants from there
| } | ||
|
|
||
| const value = getURLValidationTableRows( { checkedOnly: true } ).map( ( row ) => { | ||
| const copyButton = row.querySelector( '.single-url-detail-copy' ); |
There was a problem hiding this comment.
I noticed that if the user changes any of the row's values (without updating the post), the JSON is not updated. For example, updating a validation error to be kept and then copying the JSON for the row does not reflect the updated field value.
|
Thanks for the suggestions, @pierlon. I've updated and am re-requesting now. |
|
The only issue I have with this currently is that the "Copy error details to clipboard" button nor the "Copy to clipboard" buttons stay focused when clicked. Also, should we provide a visual feedback to indicate that the JSON has successfully been copied? |
Good call, I will update. |
|
@pierlon I've addressed your suggestions in ddf5ec4
Let me know what you think. |
| * @param {HTMLElement} event.trigger The element triggering the event. | ||
| */ | ||
| function onSuccess( { trigger } ) { | ||
| trigger.focus(); |
There was a problem hiding this comment.
Yes, looking at my code, that bug makes perfect sense 🤦 Fixing.
Co-authored-by: Weston Ruter <westonruter@google.com>
|
|
||
| $json['status'] = (bool) ( (int) $term->term_group & self::ACCEPTED_VALIDATION_ERROR_BIT_MASK ) ? __( 'Removed', 'amp' ) : __( 'Kept', 'amp' ); | ||
|
|
||
| return wp_json_encode( $json, JSON_PRETTY_PRINT ); |
There was a problem hiding this comment.
Since the slashes aren't needed in this context (and they impair readability):
| return wp_json_encode( $json, JSON_PRETTY_PRINT ); | |
| return wp_json_encode( $json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); |
There was a problem hiding this comment.
I suppose this is not needed if the JSON is re-parsed and re-serialized. If that's the case, then JSON_PRETTY_PRINT isn't needed either.
Co-authored-by: Weston Ruter <westonruter@google.com>
…iewed field Co-authored-by: Weston Ruter <westonruter@google.com>
|
@johnwatkins0 Do you want to rebase this onto |
…oard-friendly-errors
Co-authored-by: Weston Ruter <westonruter@google.com>
|
@westonruter I've addressed all feedback and merged in the latest |
…209-clipboard-friendly-errors * 'develop' of github.com:ampproject/amp-wp: (174 commits) Temporarily force of Composer v1 in CI (#5543) Fix typo in Optimizer readme (#5535) Include file.php separately from class-wp-upgrader.php (#5539) Add PhpIncludeInspection annotation Add PhpUnusedParameterInspection annotation Capture the original block render_callbacks to detect originating plugin Fix Gutenberg 9.2.1 compat due to gutenberg_current_parsed_block_tracking() Ensure full coverage for test_get_plugin_dir Skip Facebook tests earlier when external-http; update skip message Fix CSSList splicing and eliminate reliance on buggy replace/splice methods Add more removed rules that cause splice issue Add charset rule to allowed_at_rules_retained test data Ensure -moz-document rule is removed after replaced Skip FB test once testing external-http suite Add test for PluginRegistry::get_plugin_dir() Ensure css_list is sanitized after -moz-document transformation Transform -moz-document at-rule Firefox hack into supports hack Fix lint error Manually bootstrap WP CLI Skip test if Facebook oEmbed endpoint is down ...
…mpproject/amp-wp into feature/5209-clipboard-friendly-errors * 'feature/5209-clipboard-friendly-errors' of github.com:ampproject/amp-wp: Remove unnecessary aria-label Parse and re-stringify JSON data to prettify No need to pretty-print error details on the backend
Isn't this addressed by #5543? |
westonruter
left a comment
There was a problem hiding this comment.
Love this functionality 👍
@johnwatkins0 is referring to the current GHA workflow used to build the plugin; it's also now using composer v2 which is causing the jobs to fail. |
|
I've run the tests locally and they pass (aside from the oEmbed handlers that . So I'm going ahead and merging. |


Summary
This modifies the single AMP Validated URL screen by making it easier to copy error details to the user's clipboard in pretty-printed JSON format. Users can take action in two ways:
These buttons are to be cleaned up as part of #5431.
QA steps are in #5209
Fixes #5209
Checklist