From a1c368402c21b53e2b66442b256584a303870785 Mon Sep 17 00:00:00 2001 From: Renato Augusto Gama dos Santos Date: Thu, 2 May 2024 17:28:23 -0300 Subject: [PATCH 1/4] AI Title Optimization: Handle errors --- .../components/title-optimization/index.tsx | 55 ++++++++++++++----- .../components/title-optimization/style.scss | 2 +- 2 files changed, 41 insertions(+), 16 deletions(-) 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 496302a7a442f..0218cf0821439 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 @@ -32,6 +32,7 @@ export default function TitleOptimization( { const [ isTitleOptimizationModalVisible, setIsTitleOptimizationModalVisible ] = useState( false ); const [ generating, setGenerating ] = useState( false ); const [ options, setOptions ] = useState( [] ); + const [ error, setError ] = useState( false ); const { editPost } = useDispatch( 'core/editor' ); const { autosave } = useAutoSaveAndRedirect(); const { increaseAiAssistantRequestsCount } = useDispatch( 'wordpress-com/plans' ); @@ -61,6 +62,7 @@ export default function TitleOptimization( { const { request, stopSuggestion } = useAiSuggestions( { onDone: handleDone, onError: () => { + setError( true ); setGenerating( false ); }, } ); @@ -91,6 +93,12 @@ export default function TitleOptimization( { handleRequest(); }, [ handleRequest, placement, recordEvent, toggleTitleOptimizationModal ] ); + const handleTryAgain = useCallback( () => { + setError( false ); + setGenerating( true ); + handleRequest(); + }, [ handleRequest ] ); + const handleAccept = useCallback( ( event: MouseEvent ) => { // track the generated title acceptance @@ -140,25 +148,42 @@ export default function TitleOptimization( { ) : ( <> - - { __( 'Choose an optimized title below:', 'jetpack' ) } - - setSelected( e.target.value ) } - selected={ selected } - options={ options?.map?.( option => ( { - value: option.title, - label: option.title, - description: option.explanation, - } ) ) } - /> + { error ? ( +
+ { __( + 'It failed to generate your suggested titles. Please try again.', + 'jetpack' + ) } +
+ ) : ( + <> + + { __( 'Choose an optimized title below:', 'jetpack' ) } + + setSelected( e.target.value ) } + selected={ selected } + options={ options?.map?.( option => ( { + value: option.title, + label: option.title, + description: option.explanation, + } ) ) } + /> + + ) }
- + { error ? ( + + ) : ( + + ) }
) } diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/title-optimization/style.scss b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/title-optimization/style.scss index 74231e44d9649..79db6eca95ad5 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/title-optimization/style.scss +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/title-optimization/style.scss @@ -9,7 +9,7 @@ justify-content: center; } - &__intro { + &__intro, &__error { margin-top: 16px; } From 1b280b005890fc317067796191504456f5caf202 Mon Sep 17 00:00:00 2001 From: Renato Augusto Gama dos Santos Date: Thu, 2 May 2024 17:28:51 -0300 Subject: [PATCH 2/4] changelog --- .../plugins/jetpack/changelog/add-title-optimization-error | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/add-title-optimization-error diff --git a/projects/plugins/jetpack/changelog/add-title-optimization-error b/projects/plugins/jetpack/changelog/add-title-optimization-error new file mode 100644 index 0000000000000..d31d02f749115 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-title-optimization-error @@ -0,0 +1,4 @@ +Significance: minor +Type: other + +Add error handling on Title Optimization From 6548745484cd41be656653a4ece85746b638d62c Mon Sep 17 00:00:00 2001 From: Renato Augusto Gama dos Santos Date: Thu, 2 May 2024 17:35:17 -0300 Subject: [PATCH 3/4] AI Title Optimization: Disable entry button if no post content --- .../ai-assistant-plugin/components/title-optimization/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0218cf0821439..768cf7a985c6e 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 @@ -128,7 +128,7 @@ export default function TitleOptimization( {

{ __( 'Use AI to optimize key details of your post.', 'jetpack' ) }