Skip to content

Commit 004def9

Browse files
authored
AI Assistant: fix discard handler (#35236)
* make discard handler actually handle a discard instead of having to call discard+accept in quick succession * add replaceContent on discard handler, add events
1 parent 52e1876 commit 004def9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: other
3+
4+
AI Assistant: fix discard handler so we don't need to call discard + accept

projects/plugins/jetpack/extensions/blocks/ai-assistant/edit.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId,
316316
}
317317
};
318318

319-
const handleAcceptContent = async () => {
319+
const replaceContent = async () => {
320320
let newGeneratedBlocks = [];
321321
if ( ! useGutenbergSyntax ) {
322322
/*
@@ -350,6 +350,11 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId,
350350
}
351351
};
352352

353+
const handleAcceptContent = () => {
354+
replaceContent();
355+
tracks.recordEvent( 'jetpack_ai_assistant_block_accept', { feature: 'ai-assistant' } );
356+
};
357+
353358
const handleAcceptTitle = () => {
354359
if ( isInBlockEditor ) {
355360
editPost( { title: attributes.content ? attributes.content.trim() : '' } );
@@ -359,12 +364,19 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId,
359364
}
360365
};
361366

362-
const handleTryAgain = () => {
367+
const handleDiscard = () => {
368+
const isDismiss = attributes?.content === getBlock( clientId ).attributes?.content;
363369
setAttributes( {
364370
content: attributes?.originalContent,
365371
promptType: undefined,
366372
messages: attributes?.originalMessages,
367373
} );
374+
replaceContent();
375+
if ( isDismiss ) {
376+
tracks.recordEvent( 'jetpack_ai_assistant_block_dismiss' );
377+
} else {
378+
tracks.recordEvent( 'jetpack_ai_assistant_block_discard', { feature: 'ai-assistant' } );
379+
}
368380
};
369381

370382
const handleStopSuggestion = () => {
@@ -563,7 +575,7 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId,
563575
onSend={ handleSend }
564576
onStop={ handleStopSuggestion }
565577
onAccept={ handleAccept }
566-
onDiscard={ handleTryAgain }
578+
onDiscard={ handleDiscard }
567579
state={ requestingState }
568580
isTransparent={ requireUpgrade || ! connected }
569581
showButtonLabels={ ! isMobileViewport }

0 commit comments

Comments
 (0)