Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default function EditorialNotesPlugin() {
justifyContent: 'center',
width: '100%',
} }
accessibleWhenDisabled
__next40pxDefaultSize
>
{ buttonLabel }
Expand Down
18 changes: 16 additions & 2 deletions src/experiments/editorial-notes/hooks/useEditorialNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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'
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default function EditorialUpdatesPlugin() {
width: '100%',
justifyContent: 'center',
} }
accessibleWhenDisabled
>
{ buttonLabel }
</Button>
Expand Down
21 changes: 21 additions & 0 deletions src/experiments/editorial-updates/hooks/useEditorialUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,34 @@ 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',
{
type: 'note',
status: 'hold',
post: postId,
include: Array.from( linkedNoteIds ),
per_page: 1,
_fields: 'id',
}
Expand Down
23 changes: 21 additions & 2 deletions tests/e2e/specs/experiments/editorial-updates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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',
} );
Expand Down
Loading