From 446a51794e534e52e97c0b194e404b1662874c2c Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Mon, 19 Oct 2026 18:04:02 +0200 Subject: [PATCH 1/9] Sharing & Likes: Replace "Open Site Editor" with template placement cards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes CM-976 On block themes with the legacy buttons off, the Sharing buttons and Like buttons sections only offered a link to the Site Editor, leaving owners to find the right template and the right spot in it. CM-972 and CM-975 can now place each block before or after the content of single posts and pages, so the sections offer that as two cards. Core cannot hook one block on both sides of the content, and the route refuses a list with both, so the cards are an either/or: each change sends the whole list, ticking one card replaces the other, and unticking the ticked one empties it. Saves go through useSaveSetting(), so a refused save rolls the cards back. "Preview and edit" only shows on a card the last save that went through has ticked, since the template has no block before then. The optimistic value is in the cache, so the saved one comes from the oldest pending save's previous value. "Switch to the … block" sets the new status before settings are read again, so the variant briefly lacks the placement key. The cards show disabled while a write or a settings read is in flight, and the old button only stays for a server that does not offer the key. --- .../add-sharing-likes-placement-cards | 4 + .../components/feature-variant.tsx | 22 +- .../components/placement-illustrations.tsx | 166 +++++++++++++ .../components/template-placements.tsx | 158 ++++++++++++ .../sharing-likes/src/settings-app/style.scss | 24 ++ .../test/feature-variant.test.tsx | 26 +- .../test/template-placements.test.tsx | 224 ++++++++++++++++++ 7 files changed, 614 insertions(+), 10 deletions(-) create mode 100644 projects/packages/sharing-likes/changelog/add-sharing-likes-placement-cards create mode 100644 projects/packages/sharing-likes/src/settings-app/components/placement-illustrations.tsx create mode 100644 projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx create mode 100644 projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx diff --git a/projects/packages/sharing-likes/changelog/add-sharing-likes-placement-cards b/projects/packages/sharing-likes/changelog/add-sharing-likes-placement-cards new file mode 100644 index 000000000000..e265fd958f90 --- /dev/null +++ b/projects/packages/sharing-likes/changelog/add-sharing-likes-placement-cards @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Settings: Add cards that place the Sharing Buttons and Like blocks before or after the content of posts and pages. diff --git a/projects/packages/sharing-likes/src/settings-app/components/feature-variant.tsx b/projects/packages/sharing-likes/src/settings-app/components/feature-variant.tsx index 7ca67c79e0d0..1a530c58136d 100644 --- a/projects/packages/sharing-likes/src/settings-app/components/feature-variant.tsx +++ b/projects/packages/sharing-likes/src/settings-app/components/feature-variant.tsx @@ -4,6 +4,7 @@ import { Button, ButtonLink, Notice, Stack, Text } from '@wordpress/ui'; import { useStatus } from '../data/queries'; import { useFeatureAction } from '../data/use-feature-action'; import { SECTION_GAP, SettingGroup } from './section-card'; +import { TemplatePlacements } from './template-placements'; import type { Feature, SectionState } from '../types'; import type { JSX, ReactNode } from 'react'; @@ -91,14 +92,19 @@ export function FeatureVariant( { switch ( state ) { case 'block_call_to_action': content = ( - - }>{ copy.addBlock } -
- - { __( 'Open Site Editor', 'jetpack-sharing-likes' ) } - -
-
+ + }>{ copy.addBlock } +
+ + { __( 'Open Site Editor', 'jetpack-sharing-likes' ) } + +
+ + } + /> ); break; case 'off': diff --git a/projects/packages/sharing-likes/src/settings-app/components/placement-illustrations.tsx b/projects/packages/sharing-likes/src/settings-app/components/placement-illustrations.tsx new file mode 100644 index 000000000000..078aabdb0693 --- /dev/null +++ b/projects/packages/sharing-likes/src/settings-app/components/placement-illustrations.tsx @@ -0,0 +1,166 @@ +import type { TemplatePlacement } from '../types'; +import type { JSX } from 'react'; + +export type PlacedBlock = 'sharing-buttons' | 'like'; + +// Ten lines of post content, as Newsletter's wireframes draw them. +const LINE_WIDTHS = [ 139.44, 145.32, 141.96, 143.64, 142.8, 144.48, 143.64, 139.44, 145.32, 96 ]; +const LINE_GAP = 4.62; +const COLUMN_X = 74; +const TITLE_Y = 50; +const ROW_HEIGHT = 14; + +/** + * Points of a five-pointed star, the Like button's icon. + * + * @param cx - Centre x. + * @param cy - Centre y. + * @param r - Outer radius. + * @return SVG polygon points. + */ +function starPoints( cx: number, cy: number, r: number ): string { + return Array.from( { length: 10 }, ( _, i ) => { + const radius = i % 2 ? r * 0.45 : r; + const angle = ( Math.PI / 5 ) * i - Math.PI / 2; + return `${ cx + radius * Math.cos( angle ) },${ cy + radius * Math.sin( angle ) }`; + } ).join( ' ' ); +} + +/** + * A row of share buttons. + * + * @param props - Props. + * @param props.y - Top of the row. + * @return Row. + */ +function SharingButtonsRow( { y }: { y: number } ): JSX.Element { + return ( + + { [ 0, 1, 2, 3 ].map( index => ( + + + + + ) ) } + + ); +} + +/** + * A Like button and the avatars of a few readers who liked the post. + * + * @param props - Props. + * @param props.y - Top of the row. + * @return Row. + */ +function LikeRow( { y }: { y: number } ): JSX.Element { + const middle = y + ROW_HEIGHT / 2; + + return ( + + + + + { [ 0, 1, 2 ].map( index => ( + + ) ) } + + + ); +} + +/** + * Wireframe of a post with the block before or after its content, drawn 294×192 to fill a `CheckboxCard`. + * + * @param props - Props. + * @param props.block - Block being placed. + * @param props.placement - Where it goes. + * @return Decorative SVG. + */ +export function PlacementIllustration( { + block, + placement, +}: { + block: PlacedBlock; + placement: TemplatePlacement; +} ): JSX.Element { + const blockFirst = placement === 'before_content'; + const contentY = TITLE_Y + 16 + ( blockFirst ? ROW_HEIGHT + 12 : 0 ); + const rowY = blockFirst ? TITLE_Y + 16 : contentY + LINE_WIDTHS.length * LINE_GAP + 8; + const Row = block === 'like' ? LikeRow : SharingButtonsRow; + + return ( + + ); +} diff --git a/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx b/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx new file mode 100644 index 000000000000..c5f82c1dcc6e --- /dev/null +++ b/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx @@ -0,0 +1,158 @@ +import CheckboxCard, { CheckboxCardGrid } from '@automattic/jetpack-components/checkbox-card'; +import { useIsFetching, useIsMutating, useMutationState } from '@tanstack/react-query'; +import { createInterpolateElement, useCallback } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { Fieldset, Link, Text } from '@wordpress/ui'; +import { SAVE_SETTING_KEY, WRITES_KEY, queryKeys, useSettings, useStatus } from '../data/queries'; +import { useSaveSetting, type SettingChange } from '../data/use-save-setting'; +import { PlacementIllustration, type PlacedBlock } from './placement-illustrations'; +import { SettingGroup } from './section-card'; +import type { Feature, TemplatePlacement } from '../types'; +import type { JSX, ReactNode } from 'react'; + +const SETTING_KEYS = { + sharing: 'sharing_buttons_auto_add', + likes: 'likes_auto_add', +} as const; + +const PLACED_BLOCKS: Record< Feature, PlacedBlock > = { + sharing: 'sharing-buttons', + likes: 'like', +}; + +const PLACEMENTS: TemplatePlacement[] = [ 'before_content', 'after_content' ]; + +/** + * The copy for each feature, one complete sentence per string. + * + * @param feature - Feature. + * @return Copy. + */ +function copyFor( feature: Feature ) { + return { + legend: + feature === 'sharing' + ? __( 'Add the Sharing Buttons block to posts and pages', 'jetpack-sharing-likes' ) + : __( 'Add the Like block to posts and pages', 'jetpack-sharing-likes' ), + before: __( 'Before the content', 'jetpack-sharing-likes' ), + after: __( 'After the content', 'jetpack-sharing-likes' ), + }; +} + +/** + * The placements of the last save that went through, which the optimistic cache value hides while saves are pending. + * + * @param key - Setting. + * @param current - Cached value. + * @return Saved placements. + */ +function useSavedPlacements( + key: ( typeof SETTING_KEYS )[ Feature ], + current: TemplatePlacement[] +): TemplatePlacement[] { + // Saves run one at a time, so the oldest pending one still holds what the server has. + const oldestPending = useMutationState( { + filters: { mutationKey: SAVE_SETTING_KEY, status: 'pending' }, + select: mutation => mutation.state.variables as SettingChange | undefined, + } ).find( change => change?.key === key ); + + return oldestPending + ? ( ( oldestPending.previous as TemplatePlacement[] | undefined ) ?? [] ) + : current; +} + +/** + * Cards that add the feature's block before or after the content of single posts and pages. + * + * @param props - Props. + * @param props.feature - Feature. + * @param props.fallback - Shown where the settings do not offer the placements. + * @return Cards, or the fallback. + */ +export function TemplatePlacements( { + feature, + fallback, +}: { + feature: Feature; + fallback: ReactNode; +} ): JSX.Element { + const status = useStatus(); + const key = SETTING_KEYS[ feature ]; + const offered = useSettings()?.[ key ]; + const selected = offered ?? []; + const saved = useSavedPlacements( key, selected ); + const saveSetting = useSaveSetting(); + // "Switch to the … block" lands in this variant before settings are read again, so the key is still missing. + const settling = + useIsMutating( { mutationKey: WRITES_KEY } ) + + useIsFetching( { queryKey: queryKeys.settings } ) > + 0; + + const handleChange = useCallback( + ( name: string, next: boolean ) => { + // The block goes on one side only, so ticking a card replaces the other. + saveSetting( key, next ? [ name as TemplatePlacement ] : [] ); + }, + [ key, saveSetting ] + ); + + if ( ! offered && ! settling ) { + return <>{ fallback }; + } + + const copy = copyFor( feature ); + const block = PLACED_BLOCKS[ feature ]; + const previewUrl = status?.site_editor_url ?? ''; + const pageTemplateUrl = status?.page_template_editor_url ?? ''; + + return ( + + + { copy.legend } + + { __( 'Pick one place: before or after the content.', 'jetpack-sharing-likes' ) } + + + { PLACEMENTS.map( placement => ( + } + checked={ selected.includes( placement ) } + onChange={ handleChange } + previewUrl={ + selected.includes( placement ) && saved.includes( placement ) + ? previewUrl || undefined + : undefined + } + disabled={ ! offered } + /> + ) ) } + + + + { pageTemplateUrl && ( + }> + { createInterpolateElement( + __( + 'Want pages to look different? Edit the page template.', + 'jetpack-sharing-likes' + ), + { link: } + ) } + + ) } + }> + { __( + 'Templates you’ve saved in the Site Editor keep the blocks you left in them, whatever you pick here.', + 'jetpack-sharing-likes' + ) } + + + + + + ); +} diff --git a/projects/packages/sharing-likes/src/settings-app/style.scss b/projects/packages/sharing-likes/src/settings-app/style.scss index 49a46140dc88..cf3f20d87a5e 100644 --- a/projects/packages/sharing-likes/src/settings-app/style.scss +++ b/projects/packages/sharing-likes/src/settings-app/style.scss @@ -29,3 +29,27 @@ body.settings_page_sharing { .jetpack-sharing-likes__variant:focus { outline: none; } + +// Placement card wireframes; the card paints the background. +.jetpack-sharing-likes__wireframe-line { + fill: var(--wpds-color-stroke-surface-neutral); +} + +.jetpack-sharing-likes__wireframe-block { + fill: var(--wpds-color-background-interactive-brand-strong); +} + +.jetpack-sharing-likes__wireframe-surface { + fill: var(--wpds-color-background-surface-neutral-strong); +} + +.jetpack-sharing-likes__wireframe-button { + fill: var(--wpds-color-background-surface-neutral-strong); + stroke: var(--wpds-color-background-interactive-brand-strong); +} + +.jetpack-sharing-likes__wireframe-avatar { + fill: var(--wpds-color-stroke-surface-neutral-strong); + stroke: var(--wpds-color-background-surface-neutral-strong); + stroke-width: 1.5; +} diff --git a/projects/packages/sharing-likes/src/settings-app/test/feature-variant.test.tsx b/projects/packages/sharing-likes/src/settings-app/test/feature-variant.test.tsx index 9df3f9217d3d..e97b16ed41e9 100644 --- a/projects/packages/sharing-likes/src/settings-app/test/feature-variant.test.tsx +++ b/projects/packages/sharing-likes/src/settings-app/test/feature-variant.test.tsx @@ -3,7 +3,7 @@ import userEvent from '@testing-library/user-event'; import apiFetch from '@wordpress/api-fetch'; import { FeatureVariant } from '../components/feature-variant'; import { SECTION_GAP } from '../components/section-card'; -import { apiCalls, baseStatus, renderWithData } from './helpers'; +import { apiCalls, baseSettings, baseStatus, renderWithData } from './helpers'; import type { Feature, SectionState } from '../types'; jest.mock( '@wordpress/api-fetch' ); @@ -49,7 +49,7 @@ describe( 'FeatureVariant', () => { [ 'likes', 'block_call_to_action', [ 'Add the Like block to your theme’s template.' ], null ], [ 'likes', 'off', [ 'Like buttons are turned off for this site.' ], 'Turn on Like buttons' ], ] as [ Feature, SectionState, string[], string | null ][] )( - '%s %s', + '%s %s, on a server that does not offer the placements', ( feature, state, texts, button ) => { renderWithData( @@ -69,6 +69,28 @@ describe( 'FeatureVariant', () => { } ); + it.each( + ( [ 'sharing', 'likes' ] as Feature[] ).flatMap( feature => + ( + [ + 'configure', + 'configure_with_block_nudge', + 'block_call_to_action', + 'off', + ] as SectionState[] + ).map( state => [ feature, state ] as [ Feature, SectionState ] ) + ) + )( '%s %s with placements offered', ( feature, state ) => { + renderWithData( , { + settings: { ...baseSettings, sharing_buttons_auto_add: [], likes_auto_add: [] }, + } ); + + expect( screen.queryAllByRole( 'checkbox' ) ).toHaveLength( + state === 'block_call_to_action' ? 2 : 0 + ); + expect( screen.queryByRole( 'link', { name: 'Open Site Editor' } ) ).not.toBeInTheDocument(); + } ); + it.each( [ [ 'configure_with_block_nudge', diff --git a/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx new file mode 100644 index 000000000000..00ba1656f00d --- /dev/null +++ b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx @@ -0,0 +1,224 @@ +import { screen, waitFor, within } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import apiFetch from '@wordpress/api-fetch'; +import { TemplatePlacements } from '../components/template-placements'; +import { LikeButtonsSection } from '../sections/like-buttons-section'; +import { + apiCalls, + baseSettings, + baseStatus, + renderWithData, + resetNotices, + setScriptData, +} from './helpers'; +import type { Feature, Settings, Status, TemplatePlacement } from '../types'; + +jest.mock( '@wordpress/api-fetch' ); +const mockApiFetch = apiFetch as jest.MockedFunction< typeof apiFetch >; + +const PAGE_TEMPLATE_URL = 'https://example.com/wp-admin/site-editor.php?p=page'; + +const KEYS = { sharing: 'sharing_buttons_auto_add', likes: 'likes_auto_add' } as const; + +/** + * A promise and the functions that settle it. + * + * @return Deferred. + */ +function deferred< T >() { + let resolve!: ( value: T ) => void; + let reject!: ( reason: unknown ) => void; + const promise = new Promise< T >( ( res, rej ) => { + resolve = res; + reject = rej; + } ); + return { promise, resolve, reject }; +} + +/** + * Render the cards with a placement list for the feature. + * + * @param feature - Feature. + * @param stored - The feature's placements. + * @param status - Status overrides. + * @return Render result. + */ +function renderCards( + feature: Feature, + stored: TemplatePlacement[], + status: Partial< Status > = {} +) { + return renderWithData( fallback

} />, { + status: { ...baseStatus, ...status }, + settings: { ...baseSettings, [ KEYS[ feature ] ]: stored }, + } ); +} + +/** + * The card's checkbox. + * + * @param name - Card title. + * @return Checkbox. + */ +function card( name: string ) { + return screen.getByRole( 'checkbox', { name } ); +} + +/** + * The "Preview and edit" links, by the card title they sit under. + * + * @return Titles of the cards showing a link. + */ +function cardsWithPreview(): string[] { + return [ 'Before the content', 'After the content' ].filter( title => + within( screen.getByText( title ).parentElement as HTMLElement ).queryByRole( 'link', { + name: 'Preview and edit', + } ) + ); +} + +beforeEach( () => { + mockApiFetch.mockReset(); + resetNotices(); + setScriptData(); +} ); + +afterEach( () => { + delete ( window as unknown as { JetpackScriptData?: unknown } ).JetpackScriptData; +} ); + +describe( 'TemplatePlacements', () => { + // Sending both sides gets a 400; sending a diff would leave the other side in place. + it.each( [ + [ 'sharing', [], 'Before the content', [ 'before_content' ] ], + [ 'sharing', [ 'after_content' ], 'Before the content', [ 'before_content' ] ], + [ 'sharing', [ 'after_content' ], 'After the content', [] ], + [ 'likes', [ 'before_content' ], 'After the content', [ 'after_content' ] ], + [ 'likes', [ 'before_content' ], 'Before the content', [] ], + ] as [ Feature, TemplatePlacement[], string, TemplatePlacement[] ][] )( + '%s: from %j, clicking "%s" saves %j and ticks only that', + async ( feature, stored, clicked, sent ) => { + const user = userEvent.setup(); + mockApiFetch.mockImplementation( ( { data } ) => + Promise.resolve( { ...baseSettings, ...( data as Settings ) } ) + ); + renderCards( feature, stored ); + + await user.click( card( clicked ) ); + + expect( apiCalls( 'PUT' ) ).toEqual( [ + { + path: '/wpcom/v2/sharing-likes/settings', + method: 'PUT', + data: { [ KEYS[ feature ] ]: sent }, + }, + ] ); + expect( card( 'Before the content' ) ).toHaveAttribute( + 'aria-checked', + String( sent.includes( 'before_content' ) ) + ); + expect( card( 'After the content' ) ).toHaveAttribute( + 'aria-checked', + String( sent.includes( 'after_content' ) ) + ); + } + ); + + it( 'rolls the cards back when the save is refused', async () => { + const user = userEvent.setup(); + const save = deferred< Settings >(); + const stored: Settings = { ...baseSettings, sharing_buttons_auto_add: [ 'after_content' ] }; + mockApiFetch.mockImplementation( ( { path, method } ) => { + if ( method === 'PUT' ) { + return save.promise; + } + return Promise.resolve( path?.endsWith( '/settings' ) ? stored : baseStatus ); + } ); + renderCards( 'sharing', [ 'after_content' ] ); + + await user.click( card( 'Before the content' ) ); + expect( card( 'Before the content' ) ).toHaveAttribute( 'aria-checked', 'true' ); + save.reject( { + code: 'rest_invalid_param', + message: 'Invalid parameter(s): sharing_buttons_auto_add', + } ); + + await waitFor( () => + expect( card( 'After the content' ) ).toHaveAttribute( 'aria-checked', 'true' ) + ); + expect( card( 'Before the content' ) ).toHaveAttribute( 'aria-checked', 'false' ); + } ); + + // The link opens the template, which only has the block once the save lands. + it.each( [ + [ [ 'after_content' ], baseStatus.site_editor_url, [ 'After the content' ] ], + [ [ 'after_content' ], '', [] ], + [ [], baseStatus.site_editor_url, [] ], + ] as [ TemplatePlacement[], string, string[] ][] )( + 'with %j saved and Site Editor URL "%s", links %j to the single template', + ( stored, url, linked ) => { + renderCards( 'likes', stored, { site_editor_url: url } ); + + expect( cardsWithPreview() ).toEqual( linked ); + screen + .queryAllByRole( 'link', { name: 'Preview and edit' } ) + .forEach( link => expect( link ).toHaveAttribute( 'href', url ) ); + } + ); + + it( 'only links a ticked card once its save lands', async () => { + const user = userEvent.setup(); + const save = deferred< Settings >(); + mockApiFetch.mockImplementation( ( { method } ) => + method === 'PUT' ? save.promise : Promise.resolve( baseStatus ) + ); + renderCards( 'sharing', [ 'after_content' ] ); + + await user.click( card( 'Before the content' ) ); + + expect( cardsWithPreview() ).toEqual( [] ); + save.resolve( { ...baseSettings, sharing_buttons_auto_add: [ 'before_content' ] } ); + await waitFor( () => expect( cardsWithPreview() ).toEqual( [ 'Before the content' ] ) ); + } ); + + it.each( [ PAGE_TEMPLATE_URL, '' ] )( 'links the page template only with a URL: "%s"', url => { + renderCards( 'sharing', [], { page_template_editor_url: url } ); + + // By text: an anchor with an empty href has no link role, so a role query would pass on a broken link. + expect( screen.queryByText( 'Edit the page template' )?.getAttribute( 'href' ) ).toBe( + url || undefined + ); + } ); + + // The status lands before settings are read again, so for a moment the variant has no placements to show. + it( 'shows the cards disabled, not the Site Editor button, while settings catch up with a switch', async () => { + const user = userEvent.setup(); + const settings = deferred< Settings >(); + mockApiFetch.mockImplementation( ( { path, method } ) => { + if ( method === 'POST' ) { + return Promise.resolve( { + ...baseStatus, + likes: { state: 'block_call_to_action', supported: true }, + } ); + } + return path?.endsWith( '/settings' ) ? settings.promise : Promise.resolve( baseStatus ); + } ); + renderWithData( , { + status: { ...baseStatus, likes: { state: 'configure_with_block_nudge', supported: true } }, + } ); + + await user.click( screen.getByRole( 'button', { name: 'Switch to the Like block' } ) ); + + await waitFor( () => expect( screen.getAllByRole( 'checkbox' ) ).toHaveLength( 2 ) ); + screen + .getAllByRole( 'checkbox' ) + .forEach( checkbox => expect( checkbox ).toHaveAttribute( 'aria-disabled', 'true' ) ); + expect( screen.queryByRole( 'link', { name: 'Open Site Editor' } ) ).not.toBeInTheDocument(); + + settings.resolve( { ...baseSettings, likes_auto_add: [] } ); + await waitFor( () => + expect( card( 'Before the content' ) ).not.toHaveAttribute( 'aria-disabled', 'true' ) + ); + expect( screen.queryByRole( 'link', { name: 'Open Site Editor' } ) ).not.toBeInTheDocument(); + } ); +} ); From 57457a1696e8d40b7ce9e22241ebe67e79d5e663 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Tue, 20 Oct 2026 10:48:01 +0200 Subject: [PATCH 2/9] Sharing & Likes: Describe the template placement cards in AGENTS.md Part of CM-976 The React screen's section in AGENTS.md covered the services manager but not the cards that now replace the Site Editor link, nor when the link still shows. --- projects/packages/sharing-likes/AGENTS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/projects/packages/sharing-likes/AGENTS.md b/projects/packages/sharing-likes/AGENTS.md index a8feda79219d..efab47e27de5 100644 --- a/projects/packages/sharing-likes/AGENTS.md +++ b/projects/packages/sharing-likes/AGENTS.md @@ -67,6 +67,11 @@ back, which is why that one removal asks first instead of offering Undo. Deletin a custom service leaves its ID in `sharing-services`, so `useCustomService` saves the lists again without it. +In `BLOCK_CALL_TO_ACTION`, `TemplatePlacements` replaces the Site Editor link with +two cards per section, saving the template placements (see "Template placements" +below). Each save sends the whole list, so ticking one card replaces the other. It +falls back to the Site Editor link only where `settings` does not offer the key. + ## Per-post switches `Post_Likes_Switch` and `Post_Sharing_Switch` own the Likes and Sharing switches From 84b0b16c12a414e0f61a44a91db5fa46bc4aab15 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 21 Oct 2026 14:39:20 +0200 Subject: [PATCH 3/9] Sharing & Likes: Test that refused saves of list settings roll back The rollback only restores a setting while the store still holds the value that save wrote, compared by identity, so a later edit of the same setting is kept. Under TanStack Query the cache held a copy of every array, so no list setting ever rolled back: `show`, and the template placements. The settings store keeps the value it is given, so lists roll back again; this pins it with a list row next to the boolean one. --- .../test/use-save-setting.test.tsx | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/projects/packages/sharing-likes/src/settings-app/test/use-save-setting.test.tsx b/projects/packages/sharing-likes/src/settings-app/test/use-save-setting.test.tsx index b7ac5112cd4f..1deeeaddf473 100644 --- a/projects/packages/sharing-likes/src/settings-app/test/use-save-setting.test.tsx +++ b/projects/packages/sharing-likes/src/settings-app/test/use-save-setting.test.tsx @@ -10,7 +10,7 @@ import { snackbarMessages, wrapperFor, } from './helpers'; -import type { Settings } from '../types'; +import type { SettingKey, Settings } from '../types'; jest.mock( '@wordpress/api-fetch' ); const mockApiFetch = apiFetch as jest.MockedFunction< typeof apiFetch >; @@ -76,28 +76,34 @@ describe( 'useSaveSetting', () => { expect( registry.select( store ).getSettings() ).toEqual( saved ); } ); - it( 'rolls back and shows the server message when a save fails', async () => { - mockApiFetch.mockImplementation( ( { method, path } ) => { - if ( method === 'PUT' ) { - return Promise.reject( { - code: 'rest_sharing_likes_comment_likes_unchanged', - message: 'Comment Likes could not be switched on or off on this site.', - } ); - } - // A settings read that never lands, so only the rollback can restore the value. - return path?.endsWith( '/status' ) ? Promise.resolve( baseStatus ) : new Promise( () => {} ); - } ); - const { result, registry } = renderSave(); + it.each( [ + [ 'comment_likes_enabled', true ], + [ 'show', [ 'post' ] ], + ] as [ SettingKey, Settings[ SettingKey ] ][] )( + 'rolls %s back and shows the server message when a save fails', + async ( key, value ) => { + mockApiFetch.mockImplementation( ( { method, path } ) => { + if ( method === 'PUT' ) { + return Promise.reject( { + code: 'rest_sharing_likes_comment_likes_unchanged', + message: 'Comment Likes could not be switched on or off on this site.', + } ); + } + // A settings read that never lands, so only the rollback can restore the value. + return path?.endsWith( '/status' ) + ? Promise.resolve( baseStatus ) + : new Promise( () => {} ); + } ); + const { result, registry } = renderSave(); - await act( () => result.current( 'comment_likes_enabled', true ) ); + await act( () => result.current( key, value ) ); - expect( registry.select( store ).getSettings() ).toMatchObject( { - comment_likes_enabled: false, - } ); - expect( snackbarMessages() ).toContain( - 'Comment Likes could not be switched on or off on this site.' - ); - } ); + expect( registry.select( store ).getSettings()?.[ key ] ).toEqual( baseSettings[ key ] ); + expect( snackbarMessages() ).toContain( + 'Comment Likes could not be switched on or off on this site.' + ); + } + ); it.each( [ { From 4b6f960b4912947007aa23ebe74b9fce71a65209 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Tue, 20 Oct 2026 11:06:24 +0200 Subject: [PATCH 4/9] Sharing & Likes: Keep the placement hint announced, and trim the card tests `Fieldset.Root` holds one description id, and `Fieldset.Details` registers its own, so wherever the theme has a page template, screen readers lost "Pick one place: before or after the content." to the hidden "More details follow." The notes under the cards are now plain paragraphs, and the page template test asserts the fieldset's description. "Before the content" and "After the content" get translator context, since they read as fragments on their own. The tests drop rows and cases that no mutation of the component could fail on their own (the rollback is covered in `use-save-setting`), and the switch test now checks the fieldset by its legend and `aria-busy`. --- .../components/template-placements.tsx | 43 +++++------ .../test/feature-variant.test.tsx | 24 +----- .../test/template-placements.test.tsx | 77 ++++++------------- 3 files changed, 45 insertions(+), 99 deletions(-) diff --git a/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx b/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx index c5f82c1dcc6e..13923ca71959 100644 --- a/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx +++ b/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx @@ -1,7 +1,7 @@ import CheckboxCard, { CheckboxCardGrid } from '@automattic/jetpack-components/checkbox-card'; import { useIsFetching, useIsMutating, useMutationState } from '@tanstack/react-query'; import { createInterpolateElement, useCallback } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; +import { __, _x } from '@wordpress/i18n'; import { Fieldset, Link, Text } from '@wordpress/ui'; import { SAVE_SETTING_KEY, WRITES_KEY, queryKeys, useSettings, useStatus } from '../data/queries'; import { useSaveSetting, type SettingChange } from '../data/use-save-setting'; @@ -34,8 +34,8 @@ function copyFor( feature: Feature ) { feature === 'sharing' ? __( 'Add the Sharing Buttons block to posts and pages', 'jetpack-sharing-likes' ) : __( 'Add the Like block to posts and pages', 'jetpack-sharing-likes' ), - before: __( 'Before the content', 'jetpack-sharing-likes' ), - after: __( 'After the content', 'jetpack-sharing-likes' ), + before: _x( 'Before the content', 'Where the block goes', 'jetpack-sharing-likes' ), + after: _x( 'After the content', 'Where the block goes', 'jetpack-sharing-likes' ), }; } @@ -124,34 +124,33 @@ export function TemplatePlacements( { onChange={ handleChange } previewUrl={ selected.includes( placement ) && saved.includes( placement ) - ? previewUrl || undefined + ? previewUrl : undefined } disabled={ ! offered } /> ) ) } - - - { pageTemplateUrl && ( - }> - { createInterpolateElement( - __( - 'Want pages to look different? Edit the page template.', - 'jetpack-sharing-likes' - ), - { link: } - ) } - - ) } + { /* Not Fieldset.Details: the fieldset takes one description, and it would replace the hint above. */ } + + { pageTemplateUrl && ( }> - { __( - 'Templates you’ve saved in the Site Editor keep the blocks you left in them, whatever you pick here.', - 'jetpack-sharing-likes' + { createInterpolateElement( + __( + 'Want pages to look different? Edit the page template.', + 'jetpack-sharing-likes' + ), + { link: } ) } - - + ) } + }> + { __( + 'Templates you’ve saved in the Site Editor keep the blocks you left in them, whatever you pick here.', + 'jetpack-sharing-likes' + ) } + + ); diff --git a/projects/packages/sharing-likes/src/settings-app/test/feature-variant.test.tsx b/projects/packages/sharing-likes/src/settings-app/test/feature-variant.test.tsx index e97b16ed41e9..1dd94ac001b5 100644 --- a/projects/packages/sharing-likes/src/settings-app/test/feature-variant.test.tsx +++ b/projects/packages/sharing-likes/src/settings-app/test/feature-variant.test.tsx @@ -3,7 +3,7 @@ import userEvent from '@testing-library/user-event'; import apiFetch from '@wordpress/api-fetch'; import { FeatureVariant } from '../components/feature-variant'; import { SECTION_GAP } from '../components/section-card'; -import { apiCalls, baseSettings, baseStatus, renderWithData } from './helpers'; +import { apiCalls, baseStatus, renderWithData } from './helpers'; import type { Feature, SectionState } from '../types'; jest.mock( '@wordpress/api-fetch' ); @@ -69,28 +69,6 @@ describe( 'FeatureVariant', () => { } ); - it.each( - ( [ 'sharing', 'likes' ] as Feature[] ).flatMap( feature => - ( - [ - 'configure', - 'configure_with_block_nudge', - 'block_call_to_action', - 'off', - ] as SectionState[] - ).map( state => [ feature, state ] as [ Feature, SectionState ] ) - ) - )( '%s %s with placements offered', ( feature, state ) => { - renderWithData( , { - settings: { ...baseSettings, sharing_buttons_auto_add: [], likes_auto_add: [] }, - } ); - - expect( screen.queryAllByRole( 'checkbox' ) ).toHaveLength( - state === 'block_call_to_action' ? 2 : 0 - ); - expect( screen.queryByRole( 'link', { name: 'Open Site Editor' } ) ).not.toBeInTheDocument(); - } ); - it.each( [ [ 'configure_with_block_nudge', diff --git a/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx index 00ba1656f00d..acb22959a7ca 100644 --- a/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx +++ b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx @@ -88,13 +88,9 @@ afterEach( () => { } ); describe( 'TemplatePlacements', () => { - // Sending both sides gets a 400; sending a diff would leave the other side in place. it.each( [ - [ 'sharing', [], 'Before the content', [ 'before_content' ] ], [ 'sharing', [ 'after_content' ], 'Before the content', [ 'before_content' ] ], [ 'sharing', [ 'after_content' ], 'After the content', [] ], - [ 'likes', [ 'before_content' ], 'After the content', [ 'after_content' ] ], - [ 'likes', [ 'before_content' ], 'Before the content', [] ], ] as [ Feature, TemplatePlacement[], string, TemplatePlacement[] ][] )( '%s: from %j, clicking "%s" saves %j and ticks only that', async ( feature, stored, clicked, sent ) => { @@ -124,48 +120,7 @@ describe( 'TemplatePlacements', () => { } ); - it( 'rolls the cards back when the save is refused', async () => { - const user = userEvent.setup(); - const save = deferred< Settings >(); - const stored: Settings = { ...baseSettings, sharing_buttons_auto_add: [ 'after_content' ] }; - mockApiFetch.mockImplementation( ( { path, method } ) => { - if ( method === 'PUT' ) { - return save.promise; - } - return Promise.resolve( path?.endsWith( '/settings' ) ? stored : baseStatus ); - } ); - renderCards( 'sharing', [ 'after_content' ] ); - - await user.click( card( 'Before the content' ) ); - expect( card( 'Before the content' ) ).toHaveAttribute( 'aria-checked', 'true' ); - save.reject( { - code: 'rest_invalid_param', - message: 'Invalid parameter(s): sharing_buttons_auto_add', - } ); - - await waitFor( () => - expect( card( 'After the content' ) ).toHaveAttribute( 'aria-checked', 'true' ) - ); - expect( card( 'Before the content' ) ).toHaveAttribute( 'aria-checked', 'false' ); - } ); - // The link opens the template, which only has the block once the save lands. - it.each( [ - [ [ 'after_content' ], baseStatus.site_editor_url, [ 'After the content' ] ], - [ [ 'after_content' ], '', [] ], - [ [], baseStatus.site_editor_url, [] ], - ] as [ TemplatePlacement[], string, string[] ][] )( - 'with %j saved and Site Editor URL "%s", links %j to the single template', - ( stored, url, linked ) => { - renderCards( 'likes', stored, { site_editor_url: url } ); - - expect( cardsWithPreview() ).toEqual( linked ); - screen - .queryAllByRole( 'link', { name: 'Preview and edit' } ) - .forEach( link => expect( link ).toHaveAttribute( 'href', url ) ); - } - ); - it( 'only links a ticked card once its save lands', async () => { const user = userEvent.setup(); const save = deferred< Settings >(); @@ -174,23 +129,35 @@ describe( 'TemplatePlacements', () => { ); renderCards( 'sharing', [ 'after_content' ] ); + expect( cardsWithPreview() ).toEqual( [ 'After the content' ] ); await user.click( card( 'Before the content' ) ); + expect( card( 'Before the content' ) ).toHaveAttribute( 'aria-checked', 'true' ); expect( cardsWithPreview() ).toEqual( [] ); save.resolve( { ...baseSettings, sharing_buttons_auto_add: [ 'before_content' ] } ); await waitFor( () => expect( cardsWithPreview() ).toEqual( [ 'Before the content' ] ) ); + expect( screen.getByRole( 'link', { name: 'Preview and edit' } ) ).toHaveAttribute( + 'href', + baseStatus.site_editor_url + ); } ); - it.each( [ PAGE_TEMPLATE_URL, '' ] )( 'links the page template only with a URL: "%s"', url => { - renderCards( 'sharing', [], { page_template_editor_url: url } ); + it.each( [ PAGE_TEMPLATE_URL, '' ] )( + 'links the page template only with a URL, keeping the notes: "%s"', + url => { + renderCards( 'sharing', [], { page_template_editor_url: url } ); - // By text: an anchor with an empty href has no link role, so a role query would pass on a broken link. - expect( screen.queryByText( 'Edit the page template' )?.getAttribute( 'href' ) ).toBe( - url || undefined - ); - } ); + // By text: an anchor with an empty href has no link role, so a role query would pass on a broken link. + expect( screen.queryByText( 'Edit the page template' )?.getAttribute( 'href' ) ).toBe( + url || undefined + ); + expect( screen.getByText( /Templates you’ve saved in the Site Editor/ ) ).toBeInTheDocument(); + expect( screen.getByRole( 'group' ) ).toHaveAccessibleDescription( + 'Pick one place: before or after the content.' + ); + } + ); - // The status lands before settings are read again, so for a moment the variant has no placements to show. it( 'shows the cards disabled, not the Site Editor button, while settings catch up with a switch', async () => { const user = userEvent.setup(); const settings = deferred< Settings >(); @@ -213,12 +180,14 @@ describe( 'TemplatePlacements', () => { screen .getAllByRole( 'checkbox' ) .forEach( checkbox => expect( checkbox ).toHaveAttribute( 'aria-disabled', 'true' ) ); + const group = screen.getByRole( 'group', { name: 'Add the Like block to posts and pages' } ); + expect( group ).toHaveAttribute( 'aria-busy', 'true' ); expect( screen.queryByRole( 'link', { name: 'Open Site Editor' } ) ).not.toBeInTheDocument(); settings.resolve( { ...baseSettings, likes_auto_add: [] } ); await waitFor( () => expect( card( 'Before the content' ) ).not.toHaveAttribute( 'aria-disabled', 'true' ) ); - expect( screen.queryByRole( 'link', { name: 'Open Site Editor' } ) ).not.toBeInTheDocument(); + expect( group ).toHaveAttribute( 'aria-busy', 'false' ); } ); } ); From faeffea54efedc7b4255b18868fd2199ce5db61d Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 21 Oct 2026 14:41:04 +0200 Subject: [PATCH 5/9] Sharing & Likes: Read the placement cards' state from the settings store MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of CM-976 The cards read two things from TanStack Query: whether settings were still being re-read after "Switch to the … block", and the value of the last save that went through, for the "Preview and edit" link. #53853 moved the screen to a @wordpress/data store, so both now come from its pending-write count. A feature action stays pending until settings are read again, so the cards show disabled until the new variant's key arrives, as before. While any write is pending, the stored settings may hold an optimistic value, so the preview link waits until nothing is saving. That hides an already-saved card's link for the length of another setting's save; in exchange the cards need no copy of the last saved settings. --- .../components/template-placements.tsx | 43 ++++--------------- .../test/template-placements.test.tsx | 10 +---- 2 files changed, 9 insertions(+), 44 deletions(-) diff --git a/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx b/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx index 13923ca71959..9fee5bd05eeb 100644 --- a/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx +++ b/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx @@ -1,10 +1,9 @@ import CheckboxCard, { CheckboxCardGrid } from '@automattic/jetpack-components/checkbox-card'; -import { useIsFetching, useIsMutating, useMutationState } from '@tanstack/react-query'; import { createInterpolateElement, useCallback } from '@wordpress/element'; import { __, _x } from '@wordpress/i18n'; import { Fieldset, Link, Text } from '@wordpress/ui'; -import { SAVE_SETTING_KEY, WRITES_KEY, queryKeys, useSettings, useStatus } from '../data/queries'; -import { useSaveSetting, type SettingChange } from '../data/use-save-setting'; +import { useIsSaving, useSettings, useStatus } from '../data/queries'; +import { useSaveSetting } from '../data/use-save-setting'; import { PlacementIllustration, type PlacedBlock } from './placement-illustrations'; import { SettingGroup } from './section-card'; import type { Feature, TemplatePlacement } from '../types'; @@ -39,28 +38,6 @@ function copyFor( feature: Feature ) { }; } -/** - * The placements of the last save that went through, which the optimistic cache value hides while saves are pending. - * - * @param key - Setting. - * @param current - Cached value. - * @return Saved placements. - */ -function useSavedPlacements( - key: ( typeof SETTING_KEYS )[ Feature ], - current: TemplatePlacement[] -): TemplatePlacement[] { - // Saves run one at a time, so the oldest pending one still holds what the server has. - const oldestPending = useMutationState( { - filters: { mutationKey: SAVE_SETTING_KEY, status: 'pending' }, - select: mutation => mutation.state.variables as SettingChange | undefined, - } ).find( change => change?.key === key ); - - return oldestPending - ? ( ( oldestPending.previous as TemplatePlacement[] | undefined ) ?? [] ) - : current; -} - /** * Cards that add the feature's block before or after the content of single posts and pages. * @@ -80,13 +57,10 @@ export function TemplatePlacements( { const key = SETTING_KEYS[ feature ]; const offered = useSettings()?.[ key ]; const selected = offered ?? []; - const saved = useSavedPlacements( key, selected ); const saveSetting = useSaveSetting(); - // "Switch to the … block" lands in this variant before settings are read again, so the key is still missing. - const settling = - useIsMutating( { mutationKey: WRITES_KEY } ) + - useIsFetching( { queryKey: queryKeys.settings } ) > - 0; + // While a write is pending the stored settings may not be what the server has yet. A feature action + // counts until settings are read again, so right after "Switch to the … block" the key can still be missing. + const saving = useIsSaving(); const handleChange = useCallback( ( name: string, next: boolean ) => { @@ -96,7 +70,7 @@ export function TemplatePlacements( { [ key, saveSetting ] ); - if ( ! offered && ! settling ) { + if ( ! offered && ! saving ) { return <>{ fallback }; } @@ -123,9 +97,8 @@ export function TemplatePlacements( { checked={ selected.includes( placement ) } onChange={ handleChange } previewUrl={ - selected.includes( placement ) && saved.includes( placement ) - ? previewUrl - : undefined + // The template only has the block once the save has gone through. + selected.includes( placement ) && ! saving ? previewUrl : undefined } disabled={ ! offered } /> diff --git a/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx index acb22959a7ca..02c71b7b6aad 100644 --- a/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx +++ b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx @@ -3,14 +3,7 @@ import userEvent from '@testing-library/user-event'; import apiFetch from '@wordpress/api-fetch'; import { TemplatePlacements } from '../components/template-placements'; import { LikeButtonsSection } from '../sections/like-buttons-section'; -import { - apiCalls, - baseSettings, - baseStatus, - renderWithData, - resetNotices, - setScriptData, -} from './helpers'; +import { apiCalls, baseSettings, baseStatus, renderWithData, setScriptData } from './helpers'; import type { Feature, Settings, Status, TemplatePlacement } from '../types'; jest.mock( '@wordpress/api-fetch' ); @@ -79,7 +72,6 @@ function cardsWithPreview(): string[] { beforeEach( () => { mockApiFetch.mockReset(); - resetNotices(); setScriptData(); } ); From d30330a36a2d12dfbc1f03b6c7d14ebc5855c88a Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 21 Oct 2026 14:59:32 +0200 Subject: [PATCH 6/9] Sharing & Likes: Make the placement card tests tell saving from loading Part of CM-976 The switch test only covers the moment when the key is missing and a write is pending at once, so a component that disabled the cards and marked the group busy during every placement save still passed. Users would see the cards flicker disabled on each click. The preview test now checks that the other card stays enabled while a save is pending. The click table now has a Likes row, so the Likes setting key is tested directly rather than only through the switch test. The comment above the preview test went: the component holds that rationale, and the test name already says it. --- .../src/settings-app/test/template-placements.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx index 02c71b7b6aad..37562663b318 100644 --- a/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx +++ b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx @@ -82,9 +82,9 @@ afterEach( () => { describe( 'TemplatePlacements', () => { it.each( [ [ 'sharing', [ 'after_content' ], 'Before the content', [ 'before_content' ] ], - [ 'sharing', [ 'after_content' ], 'After the content', [] ], + [ 'likes', [ 'after_content' ], 'After the content', [] ], ] as [ Feature, TemplatePlacement[], string, TemplatePlacement[] ][] )( - '%s: from %j, clicking "%s" saves %j and ticks only that', + '%s: from %j, clicking "%s" saves and ticks %j', async ( feature, stored, clicked, sent ) => { const user = userEvent.setup(); mockApiFetch.mockImplementation( ( { data } ) => @@ -112,7 +112,6 @@ describe( 'TemplatePlacements', () => { } ); - // The link opens the template, which only has the block once the save lands. it( 'only links a ticked card once its save lands', async () => { const user = userEvent.setup(); const save = deferred< Settings >(); @@ -125,6 +124,7 @@ describe( 'TemplatePlacements', () => { await user.click( card( 'Before the content' ) ); expect( card( 'Before the content' ) ).toHaveAttribute( 'aria-checked', 'true' ); + expect( card( 'After the content' ) ).not.toHaveAttribute( 'aria-disabled', 'true' ); expect( cardsWithPreview() ).toEqual( [] ); save.resolve( { ...baseSettings, sharing_buttons_auto_add: [ 'before_content' ] } ); await waitFor( () => expect( cardsWithPreview() ).toEqual( [ 'Before the content' ] ) ); From 9168b764ca955591f372dcf81fc7b9e9b594d479 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 21 Oct 2026 15:04:53 +0200 Subject: [PATCH 7/9] Sharing & Likes: Say what the cards cannot change in a saved template Part of CM-976 The note under the cards said saved templates "keep the blocks you left in them, whatever you pick here", which reads as if a pick still applies on top. It does not. Saving a template in the Site Editor records each hooked block type in the anchor's `ignoredHookedBlocks`, per type rather than per side. After that, a block the owner removed stays removed, and moving a placement to the other side adds nothing there. The card's own "Preview and edit" link is the shortest way into that state, so the note now says to move or remove those blocks in the Site Editor. --- .../src/settings-app/components/template-placements.tsx | 2 +- .../src/settings-app/test/template-placements.test.tsx | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx b/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx index 9fee5bd05eeb..42ce14673286 100644 --- a/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx +++ b/projects/packages/sharing-likes/src/settings-app/components/template-placements.tsx @@ -119,7 +119,7 @@ export function TemplatePlacements( { ) } }> { __( - 'Templates you’ve saved in the Site Editor keep the blocks you left in them, whatever you pick here.', + 'Once you’ve saved a template in the Site Editor, move or remove its blocks there: picking a place here won’t move a block that template already has, or bring back one you removed.', 'jetpack-sharing-likes' ) } diff --git a/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx index 37562663b318..1620de9197d7 100644 --- a/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx +++ b/projects/packages/sharing-likes/src/settings-app/test/template-placements.test.tsx @@ -143,7 +143,9 @@ describe( 'TemplatePlacements', () => { expect( screen.queryByText( 'Edit the page template' )?.getAttribute( 'href' ) ).toBe( url || undefined ); - expect( screen.getByText( /Templates you’ve saved in the Site Editor/ ) ).toBeInTheDocument(); + expect( + screen.getByText( /Once you’ve saved a template in the Site Editor/ ) + ).toBeInTheDocument(); expect( screen.getByRole( 'group' ) ).toHaveAccessibleDescription( 'Pick one place: before or after the content.' ); From 55140abed7099ade2f25e9df3ccd8208423c3f64 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 21 Oct 2026 15:05:01 +0200 Subject: [PATCH 8/9] Sharing & Likes: Correct the placement cards' notes and changelog entry Part of CM-976 AGENTS.md said each save "sends the whole list", which describes the bug the tests guard against: the cards send one placement or none, and that is why ticking one card unticks the other. It also left out that the fallback waits while a write is pending, showing the cards disabled instead. The changelog entry read as if the live Settings > Sharing screen got the cards. They are only in its React version, behind `rsm_jetpack_ui_modernization_sharing_likes`, and the entry now says so, matching the package's earlier entries for that screen. --- projects/packages/sharing-likes/AGENTS.md | 5 +++-- .../changelog/add-sharing-likes-placement-cards | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/packages/sharing-likes/AGENTS.md b/projects/packages/sharing-likes/AGENTS.md index efab47e27de5..aa463ea69267 100644 --- a/projects/packages/sharing-likes/AGENTS.md +++ b/projects/packages/sharing-likes/AGENTS.md @@ -69,8 +69,9 @@ the lists again without it. In `BLOCK_CALL_TO_ACTION`, `TemplatePlacements` replaces the Site Editor link with two cards per section, saving the template placements (see "Template placements" -below). Each save sends the whole list, so ticking one card replaces the other. It -falls back to the Site Editor link only where `settings` does not offer the key. +below). Each save sends a one-item list, or an empty one, so ticking one card +unticks the other. It falls back to the Site Editor link only where `settings` does +not offer the key and no write is pending; while one is, the cards show disabled. ## Per-post switches diff --git a/projects/packages/sharing-likes/changelog/add-sharing-likes-placement-cards b/projects/packages/sharing-likes/changelog/add-sharing-likes-placement-cards index e265fd958f90..5b707102e96b 100644 --- a/projects/packages/sharing-likes/changelog/add-sharing-likes-placement-cards +++ b/projects/packages/sharing-likes/changelog/add-sharing-likes-placement-cards @@ -1,4 +1,4 @@ Significance: minor Type: added -Settings: Add cards that place the Sharing Buttons and Like blocks before or after the content of posts and pages. +Add cards to the React version of Settings > Sharing that place the Sharing Buttons and Like blocks before or after the content of posts and pages. From d4b398633d6c1a17f710ef1bf2b9b13ce1b7647c Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 21 Oct 2026 16:36:06 +0200 Subject: [PATCH 9/9] Sharing & Likes: Say the placement choices don't apply to the blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of CM-976 The "Where … appear" section stays on screen while another section offers its block, and the block cards cover posts and pages whatever that section says. Unticking Pages there reads as if it kept the blocks off pages too. The section now says blocks added to templates aren't affected, whenever a section offers its block. --- .../sections/placement-section.tsx | 20 +++++++++++++---- .../test/placement-section.test.tsx | 22 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/projects/packages/sharing-likes/src/settings-app/sections/placement-section.tsx b/projects/packages/sharing-likes/src/settings-app/sections/placement-section.tsx index f3a51ad3550b..ea7b83e1259f 100644 --- a/projects/packages/sharing-likes/src/settings-app/sections/placement-section.tsx +++ b/projects/packages/sharing-likes/src/settings-app/sections/placement-section.tsx @@ -36,14 +36,26 @@ export function PlacementSection(): JSX.Element | null { return null; } + // A section that offers its block sits next to this one, and the block ignores these choices. + const offersBlock = + status.sharing.state === 'block_call_to_action' || + ( status.likes.state === 'block_call_to_action' && status.likes.supported ); + return ( + { __( + 'These choices apply to every feature named in the heading.', + 'jetpack-sharing-likes' + ) } + { offersBlock && + ' ' + + __( 'Blocks you add to your templates aren’t affected.', 'jetpack-sharing-likes' ) } + + } > diff --git a/projects/packages/sharing-likes/src/settings-app/test/placement-section.test.tsx b/projects/packages/sharing-likes/src/settings-app/test/placement-section.test.tsx index 0c97266277a6..6b3b252e3a44 100644 --- a/projects/packages/sharing-likes/src/settings-app/test/placement-section.test.tsx +++ b/projects/packages/sharing-likes/src/settings-app/test/placement-section.test.tsx @@ -3,6 +3,7 @@ import userEvent from '@testing-library/user-event'; import apiFetch from '@wordpress/api-fetch'; import { PlacementSection } from '../sections/placement-section'; import { apiCalls, baseSettings, baseStatus, renderWithData, setScriptData } from './helpers'; +import type { Status } from '../types'; jest.mock( '@wordpress/api-fetch' ); const mockApiFetch = apiFetch as jest.MockedFunction< typeof apiFetch >; @@ -30,6 +31,27 @@ describe( 'PlacementSection', () => { ).not.toBeChecked(); } ); + // Unticking Pages here doesn't keep the Sharing Buttons or Like block off pages. + it.each( [ + [ 'sharing', { ...baseStatus, sharing: { state: 'block_call_to_action' } }, true ], + [ 'likes', { ...baseStatus, likes: { state: 'block_call_to_action', supported: true } }, true ], + [ + 'offline likes', + { ...baseStatus, likes: { state: 'block_call_to_action', supported: false } }, + false, + ], + [ 'no', baseStatus, false ], + ] as [ string, Status, boolean ][] )( + 'with %s section on the block, says blocks are not affected: %s', + ( _section, status, shown ) => { + renderWithData( , { status } ); + + expect( + screen.queryByText( /Blocks you add to your templates aren’t affected\./ ) !== null + ).toBe( shown ); + } + ); + it( 'saves the whole list when one place changes', async () => { const user = userEvent.setup(); renderWithData( );