Skip to content

Add Analytics option to settings screen#5155

Merged
westonruter merged 38 commits intodevelopfrom
feature/5013-move-analytics-to-settings-screen
Aug 6, 2020
Merged

Add Analytics option to settings screen#5155
westonruter merged 38 commits intodevelopfrom
feature/5013-move-analytics-to-settings-screen

Conversation

@johnwatkins0
Copy link
Copy Markdown
Contributor

@johnwatkins0 johnwatkins0 commented Aug 3, 2020

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:

image

image

image

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_option with the analytics key would add the new value without removing existing values. Entries were only deleted if they were passed in with a delete flag. **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 type attribute):

  • Remove required attribute from Type input field and server-side validation.
  • Omit type from amp-analytics tag when Type is empty.
  • Remove the unnecessary readonly ID input field from the form entries.
  • Use UUID to generate unique IDs rather than hashing type and contents.
  • Stop needlessly showing ID in entry heading on admin screen, and use ordered list instead to differentiate entries.

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • 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).

@google-cla google-cla bot added the cla: yes Signed the Google CLA label Aug 3, 2020
@johnwatkins0 johnwatkins0 marked this pull request as ready for review August 3, 2020 21:58
@johnwatkins0 johnwatkins0 self-assigned this Aug 3, 2020
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 3, 2020

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' ) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (
<div>

<details open={ ! Boolean( Object.keys( originalOptions.analytics ).length ) }>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<details open={ ! Boolean( Object.keys( originalOptions.analytics ).length ) }>
<details open={ detailsInitialOpen }>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it looks like the state wasn't needed. Fixed in e5380c9

<Button
isLink
onClick={ onDelete }
className="amp-analytics__delete-button"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend making this button red instead of blue on hover.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in da8ea68

<div>

<details open={ ! Boolean( Object.keys( originalOptions.analytics ).length ) }>
<summary>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor should be a pointer when over the summary element.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e5380c9

label={ __( 'ID:', 'amp' ) }
type="text"
value={ isExistingEntry ? entryId : '' }
readOnly
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend adding a tooltip for this input to inform the user that the ID will be generated once the settings are saved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added help text to the two inputs in 076d206

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for pointing that out. I was staying too faithful to the source.

label={ __( 'JSON Configuration:', 'amp' ) }
>
<textarea
rows="10"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Save Changes" button should be disabled if the JSON entered is invalid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

johnwatkins0 and others added 7 commits August 5, 2020 08:34
…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>

const firstInput = inputWrapper.current.querySelector( 'input' );
if ( firstInput ) {
firstInput.focus();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to work as intended when the drawer is first opened; the last input is focused instead of the first.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just saw the same. While I appreciate the intention, I don't think it's necessary in this context. Removed in 877f1f8.

@westonruter
Copy link
Copy Markdown
Member

I'm amending the PR with the changes from #4802.

@amedina
Copy link
Copy Markdown
Member

amedina commented Aug 6, 2020

This looks great!

One nit pick: I would like to consider a better label for Analytics 1.

Testing now on local install.

Copy link
Copy Markdown
Member

@amedina amedina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Addressed comment offline.

@westonruter
Copy link
Copy Markdown
Member

Perhaps we should retain the Analytics admin menu item and have it go to the settings screen with the Analytics section pre-expanded.

@westonruter
Copy link
Copy Markdown
Member

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.

@westonruter westonruter merged commit d20c516 into develop Aug 6, 2020
@westonruter westonruter deleted the feature/5013-move-analytics-to-settings-screen branch August 6, 2020 17:51
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Aug 8, 2020
@johnwatkins0 johnwatkins0 added the WS:UX Work stream for UX/Front-end label Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelogged Whether the issue/PR has been added to release notes. cla: yes Signed the Google CLA WS:UX Work stream for UX/Front-end

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move Analytics Options submenu into "Advanced" section of settings page

5 participants