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

Immediately add/remove DevTools-related AMP admin menu items when setting updated #6878

Merged

Conversation

NikhilJoshua
Copy link
Contributor

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

  • 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).

Show/Hides Developer Tools in WP AMP menu section when Enable Developer tools is toggled and saved
@NikhilJoshua NikhilJoshua force-pushed the bug/6714-show-hide-devtools-on-save branch from d878740 to 32233f8 Compare February 4, 2022 10:55
@maitreyie-chavan maitreyie-chavan added this to the v2.2.2 milestone Feb 9, 2022
@maitreyie-chavan maitreyie-chavan added the Bug Something isn't working label Feb 9, 2022
Copy link
Collaborator

@dhaval-parekh dhaval-parekh left a 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
  ...
Comment on lines 164 to 181
/*
* 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 );
};
Copy link
Member

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.

return;
}

addAmpDevOptions( __( 'Validated URLs', 'amp' ), 'edit.php?post_type=amp_validated_url' );
Copy link
Member

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.

}

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' );
Copy link
Member

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.

* 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"]' )
Copy link
Member

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.

@westonruter
Copy link
Member

I apologize for my delay in reviewing. Please take a look at my suggested changes in 41dac1d.

@NikhilJoshua
Copy link
Contributor Author

NikhilJoshua commented Mar 3, 2022

I apologize for my delay in reviewing. Please take a look at my suggested changes in 41dac1d.

Thanks for the updates/changes :) @westonruter

@NikhilJoshua NikhilJoshua requested a review from westonruter March 3, 2022 06:11
@westonruter westonruter changed the title Update AMP menu item based on AMP settings when it saved. Immediately show/hide DevTools-related AMP admin menu items when setting updated Mar 3, 2022
@westonruter westonruter changed the title Immediately show/hide DevTools-related AMP admin menu items when setting updated Immediately add/remove DevTools-related AMP admin menu items when setting updated Mar 3, 2022
@westonruter westonruter merged commit ae407f9 into ampproject:develop Mar 3, 2022
westonruter added a commit that referenced this pull request Mar 3, 2022
…ting updated (#6878)

Co-authored-by: Nikhil Joshua <nikhiljoshua.a@gmail.com>
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Changelogged Whether the issue/PR has been added to release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure any changes to the "Enable Developer Tools" option reload the page to in
4 participants