From b1f867e8328dac4b92352e50573722a25c0e9a3a Mon Sep 17 00:00:00 2001 From: Luiz Kowalski Date: Fri, 27 Sep 2024 14:54:38 -0300 Subject: [PATCH] Title Optimization: improve button behavior on error screen (#39554) * Properly close the modal when Cancel is clicked, cleaning up the state * Skip new generation on try again button when there are options already * Changelog --- ...e-jetpack-ai-reset-error-on-title-optimization | 4 ++++ .../components/title-optimization/index.tsx | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/update-jetpack-ai-reset-error-on-title-optimization diff --git a/projects/plugins/jetpack/changelog/update-jetpack-ai-reset-error-on-title-optimization b/projects/plugins/jetpack/changelog/update-jetpack-ai-reset-error-on-title-optimization new file mode 100644 index 0000000000000..9a27b121659f1 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-jetpack-ai-reset-error-on-title-optimization @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Title Optimization: improve button behaviors when handling errors. diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/title-optimization/index.tsx b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/title-optimization/index.tsx index 01acfac40d607..876ee493e2929 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/title-optimization/index.tsx +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/title-optimization/index.tsx @@ -177,8 +177,16 @@ export default function TitleOptimization( { const handleTryAgain = useCallback( () => { setError( null ); - handleRequest( true ); // retry the generation - }, [ handleRequest ] ); + + /** + * Only try to generate again if there are no options available. + * If there are options, show them so the user can choose one + * or ask for new suggestions. + */ + if ( options.length === 0 ) { + handleRequest( true ); // retry the generation + } + }, [ handleRequest, options ] ); const handleTitleOptimizationWithKeywords = useCallback( () => { handleRequest(); @@ -204,6 +212,7 @@ export default function TitleOptimization( { ); const handleClose = useCallback( () => { + setError( null ); toggleTitleOptimizationModal(); setOptimizationKeywords( '' ); stopSuggestion(); @@ -275,7 +284,7 @@ export default function TitleOptimization( { ) }
- { showTryAgainButton && (