From b500c7f928e32e50511a489378d105a329388802 Mon Sep 17 00:00:00 2001 From: Dylan Munson <65001528+CodeyGuyDylan@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:53:40 -0600 Subject: [PATCH 1/4] Unify connection notices on At A Glance --- .../_inc/client/at-a-glance/connections.jsx | 10 +--- .../_inc/client/at-a-glance/monitor.jsx | 34 ++++++----- .../_inc/client/at-a-glance/style.scss | 34 +++++++++++ .../_inc/client/at-a-glance/test/component.js | 6 +- .../components/connect-button/index.jsx | 60 +++++++++---------- .../connect-button/test/component.js | 58 ++++++++---------- .../connect-button/test/fixtures.js | 27 +++++++++ 7 files changed, 137 insertions(+), 92 deletions(-) create mode 100644 projects/plugins/jetpack/_inc/client/components/connect-button/test/fixtures.js diff --git a/projects/plugins/jetpack/_inc/client/at-a-glance/connections.jsx b/projects/plugins/jetpack/_inc/client/at-a-glance/connections.jsx index 812d536a8e5d..c669d86b5e5a 100644 --- a/projects/plugins/jetpack/_inc/client/at-a-glance/connections.jsx +++ b/projects/plugins/jetpack/_inc/client/at-a-glance/connections.jsx @@ -71,7 +71,6 @@ export class DashConnections extends Component { ) }
- { __( 'Your site is connected to WordPress.com.', 'jetpack' ) } { this.props.isConnectionOwner && ( { __( 'You are the Jetpack owner.', 'jetpack' ) } @@ -131,14 +130,7 @@ export class DashConnections extends Component { } if ( ! this.props.isLinked ) { - cardContent = ( -
-
- { __( 'Get the most out of Jetpack.', 'jetpack' ) } -
-
{ maybeShowLinkUnlinkBtn }
-
- ); + cardContent =
{ maybeShowLinkUnlinkBtn }
; } else if ( this.props.isFetchingUserData ) { cardContent = __( 'Loading…', 'jetpack' ); } else if ( ! this.props.wpComConnectedUser?.email ) { diff --git a/projects/plugins/jetpack/_inc/client/at-a-glance/monitor.jsx b/projects/plugins/jetpack/_inc/client/at-a-glance/monitor.jsx index 077da4c240e1..fbb2b5a1e08f 100644 --- a/projects/plugins/jetpack/_inc/client/at-a-glance/monitor.jsx +++ b/projects/plugins/jetpack/_inc/client/at-a-glance/monitor.jsx @@ -3,9 +3,10 @@ import { createInterpolateElement } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import Button from 'components/button'; import DashItem from 'components/dash-item'; +import JetpackBanner from 'components/jetpack-banner'; import analytics from 'lib/analytics'; import PropTypes from 'prop-types'; -import React, { Component } from 'react'; +import { Component } from 'react'; import { connect } from 'react-redux'; import { isOfflineMode, hasConnectedOwner, connectUser } from 'state/connection'; import { isModuleAvailable } from 'state/modules'; @@ -78,26 +79,29 @@ class DashMonitor extends Component { support={ support } className="jp-dash-item__is-inactive" noToggle={ ! this.props.hasConnectedOwner } + overrideContent={ + ( ! this.props.hasConnectedOwner && ! this.props.isOfflineMode && ( + + ) ) || + null + } >

{ this.props.isOfflineMode ? __( 'Unavailable in Offline Mode.', 'jetpack' ) : activateMessage }

- - { ! this.props.isOfflineMode && ! this.props.hasConnectedOwner && ( -

- { createInterpolateElement( - __( - ' account to use this feature.', - 'jetpack' - ), - { - Button: + return ( + ); }; @@ -162,15 +160,15 @@ export class ConnectButton extends React.Component { if ( this.props.isSiteConnected ) { return ( - - { this.props.connectLegend || __( 'Manage site connection', 'jetpack' ) } - + eventFeature="manage-site-connection" + path="dashboard" + eventProps={ { type: 'manage' } } + /> ); } diff --git a/projects/plugins/jetpack/_inc/client/components/connect-button/test/component.js b/projects/plugins/jetpack/_inc/client/components/connect-button/test/component.js index 63fa59414fbc..04f6eb067d0c 100644 --- a/projects/plugins/jetpack/_inc/client/components/connect-button/test/component.js +++ b/projects/plugins/jetpack/_inc/client/components/connect-button/test/component.js @@ -1,8 +1,8 @@ import { jest } from '@jest/globals'; import userEvent from '@testing-library/user-event'; -import React from 'react'; import { render, screen } from 'test/test-utils'; import { ConnectButton } from '../index'; +import { buildInitialState } from './fixtures'; // Mock components that do fetches in the background. We supply needed state directly. jest.mock( 'components/data/query-site-benefits', () => ( { @@ -29,26 +29,10 @@ describe( 'ConnectButton', () => { describe( 'Initially', () => { it( 'renders a button to connect or link', () => { - render( ); - expect( - screen.getByRole( 'link', { name: 'Connect your WordPress.com account' } ) - ).toBeInTheDocument(); - } ); - - it( 'disables the button while fetching the connect URL', () => { - render( ); - expect( screen.getByRole( 'link', { name: 'Connect your WordPress.com account' } ) ) - // eslint-disable-next-line jest-dom/prefer-enabled-disabled -- `.toBeDisabled()` doesn't work on links. - .toHaveAttribute( 'disabled' ); - } ); - } ); - - describe( 'When it is used to link a user', () => { - it( 'has a link to jetpack.wordpress.com', () => { - render( ); - expect( - screen.getByRole( 'link', { name: 'Connect your WordPress.com account' } ) - ).toHaveAttribute( 'href', 'https://jetpack.wordpress.com/jetpack.authorize/1/' ); + render( , { + initialState: buildInitialState(), + } ); + expect( screen.getByRole( 'button', { name: 'Connect' } ) ).toBeInTheDocument(); } ); } ); @@ -62,15 +46,15 @@ describe( 'ConnectButton', () => { }; it( 'has a link to jetpack.wordpress.com', () => { - render( ); - expect( - screen.getByRole( 'link', { name: 'Link your account to WordPress.com' } ) - ).toHaveAttribute( 'href', 'https://jetpack.wordpress.com/jetpack.authorize/1/' ); + render( , { + initialState: buildInitialState(), + } ); + expect( screen.getByRole( 'button', { name: 'Connect' } ) ).toBeInTheDocument(); } ); it( 'when clicked, loadConnectionScreen() is called once', async () => { const user = userEvent.setup(); - const loadConnectionScreen = jest.fn( e => e.preventDefault() ); + const loadConnectionScreen = jest.fn(); class ConnectButtonMock extends ConnectButton { constructor( props ) { @@ -79,10 +63,10 @@ describe( 'ConnectButton', () => { } } - render( ); - await user.click( - screen.getByRole( 'link', { name: 'Link your account to WordPress.com' } ) - ); + render( , { + initialState: buildInitialState(), + } ); + await user.click( screen.getByRole( 'button', { name: 'Connect' } ) ); expect( loadConnectionScreen ).toHaveBeenCalledTimes( 1 ); } ); } ); @@ -96,7 +80,9 @@ describe( 'ConnectButton', () => { }; it( 'does not link to a URL', () => { - render( ); + render( , { + initialState: buildInitialState(), + } ); expect( screen.getByRole( 'button', { name: 'Unlink your account from WordPress.com' } ) ).not.toHaveAttribute( 'href' ); @@ -152,7 +138,9 @@ describe( 'ConnectButton', () => { }; it( 'does not link to a URL', () => { - render( ); + render( , { + initialState: buildInitialState(), + } ); expect( screen.getByRole( 'button', { name: 'Disconnect your site from WordPress.com' } ) ).not.toHaveAttribute( 'href' ); @@ -160,7 +148,7 @@ describe( 'ConnectButton', () => { it( 'when clicked, handleOpenModal() is called once', async () => { const user = userEvent.setup(); - const handleOpenModal = jest.fn( e => e.preventDefault() ); + const handleOpenModal = jest.fn(); class ConnectButtonMock extends ConnectButton { constructor( props ) { @@ -169,7 +157,9 @@ describe( 'ConnectButton', () => { } } - render( ); + render( , { + initialState: buildInitialState(), + } ); await user.click( screen.getByRole( 'button', { name: 'Disconnect your site from WordPress.com' } ) ); diff --git a/projects/plugins/jetpack/_inc/client/components/connect-button/test/fixtures.js b/projects/plugins/jetpack/_inc/client/components/connect-button/test/fixtures.js new file mode 100644 index 000000000000..2ffddcfba369 --- /dev/null +++ b/projects/plugins/jetpack/_inc/client/components/connect-button/test/fixtures.js @@ -0,0 +1,27 @@ +/** + * Build an object that can be used as a Redux store initial state. + * + * @return {object} – initial Redux state + */ +export function buildInitialState() { + return { + jetpack: { + initialState: { + userData: { + currentUser: { + permissions: { + manage_modules: true, + }, + }, + }, + }, + connection: { + user: { + currentUser: { + isConnected: true, + }, + }, + }, + }, + }; +} From f7d96d5daecf8767a9fc9fbe2331a35247640b84 Mon Sep 17 00:00:00 2001 From: Dylan Munson <65001528+CodeyGuyDylan@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:54:30 -0600 Subject: [PATCH 2/4] changelog --- .../changelog/update-at-a-glance-unify-connection-ctas | 4 ++++ tools/e2e-commons/pages/wp-admin/jetpack-dashboard.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 projects/plugins/jetpack/changelog/update-at-a-glance-unify-connection-ctas diff --git a/projects/plugins/jetpack/changelog/update-at-a-glance-unify-connection-ctas b/projects/plugins/jetpack/changelog/update-at-a-glance-unify-connection-ctas new file mode 100644 index 000000000000..af2f73b816a2 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-at-a-glance-unify-connection-ctas @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Unify connection related CTAs on At A Glance diff --git a/tools/e2e-commons/pages/wp-admin/jetpack-dashboard.js b/tools/e2e-commons/pages/wp-admin/jetpack-dashboard.js index e5be2e4f82e6..41df6fe5c5db 100644 --- a/tools/e2e-commons/pages/wp-admin/jetpack-dashboard.js +++ b/tools/e2e-commons/pages/wp-admin/jetpack-dashboard.js @@ -49,7 +49,7 @@ export default class JetpackDashboardPage extends WpPage { logger.step( 'Checking that WordPress.com user is not connected' ); const selector = `${ this.#connectionInfoContainerSel } >> nth=1`; return ( await this.page.locator( selector ).innerText() ).includes( - 'Get the most out of Jetpack' + 'Get the most out of Jetpack by connecting your WordPress.com account' ); } } From 374b04ec7020b0ef7dbc0172cfe95dd9e568a981 Mon Sep 17 00:00:00 2001 From: Dylan Munson <65001528+CodeyGuyDylan@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:12:46 -0600 Subject: [PATCH 3/4] Fix nudges on settings page --- .../_inc/client/at-a-glance/connections.jsx | 2 +- .../components/connect-button/index.jsx | 52 ++++++++++++++----- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/projects/plugins/jetpack/_inc/client/at-a-glance/connections.jsx b/projects/plugins/jetpack/_inc/client/at-a-glance/connections.jsx index c669d86b5e5a..75b497f5429f 100644 --- a/projects/plugins/jetpack/_inc/client/at-a-glance/connections.jsx +++ b/projects/plugins/jetpack/_inc/client/at-a-glance/connections.jsx @@ -99,7 +99,7 @@ export class DashConnections extends Component { */ userConnection() { const maybeShowLinkUnlinkBtn = this.props.isConnectionOwner ? null : ( - + ); let cardContent = ''; diff --git a/projects/plugins/jetpack/_inc/client/components/connect-button/index.jsx b/projects/plugins/jetpack/_inc/client/components/connect-button/index.jsx index f2aaef8b337f..858e6a48ffca 100644 --- a/projects/plugins/jetpack/_inc/client/components/connect-button/index.jsx +++ b/projects/plugins/jetpack/_inc/client/components/connect-button/index.jsx @@ -48,6 +48,7 @@ export class ConnectButton extends React.Component { connectUser: PropTypes.bool, from: PropTypes.string, asLink: PropTypes.bool, + asBanner: PropTypes.bool, connectLegend: PropTypes.string, connectInPlace: PropTypes.bool, customConnect: PropTypes.func, @@ -137,19 +138,44 @@ export class ConnectButton extends React.Component { ); } - return ( - + if ( this.props.asBanner ) { + return ( + + ); + } + + let connectUrl = this.props.connectUrl; + if ( this.props.from ) { + connectUrl += `&from=${ this.props.from }`; + connectUrl += '&additional-user'; + } + + const buttonProps = { + className: 'is-primary jp-jetpack-connect__button', + href: connectUrl, + disabled: this.props.fetchingConnectUrl || this.props.isAuthorizing, + onClick: this.loadConnectionScreen, + }, + connectLegend = + this.props.connectLegend || __( 'Connect your WordPress.com account', 'jetpack' ); + + return this.props.asLink ? ( + { connectLegend } + ) : ( + ); }; From 4529a6e029a1e69f6ed4247d243ac2e538465d32 Mon Sep 17 00:00:00 2001 From: Dylan Munson <65001528+CodeyGuyDylan@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:43:58 -0600 Subject: [PATCH 4/4] Fix tests --- .../_inc/client/components/connect-button/test/component.js | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/plugins/jetpack/_inc/client/components/connect-button/test/component.js b/projects/plugins/jetpack/_inc/client/components/connect-button/test/component.js index 04f6eb067d0c..5a04f1824765 100644 --- a/projects/plugins/jetpack/_inc/client/components/connect-button/test/component.js +++ b/projects/plugins/jetpack/_inc/client/components/connect-button/test/component.js @@ -25,6 +25,7 @@ describe( 'ConnectButton', () => { asLink: false, connectInPlace: false, doNotUseConnectionIframe: false, + asBanner: true, }; describe( 'Initially', () => {