Add link to analytics options in submenu and make all settings sections linkable#5216
Conversation
|
Plugin builds for 249fb03 are ready 🛎️!
|
…190-settings-screen-anchor-links * 'develop' of github.com:ampproject/amp-wp: Revert "Replace astra with neve for testing since astra is suspended" Unset `$_SERVER['REQUEST_URI']` Fix lint error Default to localhost if `$_SERVER['HTTP_HOST']` is not set Remove check for WP CLI context Default parsed URL host to localhost if in WP CLI context Default parsed URL host to localhost if in WP CLI context Add null as return type Return null if the URL cannot be parsed when in a WP CLI environment Padding: adjust padding on mobile-width close button Ensure non-AMP link in paired browsing does not redirect to AMP version Update dependency @wordpress/data to v4.22.3 Update ReaderThemes::get_themes() to remove any themes that lack slug Also make name optional, falling back to slug Make theme description optional for Reader themes Make homepage a optional field for Reader themes Wizard: move close button to the top in mobile view Defer mobile redirection to end of template_redirect action Fix test referencing core theme Abort post-processing if an expected template was not rendered
assets/src/settings-page/index.js
Outdated
| * Settings page application root. | ||
| * | ||
| * @param {Object} props Component props. | ||
| * @param {string} props.section The initially focused section. |
There was a problem hiding this comment.
Maybe focusedSection would be more clear?
assets/src/settings-page/index.js
Outdated
| const focusedSection = document.getElementById( section ); | ||
|
|
||
| if ( focusedSection ) { | ||
| focusedSection.scrollIntoView(); |
There was a problem hiding this comment.
Would smooth scrolling be desirable?
| focusedSection.scrollIntoView(); | |
| focusedSection.scrollIntoView( { behavior: 'smooth' } ); |
There was a problem hiding this comment.
Alternatively, for accessibility, I think what is needed is to actually focus() on the first focusable element.
So this should be looking for the first button or input that is inside the focusedSection and then focus() on it. This will automatically scroll and add the necessary keyboard focus.
There was a problem hiding this comment.
Done in e41c971d9 with select elements also included
| [ $old_menu[0] ], | ||
| [ | ||
| [ | ||
| __( 'AMP Analytics Options', 'amp' ), |
| array_slice( $old_menu, 1 ) | ||
| ); | ||
|
|
||
| $submenu[ $this->parent_menu_slug ] = array_values( $new_menu ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
There was a problem hiding this comment.
Should not $submenu be modified with add_submenu_page() rather than doing this and the above?
There was a problem hiding this comment.
Ah, you're right. Updated in 0299a03. Didn't realize it would be so simple to link to the parent menu page with a hash appended.
assets/src/settings-page/index.js
Outdated
| <ErrorContextProvider> | ||
| <Providers> | ||
| <Root optionsRestPath={ OPTIONS_REST_PATH } /> | ||
| <Root section={ global.location.hash.replace( /^#/, '' ) } /> |
There was a problem hiding this comment.
I think this can be improved… namely, if I am already on the AMP Settings screen and click the admin menu item, then I am jumped down the screen without the section expanding. Therefore, it would be preferable if there was also a hashchange event that would re-render this tree whenever it fires. This will ensure that the section always reflects what is currently in the location.hash.
There was a problem hiding this comment.
I did this in 754aadd but it was surprisingly complicated to get it to work in all the scenarios (initial load of the page, changing the hash in the URL location bar, clicking the Analytics link in the menu), and I'm not sure how I feel about how much code I had to add. It's working, though.
…ithub.com/ampproject/amp-wp into feature/5190-settings-screen-anchor-links
assets/src/settings-page/index.js
Outdated
| * | ||
| * @param {Object} props Component props. | ||
| * @param {string} props.focusedSection The initially focused focusedSection. |
There was a problem hiding this comment.
| * | |
| * @param {Object} props Component props. | |
| * @param {string} props.focusedSection The initially focused focusedSection. |
assets/src/settings-page/index.js
Outdated
| Root.propTypes = { | ||
| focusedSection: PropTypes.string, | ||
| }; |
There was a problem hiding this comment.
| Root.propTypes = { | |
| focusedSection: PropTypes.string, | |
| }; |
assets/src/settings-page/index.js
Outdated
| <h2 id="advanced-settings"> | ||
| { __( 'Advanced Settings', 'amp' ) } | ||
| </h2> | ||
| <MobileRedirection /> |
There was a problem hiding this comment.
Why not put the ID for the section here instead of inside of the component?
There was a problem hiding this comment.
Yeah, I like having all the IDs at this level. Updated in 5e7b5de
| id="supported-templates" | ||
| initialOpen={ 'supported-templates' === focusedSection } | ||
| > | ||
| <SupportedTemplates /> |
There was a problem hiding this comment.
In this case the ID is set just above on the AMPDrawer component.
| import { getPageError } from '@wordpress/e2e-test-utils'; | ||
|
|
||
| function createURLWithHash( WPPath, query = '', hash = '' ) { | ||
| const url = new URL( 'http://localhost:8890' ); |
There was a problem hiding this comment.
This URL should be available via the environment variable WP_BASE_URL, so no need to hard code it.
| * @param {string} query String to be serialized as query portion of URL. | ||
| * @param {string} hash URL hash. | ||
| */ | ||
| export async function visitAdminPageWithHash( adminPath, query, hash = null ) { |
There was a problem hiding this comment.
If defaulting hash to null is still wanted I'd recommend updating the docblock to include null, otherwise I'd recommend defaulting to an empty string:
| export async function visitAdminPageWithHash( adminPath, query, hash = null ) { | |
| export async function visitAdminPageWithHash( adminPath, query, hash = '' ) { |
Co-authored-by: Pierre Gordon <16200219+pierlon@users.noreply.github.com>
| * @param WP_Styles $wp_styles The WP_Styles instance for the current page. | ||
| */ | ||
| public function register_shimmed_styles( $wp_styles ) { | ||
| if ( version_compare( get_bloginfo( 'version' ), '5.4', '<' ) ) { |
There was a problem hiding this comment.
Unrelated change: Noticed some undesirable CSS effects when working in 5.2 locally, so this will force the polyfilled wp-components styles. Note this only runs on AMP screens.
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
|
@googlebot I consent. |
|
Some tests were modifying the global |
That's true, but it's just because the analytics section is last on the page so it can't scroll any further than that. I suppose the workarounds would be to move that section up or add a bit of extra padding to the bottom of the page. |
|
Could we focus the drawer when selected by hash? Similar to how GitHub does it, where if I link to a comment it adds a border around it: |
I'd say that would be an optional enhancement. GitHub styles this via: :target .timeline-comment {
border-color: #2188ff;
box-shadow: 0 0 0 0.2em #c8e1ff;
}However, the drawers depend on But yeah, I'd say this is not really necessary. After all, the first focusable element will have the outline. I suppose the the alternative would be remove the --- a/assets/src/settings-page/index.js
+++ b/assets/src/settings-page/index.js
@@ -105,7 +105,7 @@ function scrollFocusedSectionIntoView( focusedSectionId ) {
return;
}
- const firstInput = focusedSectionElement.querySelector( 'input, select, textarea, button:not(.components-panel__body-toggle)' );
+ const firstInput = focusedSectionElement.querySelector( 'input, select, textarea, button' );
if ( firstInput ) {
firstInput.focus(); |
|
I noticed that when going to |
|
a856c71 adds scrolling to the reader themes drawer if it's on the page (note I changed that HTML ID from Another thing, I noticed that |
Oh, I didn't even the So, good to switch to |
| } | ||
|
|
||
| #reader-themes-drawer { | ||
| #reader-themes { |
There was a problem hiding this comment.
Thanks for making this change. I was going to suggest it but I didn't want to nit pick… too much. 😊
Huh, you're right. I could've sworn I learned this was a thing recently, but I'm no longer able to find it 🤷♂️ No wonder it didn't work. |
|
For some reason deeplinking to |




Summary
Fixes #5190
In #5155 we removed the Analytics menu page and placed the analytics option on the settings screen. This restores that menu item with a link to the Analytics section of the menu page.
Additional changes:
AnalyticsOptionsSubmenuservice class, which is a stripped-down version of the class that was removed in Add Analytics option to settings screen #5155. It inserts a link into the AMP admin menu in the second position.get_menu_slugmethod in theOptionsMenuclass for consumption inAnalyticsOptionsSubmenu.Checklist