diff --git a/src/experiments/editorial-notes/components/EditorialNotesPlugin.tsx b/src/experiments/editorial-notes/components/EditorialNotesPlugin.tsx index a9a421659..61e11ed77 100644 --- a/src/experiments/editorial-notes/components/EditorialNotesPlugin.tsx +++ b/src/experiments/editorial-notes/components/EditorialNotesPlugin.tsx @@ -85,6 +85,7 @@ export default function EditorialNotesPlugin() { justifyContent: 'center', width: '100%', } } + accessibleWhenDisabled __next40pxDefaultSize > { buttonLabel } diff --git a/src/experiments/editorial-notes/hooks/useEditorialNotes.ts b/src/experiments/editorial-notes/hooks/useEditorialNotes.ts index c9450a4b3..59be2e67a 100644 --- a/src/experiments/editorial-notes/hooks/useEditorialNotes.ts +++ b/src/experiments/editorial-notes/hooks/useEditorialNotes.ts @@ -265,6 +265,20 @@ export function useEditorialNotes(): { ( dispatch( coreStore ) as any ).invalidateResolutionForStoreSelector( 'getEntityRecords' ); + + ( dispatch( noticesStore ) as any ).createSuccessNotice( + sprintf( + /* translators: %d: number of suggestions added. */ + _n( + '%d suggestion added. Save to keep changes.', + '%d suggestions added. Save to keep changes.', + totalSuggestions, + 'ai' + ), + totalSuggestions + ), + { type: 'snackbar' } + ); } } catch ( error: any ) { ( dispatch( noticesStore ) as any ).createErrorNotice( @@ -350,8 +364,8 @@ export function useEditorialBlock(): { sprintf( /* translators: %d: number of suggestions added. */ _n( - '%d suggestion added.', - '%d suggestions added.', + '%d suggestion added. Save to keep changes.', + '%d suggestions added. Save to keep changes.', suggestionCount, 'ai' ), diff --git a/src/experiments/editorial-updates/components/EditorialUpdatesPlugin.tsx b/src/experiments/editorial-updates/components/EditorialUpdatesPlugin.tsx index 065682cd2..017e3b5f3 100644 --- a/src/experiments/editorial-updates/components/EditorialUpdatesPlugin.tsx +++ b/src/experiments/editorial-updates/components/EditorialUpdatesPlugin.tsx @@ -63,6 +63,7 @@ export default function EditorialUpdatesPlugin() { width: '100%', justifyContent: 'center', } } + accessibleWhenDisabled > { buttonLabel } diff --git a/src/experiments/editorial-updates/hooks/useEditorialUpdates.ts b/src/experiments/editorial-updates/hooks/useEditorialUpdates.ts index 82ebcc926..ee9a06fc4 100644 --- a/src/experiments/editorial-updates/hooks/useEditorialUpdates.ts +++ b/src/experiments/editorial-updates/hooks/useEditorialUpdates.ts @@ -99,6 +99,26 @@ export function useEditorialUpdates(): { if ( ! postId ) { return false; } + + // Collect Note IDs linked from block metadata, then check whether any are + // still pending. This avoids showing the action for stale Notes left behind + // after refreshing before the generated Note metadata was explicitly saved. + const allBlocks = sel( blockEditorStore ).getBlocks() as Block[]; + const linkedNoteIds = Array.from( + new Set( + flattenBlocks( allBlocks ) + .filter( ( block ) => + REVIEWABLE_BLOCK_TYPES.includes( block.name ) + ) + .map( ( block ) => block.attributes.metadata?.noteId ) + .filter( ( id ) => typeof id === 'number' ) + ) + ); + + if ( linkedNoteIds.length === 0 ) { + return false; + } + const notes = ( sel( coreStore ) as any ).getEntityRecords( 'root', 'comment', @@ -106,6 +126,7 @@ export function useEditorialUpdates(): { type: 'note', status: 'hold', post: postId, + include: Array.from( linkedNoteIds ), per_page: 1, _fields: 'id', } diff --git a/tests/e2e/specs/experiments/editorial-updates.spec.js b/tests/e2e/specs/experiments/editorial-updates.spec.js index c79416314..ca61feb1a 100644 --- a/tests/e2e/specs/experiments/editorial-updates.spec.js +++ b/tests/e2e/specs/experiments/editorial-updates.spec.js @@ -232,8 +232,14 @@ test.describe( 'Editorial Updates Experiment', () => { await admin.createNewPost( { title: 'Grouped Editorial Controls Test', - content: - 'This post has enough content to meet the minimum character requirement for the summarization feature and show the editor sidebar controls.', + } ); + + await editor.insertBlock( { + name: 'core/paragraph', + attributes: { + content: + 'This post has enough content to meet the minimum character requirement for the summarization feature and show the editor sidebar controls.', + }, } ); await editor.saveDraft(); @@ -296,6 +302,19 @@ test.describe( 'Editorial Updates Experiment', () => { await page.reload(); await editor.openDocumentSettingsSidebar(); + // Re-inject noteId after reload. + await page.evaluate( ( id ) => { + const blocks = window.wp.data + .select( 'core/block-editor' ) + .getBlocks(); + + window.wp.data + .dispatch( 'core/block-editor' ) + .updateBlockAttributes( blocks[ 0 ].clientId, { + metadata: { noteId: id }, + } ); + }, noteId ); + const notesButton = page.getByRole( 'button', { name: 'Generate Editorial Notes', } );