-
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
Immediately add/remove DevTools-related AMP admin menu items when setting updated #6878
Immediately add/remove DevTools-related AMP admin menu items when setting updated #6878
Conversation
Show/Hides Developer Tools in WP AMP menu section when Enable Developer tools is toggled and saved
d878740
to
32233f8
Compare
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.
Changes looks good to me.
…show-hide-devtools-on-save * 'develop' of github.com:ampproject/amp-wp: (125 commits) Bump postcss-preset-env from 7.4.1 to 7.4.2 Update namespace for Attribute and Tag interfaces Remove obsolete debug code Defer creation of post fixture until test Add assertion for post data being created before test Add yet more assertions to debug oEmbed problem on GHA Add oembed_request_post_id filter sooner Add more assertions Add assertions Ensure video shortcode is registered to test_process_text_widgets Use oembed_request_post_id for test Add debugging code Fix test_add_block_source_comments for Gutenberg 12.7 Add missing HTTP response mock Add tests for internal post embeds Prevent copying PHP files from `src/` into `assets/` Bump actions/checkout from 2 to 3 Bump eslint-plugin-jsdoc from 37.9.5 to 37.9.6 Update since tag to 2.2.2 Bump eslint-plugin-jsdoc from 37.9.4 to 37.9.5 ...
…em matching more robust
assets/src/settings-page/index.js
Outdated
/* | ||
* Adds the developer tools 'Validated URLs' & 'Error Index' on turning ON | ||
* the 'Enable Developer Tools' toggle button and saving. | ||
*/ | ||
const addAmpDevOptions = ( optionTitle, optionUrl ) => { | ||
const wpAmpSettings = document.querySelector( '#toplevel_page_amp-options ul' ); | ||
|
||
if ( wpAmpSettings === null ) { | ||
return; | ||
} | ||
|
||
const listElement = document.createElement( 'li' ); | ||
const anchorElement = document.createElement( 'a' ); | ||
anchorElement.innerText = optionTitle; | ||
anchorElement.setAttribute( 'href', optionUrl ); | ||
listElement.appendChild( anchorElement ); | ||
wpAmpSettings.appendChild( listElement ); | ||
}; |
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.
This would make sense to be defined at the top level of the module, rather than as a nested callback.
assets/src/settings-page/index.js
Outdated
return; | ||
} | ||
|
||
addAmpDevOptions( __( 'Validated URLs', 'amp' ), 'edit.php?post_type=amp_validated_url' ); |
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.
The URL here is actually already exported as part of amp-settings
as VALIDATED_URLS_LINK
.
assets/src/settings-page/index.js
Outdated
} | ||
|
||
addAmpDevOptions( __( 'Validated URLs', 'amp' ), 'edit.php?post_type=amp_validated_url' ); | ||
addAmpDevOptions( __( 'Error Index', 'amp' ), 'edit-tags.php?taxonomy=amp_validation_error&post_type=amp_validated_url' ); |
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.
To go along with the previous, we could add ERROR_INDEX_LINK
as exported from PHP.
assets/src/settings-page/index.js
Outdated
* Add/Remove Dev Tools 'Validated URLs' & 'Error Index' on 'Enable Developer Tools' ON/OFF on save. | ||
*/ | ||
if ( ! developerToolsOption ) { | ||
document.querySelectorAll( '#toplevel_page_amp-options ul li a[href*="post_type=amp_validated_url"]' ) |
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.
While this works, it seems it could be hardened a bit to prevent removing unexpected menu items.
I apologize for my delay in reviewing. Please take a look at my suggested changes in 41dac1d. |
Thanks for the updates/changes :) @westonruter |
…ting updated (#6878) Co-authored-by: Nikhil Joshua <nikhiljoshua.a@gmail.com>
Summary
Fixes #6714
These changes will add or remove "Validated URL" and "Error Index" menu items from the main AMP menu when the user changes the "Enable Developer Tool" option and save it instead of adding or removing it after page load.
screen-capture.mp4
Checklist