) }
+ disabled={ false }
+ />
+ );
+
+ expect( blocksSwitch() !== null ).toBe( shown );
+ } );
+
+ it( 'saves the blocks option on its own', async () => {
+ render( );
+ await userEvent.click( blocksSwitch()! );
+
+ expect( posts() ).toEqual( [ { enable_blocks_comments: false } ] );
+ } );
+
+ it( 'saves the introduction on blur, and only when it changed', async () => {
+ render( );
+
+ await userEvent.click( introField() );
+ await userEvent.tab();
+ expect( posts() ).toHaveLength( 0 );
+
+ await userEvent.clear( introField() );
+ await userEvent.type( introField(), 'Say hello' );
+ expect( posts() ).toHaveLength( 0 );
+ await userEvent.tab();
+
+ await waitFor( () =>
+ expect( posts() ).toEqual( [ { highlander_comment_form_prompt: 'Say hello' } ] )
+ );
+ } );
+
+ it( 'locks the introduction while it saves, and keeps the typed text when the save fails', async () => {
+ let failSave: () => void = () => undefined;
+ mockFetch.mockImplementation(
+ () =>
+ new Promise( ( _resolve, reject ) => {
+ failSave = () => reject( new Error( 'nope' ) );
+ } )
+ );
+ render( );
+
+ await userEvent.clear( introField() );
+ await userEvent.type( introField(), 'Say hello' );
+ await userEvent.tab();
+ expect( introField() ).toBeDisabled();
+
+ failSave();
+ await waitFor( () => expect( introField() ).toBeEnabled() );
+ expect( introField() ).toHaveValue( 'Say hello' );
+ } );
+
+ it.each( [
+ [ 'the module is off', { activated: false }, false ],
+ [ 'the site cannot use it', {}, true ],
+ ] )( 'locks the options when %s', ( _name, overrides, disabled ) => {
+ render( );
+
+ expect( blocksSwitch() ).toHaveAttribute( 'aria-disabled', 'true' );
+ expect( introField() ).toBeDisabled();
+ } );
+
+ it( 'locks the module switch when the site cannot use it', () => {
+ render( );
+
+ expect(
+ screen.getByRole( 'checkbox', { name: 'Use the Jetpack comment form' } )
+ ).toBeDisabled();
+ } );
+} );
diff --git a/projects/packages/my-jetpack/_inc/components/settings-panel/use-module-option.ts b/projects/packages/my-jetpack/_inc/components/settings-panel/use-module-option.ts
index c5dfde6634a2..1263b7362e58 100644
--- a/projects/packages/my-jetpack/_inc/components/settings-panel/use-module-option.ts
+++ b/projects/packages/my-jetpack/_inc/components/settings-panel/use-module-option.ts
@@ -17,7 +17,7 @@ type ModuleOptionValue = boolean | string;
* @param $module - The module that owns the option.
* @param name - The option name, such as `carousel_background_color`.
* @param parse - Turns the stored `current_value` into the value to show.
- * @return The value to show, whether a save is running, and the setter.
+ * @return The value to show, whether a save is running, and the setter, which resolves to whether the save worked.
*/
export function useModuleSetting< T extends ModuleOptionValue >(
$module: MyJetpackModule,
@@ -44,10 +44,12 @@ export function useModuleSetting< T extends ModuleOptionValue >(
createSuccessNotice( __( 'Updated settings.', 'jetpack-my-jetpack' ), {
type: 'snackbar',
} );
+ return true;
} catch {
createErrorNotice( __( 'Failed to save the setting.', 'jetpack-my-jetpack' ), {
type: 'snackbar',
} );
+ return false;
} finally {
setRequested( null );
}
diff --git a/projects/packages/my-jetpack/changelog/change-settings-comments-panel b/projects/packages/my-jetpack/changelog/change-settings-comments-panel
new file mode 100644
index 000000000000..32ab11f6d7b0
--- /dev/null
+++ b/projects/packages/my-jetpack/changelog/change-settings-comments-panel
@@ -0,0 +1,5 @@
+Significance: patch
+Type: changed
+Comment: Settings panel: Add the Comments settings, behind the settings consolidation flag.
+
+
diff --git a/projects/packages/my-jetpack/src/class-initializer.php b/projects/packages/my-jetpack/src/class-initializer.php
index 2d726b8b241b..2046cc1fba75 100644
--- a/projects/packages/my-jetpack/src/class-initializer.php
+++ b/projects/packages/my-jetpack/src/class-initializer.php
@@ -155,7 +155,7 @@ class Initializer {
/**
* Modules whose Jetpack settings link opens in the Features panel. A subset of `moduleSettings` in `settings-panel/registry.ts`; see there for which modules stay out.
*/
- public const SETTINGS_PANEL_MODULES = array( 'carousel', 'infinite-scroll', 'markdown', 'post-by-email', 'related-posts' );
+ public const SETTINGS_PANEL_MODULES = array( 'carousel', 'comments', 'infinite-scroll', 'markdown', 'post-by-email', 'related-posts' );
/**
* Holds info/data about the site (from the /sites/%d endpoint)
diff --git a/projects/plugins/jetpack/_inc/client/components/settings-nav-tabs/index.jsx b/projects/plugins/jetpack/_inc/client/components/settings-nav-tabs/index.jsx
index 6dd249ae3984..3d12196e6c74 100644
--- a/projects/plugins/jetpack/_inc/client/components/settings-nav-tabs/index.jsx
+++ b/projects/plugins/jetpack/_inc/client/components/settings-nav-tabs/index.jsx
@@ -123,7 +123,11 @@ const SettingsNavTabs = props => {
) {
visibleTabs.push( '/sharing' );
}
- if ( hasModules( [ 'comments', 'gravatar-hovercards', 'markdown' ] ) ) {
+ // Once settings move out, admins find every Discussion setting in Features.
+ if (
+ ! isSettingsConsolidationEnabled() &&
+ hasModules( [ 'comments', 'gravatar-hovercards', 'markdown' ] )
+ ) {
visibleTabs.push( '/discussion' );
}
if (
diff --git a/projects/plugins/jetpack/_inc/client/components/settings-nav-tabs/test/component.jsx b/projects/plugins/jetpack/_inc/client/components/settings-nav-tabs/test/component.jsx
index 7b0afc4d66e8..a777887a02cc 100644
--- a/projects/plugins/jetpack/_inc/client/components/settings-nav-tabs/test/component.jsx
+++ b/projects/plugins/jetpack/_inc/client/components/settings-nav-tabs/test/component.jsx
@@ -101,6 +101,9 @@ describe( 'SettingsNavTabs', () => {
[ 'hides', 'Writing', 'Infinite Scroll', 'infinite-scroll', true, 0 ],
[ 'shows', 'Writing', 'custom content types', null, false, 1 ],
[ 'hides', 'Writing', 'custom content types', null, true, 0 ],
+ [ 'shows', 'Discussion', 'Comments', 'comments', false, 1 ],
+ [ 'hides', 'Discussion', 'Comments', 'comments', true, 0 ],
+ [ 'hides', 'Discussion', 'Gravatar Hovercards', 'gravatar-hovercards', true, 0 ],
[ 'shows', 'Reader', 'the Reader', 'wpcom-reader', false, 1 ],
[ 'hides', 'Reader', 'the Reader', 'wpcom-reader', true, 0 ],
] )(
diff --git a/projects/plugins/jetpack/_inc/client/discussion/comments-moved.jsx b/projects/plugins/jetpack/_inc/client/discussion/comments-moved.jsx
new file mode 100644
index 000000000000..172196897e1d
--- /dev/null
+++ b/projects/plugins/jetpack/_inc/client/discussion/comments-moved.jsx
@@ -0,0 +1,19 @@
+import { __ } from '@wordpress/i18n';
+import PointerCard from 'components/pointer-card';
+
+/**
+ * Search result that sends the Comments settings to the panel in Features.
+ *
+ * @param {object} props - Component props.
+ * @param {Function} props.getModule - Reads a module by slug.
+ * @return {import('react').ReactNode} The card.
+ */
+export const CommentsMoved = ( { getModule } ) => (
+
+ { __( 'The Comments settings are now in Features, in My Jetpack.', 'jetpack' ) }
+
+);
diff --git a/projects/plugins/jetpack/_inc/client/discussion/index.jsx b/projects/plugins/jetpack/_inc/client/discussion/index.jsx
index e4b6eab67867..60c761e00fd8 100644
--- a/projects/plugins/jetpack/_inc/client/discussion/index.jsx
+++ b/projects/plugins/jetpack/_inc/client/discussion/index.jsx
@@ -2,7 +2,8 @@ import { __ } from '@wordpress/i18n';
import { Component } from 'react';
import { connect } from 'react-redux';
import QuerySite from 'components/data/query-site';
-import { isSettingsConsolidationEnabled } from 'lib/settings-consolidation';
+import { FeaturesPointer } from 'components/pointer-card';
+import { isInSettingsPanel } from 'lib/settings-consolidation';
import {
isOfflineMode,
isUnavailableInOfflineMode,
@@ -13,12 +14,12 @@ import {
isOdysseyStatsEnabled,
getSiteAdminUrl,
isCommentBlocksAvailable,
- userCanManageModules,
} from 'state/initial-state';
import { getModule, getModuleOverride } from 'state/modules';
import { isModuleFound as _isModuleFound } from 'state/search';
import { getSettings } from 'state/settings';
import { Comments } from './comments';
+import { CommentsMoved } from './comments-moved';
export class Discussion extends Component {
static displayName = 'DiscussionSettings';
@@ -37,28 +38,49 @@ export class Discussion extends Component {
return null;
}
- const foundComments = this.props.isModuleFound( 'comments' ),
+ const { isMovedToFeatures, searchTerm } = this.props,
+ foundComments = this.props.isModuleFound( 'comments' ),
foundMarkdown = this.props.isModuleFound( 'markdown' ),
foundGravatar = this.props.isModuleFound( 'gravatar-hovercards' ),
foundCommentLikes = this.props.isModuleFound( 'comment-likes' );
- if ( ! foundComments && ! foundMarkdown && ! foundGravatar && ! foundCommentLikes ) {
+ // Once settings move out, admins find this tab's settings in Features, and only a search points there.
+ // Markdown's pointer is on the Writing tab.
+ const shown = isMovedToFeatures
+ ? !! searchTerm && ( foundComments || foundGravatar || foundCommentLikes )
+ : foundComments || foundMarkdown || foundGravatar || foundCommentLikes;
+ if ( ! shown ) {
return null;
}
+ const pointTo = module => {
+ const { name } = this.props.module( module );
+ return (
+
+ );
+ };
+
return (
{ __( 'Jetpack Discussion Settings', 'jetpack' ) }
- { this.props.searchTerm && (
+ { searchTerm && (
{ __( 'Discussion', 'jetpack' ) }
) }
-
+ { isMovedToFeatures ? (
+ <>
+ { foundComments && }
+ { foundGravatar && pointTo( 'gravatar-hovercards' ) }
+ { foundCommentLikes && pointTo( 'comment-likes' ) }
+ >
+ ) : (
+
+ ) }
);
}
@@ -70,13 +92,8 @@ export default connect( state => {
settings: getSettings( state ),
isOfflineMode: isOfflineMode( state ),
isUnavailableInOfflineMode: module_name => isUnavailableInOfflineMode( state, module_name ),
- // Markdown's settings live in its My Jetpack panel, as in the Writing tab.
- isModuleFound: module_name =>
- ! (
- 'markdown' === module_name &&
- isSettingsConsolidationEnabled() &&
- userCanManageModules( state )
- ) && _isModuleFound( state, module_name ),
+ isModuleFound: module_name => _isModuleFound( state, module_name ),
+ isMovedToFeatures: isInSettingsPanel( state ),
connectUrl: getConnectUrl( state ),
isLinked: isCurrentUserLinked( state ),
getModuleOverride: module_name => getModuleOverride( state, module_name ),
diff --git a/projects/plugins/jetpack/_inc/client/discussion/test/discussion.test.jsx b/projects/plugins/jetpack/_inc/client/discussion/test/discussion.test.jsx
new file mode 100644
index 000000000000..77e63895fd24
--- /dev/null
+++ b/projects/plugins/jetpack/_inc/client/discussion/test/discussion.test.jsx
@@ -0,0 +1,86 @@
+import { render, screen } from 'test/test-utils';
+import Discussion from '../index';
+
+jest.mock( 'components/data/query-site', () => () => null );
+jest.mock( '../comments', () => ( { Comments: () => Comments card
} ) );
+jest.mock( '../comments-moved', () => ( { CommentsMoved: () => Comments pointer
} ) );
+jest.mock( 'components/pointer-card', () => ( {
+ FeaturesPointer: ( { search } ) => { `Features pointer: ${ search }` }
,
+} ) );
+
+const MODULES = {
+ comments: { module: 'comments', name: 'Comments' },
+ 'gravatar-hovercards': { module: 'gravatar-hovercards', name: 'Gravatar Hovercards' },
+ 'comment-likes': { module: 'comment-likes', name: 'Comment Likes' },
+ markdown: { module: 'markdown', name: 'Markdown' },
+};
+
+const renderDiscussion = ( { flag, searchTerm = '', canManageModules = true } ) => {
+ window.JetpackScriptData = { myJetpack: { settingsConsolidation: flag } };
+ return render( , {
+ initialState: {
+ jetpack: {
+ connection: {
+ status: { siteConnected: { isActive: true, offlineMode: { isActive: false } } },
+ user: { currentUser: { isConnected: true } },
+ },
+ initialState: {
+ siteData: {},
+ userData: { currentUser: { permissions: { manage_modules: canManageModules } } },
+ },
+ modules: { items: MODULES },
+ search: { searchTerm },
+ settings: { items: {} },
+ },
+ },
+ } );
+};
+
+describe( 'Discussion settings', () => {
+ afterEach( () => {
+ delete window.JetpackScriptData;
+ } );
+
+ it.each( [
+ [ 'the card on the tab with the settings flag off', false, '', true, [ 'Comments card' ] ],
+ [ 'nothing on the tab once the flag is on', true, '', true, [] ],
+ [ 'the panel pointer for a Comments search', true, 'comments', true, [ 'Comments pointer' ] ],
+ [
+ 'the Features row for a Gravatar search',
+ true,
+ 'gravatar',
+ true,
+ [ 'Features pointer: Gravatar Hovercards' ],
+ ],
+ [
+ 'the Features row for a Comment Likes search',
+ true,
+ 'comment likes',
+ true,
+ [ 'Features pointer: Comment Likes' ],
+ ],
+ [
+ 'the card to a user who cannot manage modules',
+ true,
+ 'comments',
+ false,
+ [ 'Comments card' ],
+ ],
+ ] )( 'shows %s', ( _name, flag, searchTerm, canManageModules, expected ) => {
+ renderDiscussion( { flag, searchTerm, canManageModules } );
+
+ const shown = [
+ 'Comments card',
+ 'Comments pointer',
+ 'Features pointer: Gravatar Hovercards',
+ 'Features pointer: Comment Likes',
+ ].filter( text => screen.queryByText( text ) );
+ expect( shown ).toEqual( expected );
+ } );
+
+ it( 'renders nothing for a Markdown search once the flag is on, since Writing points to it', () => {
+ const { container } = renderDiscussion( { flag: true, searchTerm: 'markdown' } );
+
+ expect( container ).toBeEmptyDOMElement();
+ } );
+} );
diff --git a/projects/plugins/jetpack/_inc/client/lib/settings-consolidation/index.js b/projects/plugins/jetpack/_inc/client/lib/settings-consolidation/index.js
index c326a400465e..6cb043492011 100644
--- a/projects/plugins/jetpack/_inc/client/lib/settings-consolidation/index.js
+++ b/projects/plugins/jetpack/_inc/client/lib/settings-consolidation/index.js
@@ -58,6 +58,17 @@ export function getMovedOutModules( state ) {
*/
export const isMovedOut = ( module, state ) => getMovedOutModules( state ).includes( module );
+/**
+ * Whether settings that moved to a My Jetpack settings panel leave only a pointer here.
+ *
+ * The panel lives in Features, which needs manage_options, so users who cannot manage modules keep the card.
+ *
+ * @param {object} state - Global state tree.
+ * @return {boolean} True when the card gives way to a pointer.
+ */
+export const isInSettingsPanel = state =>
+ isSettingsConsolidationEnabled() && userCanManageModules( state );
+
/**
* Whether a module's Settings toggle gives way to its switch in My Jetpack › Features, leaving only a search result that points there.
*
diff --git a/projects/plugins/jetpack/_inc/client/lib/settings-consolidation/test/index.js b/projects/plugins/jetpack/_inc/client/lib/settings-consolidation/test/index.js
index 33b65ebe26cb..4fc2ca75b787 100644
--- a/projects/plugins/jetpack/_inc/client/lib/settings-consolidation/test/index.js
+++ b/projects/plugins/jetpack/_inc/client/lib/settings-consolidation/test/index.js
@@ -1,10 +1,15 @@
import { getScriptData, isWoASite } from '@automattic/jetpack-script-data';
-import { getMovedOutModules, isSettingsConsolidationEnabled } from '../index';
+import { userCanManageModules } from 'state/initial-state';
+import { getMovedOutModules, isInSettingsPanel, isSettingsConsolidationEnabled } from '../index';
jest.mock( '@automattic/jetpack-script-data', () => ( {
getScriptData: jest.fn(),
isWoASite: jest.fn(),
} ) );
+jest.mock( 'state/initial-state', () => ( {
+ ...jest.requireActual( 'state/initial-state' ),
+ userCanManageModules: jest.fn(),
+} ) );
describe( 'isSettingsConsolidationEnabled', () => {
it.each( [
@@ -30,3 +35,16 @@ describe( 'getMovedOutModules', () => {
expect( getMovedOutModules() ).toEqual( expected );
} );
} );
+
+describe( 'isInSettingsPanel', () => {
+ it.each( [
+ [ 'moves', 'admins with the flag on', true, true, true ],
+ [ 'keeps', 'users who cannot manage modules', true, false, false ],
+ [ 'keeps', 'admins with the flag off', false, true, false ],
+ ] )( '%s the card for %s', ( _verb, _who, flag, canManage, expected ) => {
+ getScriptData.mockReturnValue( { myJetpack: { settingsConsolidation: flag } } );
+ userCanManageModules.mockReturnValue( canManage );
+
+ expect( isInSettingsPanel( {} ) ).toBe( expected );
+ } );
+} );
diff --git a/projects/plugins/jetpack/_inc/client/main.jsx b/projects/plugins/jetpack/_inc/client/main.jsx
index 2a0ea075c45b..c8418cc6bdf5 100644
--- a/projects/plugins/jetpack/_inc/client/main.jsx
+++ b/projects/plugins/jetpack/_inc/client/main.jsx
@@ -291,8 +291,15 @@ export class Main extends Component {
break;
}
// Falls through.
- case '/settings':
case '/discussion':
+ if ( '/discussion' === route && isSettingsConsolidationEnabled() ) {
+ window.location.replace(
+ getAdminUrl( 'admin.php?page=my-jetpack&p=%2Ffeatures%3Fconfigure%3Dcomments' )
+ );
+ break;
+ }
+ // Falls through.
+ case '/settings':
case '/traffic':
case '/privacy':
pageComponent = (
diff --git a/projects/plugins/jetpack/_inc/client/test/security-route.test.jsx b/projects/plugins/jetpack/_inc/client/test/security-route.test.jsx
index bf175d0078cd..a5b950b5872b 100644
--- a/projects/plugins/jetpack/_inc/client/test/security-route.test.jsx
+++ b/projects/plugins/jetpack/_inc/client/test/security-route.test.jsx
@@ -79,6 +79,7 @@ describe( 'Main routes that leave Settings once settings move out', () => {
[ '/sharing', 'admin.php?page=my-jetpack#/features?search=sharing' ],
[ '/reader', 'admin.php?page=my-jetpack#/features?search=reader' ],
[ '/writing', 'admin.php?page=my-jetpack#/features' ],
+ [ '/discussion', 'admin.php?page=my-jetpack&p=%2Ffeatures%3Fconfigure%3Dcomments' ],
] )( 'sends %s to %s with the settings flag on', ( route, destination ) => {
isSettingsConsolidationEnabled.mockReturnValue( true );
renderAt( route, false );
@@ -88,7 +89,7 @@ describe( 'Main routes that leave Settings once settings move out', () => {
expect( screen.queryByTestId( 'searchable-settings' ) ).not.toBeInTheDocument();
} );
- it.each( [ '/performance', '/sharing', '/reader', '/writing' ] )(
+ it.each( [ '/performance', '/sharing', '/reader', '/writing', '/discussion' ] )(
'keeps %s on Settings with the settings flag off',
route => {
renderAt( route, false );
diff --git a/projects/plugins/jetpack/_inc/client/writing/composing.jsx b/projects/plugins/jetpack/_inc/client/writing/composing.jsx
index 6af51f13f479..3ad4118bea5f 100644
--- a/projects/plugins/jetpack/_inc/client/writing/composing.jsx
+++ b/projects/plugins/jetpack/_inc/client/writing/composing.jsx
@@ -12,10 +12,10 @@ import { FeaturesPointer } from 'components/pointer-card';
import SettingsCard from 'components/settings-card';
import SettingsGroup from 'components/settings-group';
import {
- isSettingsConsolidationEnabled,
+ isInSettingsPanel,
isSwitchedInFeatures as _isSwitchedInFeatures,
} from 'lib/settings-consolidation';
-import { showMyJetpack, userCanManageModules } from 'state/initial-state';
+import { showMyJetpack } from 'state/initial-state';
import { getModule } from 'state/modules';
import { isModuleFound as _isModuleFound, getSearchTerm } from 'state/search';
import { MarkdownMoved } from './markdown-moved';
@@ -278,8 +278,7 @@ export default connect( state => {
module: module_name => getModule( state, module_name ),
isModuleFound: module_name => _isModuleFound( state, module_name ),
isSwitchedInFeatures: module_name => _isSwitchedInFeatures( state, module_name ),
- // The panel needs Features, which users who cannot manage modules lack.
- isMarkdownMoved: isSettingsConsolidationEnabled() && userCanManageModules( state ),
+ isMarkdownMoved: isInSettingsPanel( state ),
isMyJetpackReachable: showMyJetpack( state ),
searchTerm: getSearchTerm( state ),
};
diff --git a/projects/plugins/jetpack/_inc/client/writing/index.jsx b/projects/plugins/jetpack/_inc/client/writing/index.jsx
index 65af747e1e92..14963b4d9cc9 100644
--- a/projects/plugins/jetpack/_inc/client/writing/index.jsx
+++ b/projects/plugins/jetpack/_inc/client/writing/index.jsx
@@ -4,6 +4,7 @@ import { connect } from 'react-redux';
import Card from 'components/card';
import QuerySite from 'components/data/query-site';
import {
+ isInSettingsPanel,
isMovedOut,
isSettingsConsolidationEnabled,
isSwitchedInFeatures,
@@ -172,7 +173,7 @@ export class Writing extends Component {
{ this.props.isModuleFound( 'post-by-email' ) &&
showPostByEmail &&
- ( isSettingsConsolidationEnabled() && this.props.userCanManageModules ? (
+ ( this.props.isPostByEmailMoved ? (
this.props.searchTerm &&
) : (
isModuleActivated( state, module_name ),
isLinked: isCurrentUserLinked( state ),
userCanManageModules: userCanManageModules( state ),
+ isPostByEmailMoved: isInSettingsPanel( state ),
isModuleFound: module_name =>
isModuleFound( state, module_name ) &&
! isMovedOut( module_name, state ) &&
diff --git a/projects/plugins/jetpack/_inc/client/writing/test/writing.test.jsx b/projects/plugins/jetpack/_inc/client/writing/test/writing.test.jsx
index 28ec98309774..709685a2d4c4 100644
--- a/projects/plugins/jetpack/_inc/client/writing/test/writing.test.jsx
+++ b/projects/plugins/jetpack/_inc/client/writing/test/writing.test.jsx
@@ -159,6 +159,7 @@ describe( 'Writing settings', () => {