Add Analytics option to settings screen#5155
Conversation
|
Plugin builds for b5b6488 are ready 🛎️!
|
| * @param string $type Optional. Message type, controls HTML class. Possible values include 'error', | ||
| * 'success', 'warning', 'info'. Default 'error'. | ||
| */ | ||
| private static function add_settings_error( $setting, $code, $message, $type = 'error' ) { |
…analytics-to-settings-screen
| return ( | ||
| <div> | ||
|
|
||
| <details open={ ! Boolean( Object.keys( originalOptions.analytics ).length ) }> |
There was a problem hiding this comment.
| <details open={ ! Boolean( Object.keys( originalOptions.analytics ).length ) }> | |
| <details open={ detailsInitialOpen }> |
There was a problem hiding this comment.
Actually it looks like the state wasn't needed. Fixed in e5380c9
| <Button | ||
| isLink | ||
| onClick={ onDelete } | ||
| className="amp-analytics__delete-button" |
There was a problem hiding this comment.
I'd recommend making this button red instead of blue on hover.
| <div> | ||
|
|
||
| <details open={ ! Boolean( Object.keys( originalOptions.analytics ).length ) }> | ||
| <summary> |
There was a problem hiding this comment.
Cursor should be a pointer when over the summary element.
| label={ __( 'ID:', 'amp' ) } | ||
| type="text" | ||
| value={ isExistingEntry ? entryId : '' } | ||
| readOnly |
There was a problem hiding this comment.
I'd recommend adding a tooltip for this input to inform the user that the ID will be generated once the settings are saved.
There was a problem hiding this comment.
Added help text to the two inputs in 076d206
There was a problem hiding this comment.
We don't really even need the ID. It really doesn't serve any purpose as far as I can tell. I started to remove it in #4802.
Remove the unnecessary readonly ID input field from the form entries.
There was a problem hiding this comment.
Ah, thanks for pointing that out. I was staying too faithful to the source.
| label={ __( 'JSON Configuration:', 'amp' ) } | ||
| > | ||
| <textarea | ||
| rows="10" |
There was a problem hiding this comment.
The "Save Changes" button should be disabled if the JSON entered is invalid.
There was a problem hiding this comment.
I entertained this possibility, but for the fields in this section we're using built-in browser form validation, which at this point will do a better job of directing the user to the invalid fields.
I've thought about creating a validation context provider that could collect issues with the form along with their associated elements, and scroll the user to form issues when they try to submit. This would allow us to implement form validation behavior for things like the the mode selection options, which are not standard form elements. I might create an issue for that.
…ediately returning Co-authored-by: Pierre Gordon <16200219+pierlon@users.noreply.github.com>
Co-authored-by: Pierre Gordon <16200219+pierlon@users.noreply.github.com>
Co-authored-by: Pierre Gordon <16200219+pierlon@users.noreply.github.com>
…s://github.com/ampproject/amp-wp into feature/5013-move-analytics-to-settings-screen
|
|
||
| const firstInput = inputWrapper.current.querySelector( 'input' ); | ||
| if ( firstInput ) { | ||
| firstInput.focus(); |
There was a problem hiding this comment.
This does not seem to work as intended when the drawer is first opened; the last input is focused instead of the first.
There was a problem hiding this comment.
Yes, I just saw the same. While I appreciate the intention, I don't think it's necessary in this context. Removed in 877f1f8.
|
I'm amending the PR with the changes from #4802. |
|
This looks great! One nit pick: I would like to consider a better label for Testing now on local install. |
amedina
left a comment
There was a problem hiding this comment.
This is great. Addressed comment offline.
|
Perhaps we should retain the Analytics admin menu item and have it go to the settings screen with the Analytics section pre-expanded. |
Filed in #5190. |
Changes addressed in #5155 (comment)
Summary
Fixes #5013
Closes #4802
The menu page for AMP Analytics has been removed in favor of this new drawer on the AMP settings page:
The migration to the new way of handling options was straightforward, except I change how the analytics option was saved. **Previously: ** calling
AMP_Options_Manager::update_optionwith the analytics key would add the new value without removing existing values. Entries were only deleted if they were passed in with adeleteflag. **Now: ** I didn't see any reason to preserve that behavior. The React state on the settings screen receives the full array of analytics entries and passes back the modified array.There may be a few unrelated CSS changes included in this PR; while working on the mobile view of this feature I saw some other parts of the settings mobile view in need of polish.
This also addresses an issue raised in support topic where in-house analytics do not need a
typeattribute):requiredattribute from Type input field and server-side validation.typefromamp-analyticstag when Type is empty.Checklist