From cded5c9c92fc20d5266857710164d009ae68747f Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Fri, 7 Feb 2025 13:01:12 -0300 Subject: [PATCH 1/3] include for option messages --- .../ai-assistant-plugin/components/seo-assistant/types.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/types.tsx b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/types.tsx index 4556ec26f338e..5b4289ea12717 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/types.tsx +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/types.tsx @@ -9,7 +9,7 @@ export interface Message { selected?: boolean; } -export type OptionMessage = Pick< Message, 'id' | 'content' >; +export type OptionMessage = Pick< Message, 'id' | 'content' | 'selected' >; export interface Results { [ key: string ]: { From bb4f6c4d5eedea4f8deea21f8496ed7ac9e11b61 Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Fri, 7 Feb 2025 13:03:41 -0300 Subject: [PATCH 2/3] split step values from selected values, add hasSelection output prop, lower delay mocks --- .../components/seo-assistant/assistant-wizard.tsx | 4 ++-- .../components/seo-assistant/types.tsx | 1 + .../components/seo-assistant/use-completion-step.tsx | 2 +- .../seo-assistant/use-meta-description-step.tsx | 12 +++++++++--- .../components/seo-assistant/use-title-step.tsx | 8 ++++++-- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/assistant-wizard.tsx b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/assistant-wizard.tsx index 52ba9934a9830..8e70f96f625ca 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/assistant-wizard.tsx +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/assistant-wizard.tsx @@ -221,7 +221,7 @@ export default function AssistantWizard( { close } ) { ) } { currentStep === 2 && steps[ currentStep ].type === 'options' && ( void; retryCtaLabel?: string; + hasSelection?: boolean; } diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-completion-step.tsx b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-completion-step.tsx index 50ad239eeb007..e9c692b011d19 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-completion-step.tsx +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-completion-step.tsx @@ -20,7 +20,7 @@ export const useCompletionStep = (): Step => { } setMessages( firstMessages ); - await new Promise( resolve => setTimeout( resolve, 1500 ) ); + await new Promise( resolve => setTimeout( resolve, 1000 ) ); const resultsString = Object.values( results ) .map( ( result: Results[ string ] ) => `${ result.value ? '✅' : '❌' } ${ result.label }` ) diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-meta-description-step.tsx b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-meta-description-step.tsx index ae19e91052a98..1f767f59b30a3 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-meta-description-step.tsx +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-meta-description-step.tsx @@ -13,6 +13,7 @@ import { useMessages } from './wizard-messages'; import type { Step, OptionMessage } from './types'; export const useMetaDescriptionStep = ( { keywords }: { keywords: string } ): Step => { + const [ value, setValue ] = useState< string >(); const [ selectedMetaDescription, setSelectedMetaDescription ] = useState< string >(); const [ metaDescriptionOptions, setMetaDescriptionOptions ] = useState< OptionMessage[] >( [] ); const { messages, setMessages, addMessage, editLastMessage, setSelectedMessage } = useMessages(); @@ -47,6 +48,9 @@ export const useMetaDescriptionStep = ( { keywords }: { keywords: string } ): St ( option: OptionMessage ) => { setSelectedMetaDescription( option.content as string ); setSelectedMessage( option ); + setMetaDescriptionOptions( prev => + prev.map( o => ( { ...o, selected: o.id === option.id } ) ) + ); }, [ setSelectedMessage ] ); @@ -67,6 +71,7 @@ export const useMetaDescriptionStep = ( { keywords }: { keywords: string } ): St }, [ generatedCount, request ] ); const handleMetaDescriptionSubmit = useCallback( async () => { + setValue( selectedMetaDescription ); await editPost( { meta: { advanced_seo_description: selectedMetaDescription } } ); addMessage( { content: __( 'Meta description updated! ✅', 'jetpack' ) } ); return selectedMetaDescription; @@ -87,8 +92,8 @@ export const useMetaDescriptionStep = ( { keywords }: { keywords: string } ): St showIcon: true, }; let newMetaDescriptions = [ ...metaDescriptionOptions ]; - // we only generate if options are empty setMessages( [ initialMessage ] ); + // we only generate if options are empty if ( newMetaDescriptions.length === 0 ) { newMetaDescriptions = await getMetaDescriptions(); } @@ -133,8 +138,9 @@ export const useMetaDescriptionStep = ( { keywords }: { keywords: string } ): St onRetry: handleMetaDescriptionRegenerate, retryCtaLabel: __( 'Regenerate', 'jetpack' ), onStart: handleMetaDescriptionGenerate, - value: selectedMetaDescription, - setValue: setSelectedMetaDescription, + value, + setValue, includeInResults: true, + hasSelection: !! selectedMetaDescription, }; }; diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-title-step.tsx b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-title-step.tsx index 289f73c86948c..7bbdde6a2b5a0 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-title-step.tsx +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/seo-assistant/use-title-step.tsx @@ -13,6 +13,7 @@ import { useMessages } from './wizard-messages'; import type { Step, OptionMessage } from './types'; export const useTitleStep = ( { keywords }: { keywords: string } ): Step => { + const [ value, setValue ] = useState< string >( '' ); const [ selectedTitle, setSelectedTitle ] = useState< string >( '' ); const [ titleOptions, setTitleOptions ] = useState< OptionMessage[] >( [] ); const { editPost } = useDispatch( 'core/editor' ); @@ -47,6 +48,7 @@ export const useTitleStep = ( { keywords }: { keywords: string } ): Step => { ( option: OptionMessage ) => { setSelectedTitle( option.content as string ); setSelectedMessage( option ); + setTitleOptions( prev => prev.map( o => ( { ...o, selected: o.id === option.id } ) ) ); }, [ setSelectedMessage ] ); @@ -135,6 +137,7 @@ export const useTitleStep = ( { keywords }: { keywords: string } ): Step => { }, [ addMessage, getTitles, titleOptions ] ); const handleTitleSubmit = useCallback( async () => { + setValue( selectedTitle ); await editPost( { title: selectedTitle, meta: { jetpack_seo_html_title: selectedTitle } } ); addMessage( { content: __( 'Title updated! ✅', 'jetpack' ) } ); return selectedTitle; @@ -153,8 +156,9 @@ export const useTitleStep = ( { keywords }: { keywords: string } ): Step => { onRetry: handleTitleRegenerate, retryCtaLabel: __( 'Regenerate', 'jetpack' ), onStart: handleTitleGenerate, - value: selectedTitle, - setValue: setSelectedTitle, + value, + setValue, includeInResults: true, + hasSelection: !! selectedTitle, }; }; From 2fabb2e3df0e20b6c1b22f8a93479c3af82a859a Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Fri, 7 Feb 2025 13:09:08 -0300 Subject: [PATCH 3/3] changelog --- .../jetpack/changelog/fix-jetpack-seo-persist-selected-option | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/fix-jetpack-seo-persist-selected-option diff --git a/projects/plugins/jetpack/changelog/fix-jetpack-seo-persist-selected-option b/projects/plugins/jetpack/changelog/fix-jetpack-seo-persist-selected-option new file mode 100644 index 0000000000000..d39368689bd18 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-jetpack-seo-persist-selected-option @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Jetpack SEO assistant: persist selected options if they haven't changed