diff --git a/projects/js-packages/ai-client/changelog/fix-ai-action-prompts b/projects/js-packages/ai-client/changelog/fix-ai-action-prompts new file mode 100644 index 0000000000000..69f2fa7c3144f --- /dev/null +++ b/projects/js-packages/ai-client/changelog/fix-ai-action-prompts @@ -0,0 +1,4 @@ +Significance: patch +Type: added + +Ai Client: use default last value (not empty), allows for handling 'one click' prompts (empty prompts) diff --git a/projects/js-packages/ai-client/src/components/ai-control/index.tsx b/projects/js-packages/ai-client/src/components/ai-control/index.tsx index 369a379a4e990..01366a5981c80 100644 --- a/projects/js-packages/ai-client/src/components/ai-control/index.tsx +++ b/projects/js-packages/ai-client/src/components/ai-control/index.tsx @@ -84,14 +84,14 @@ export function AIControl( const promptUserInputRef = useRef( null ); const loading = state === 'requesting' || state === 'suggesting'; const [ editRequest, setEditRequest ] = React.useState( false ); - const [ lastValue, setLastValue ] = React.useState( value || '' ); + const [ lastValue, setLastValue ] = React.useState( value || null ); useEffect( () => { if ( editRequest ) { promptUserInputRef?.current?.focus(); } - if ( ! editRequest && lastValue && value !== lastValue ) { + if ( ! editRequest && lastValue !== null && value !== lastValue ) { onChange?.( lastValue ); } }, [ editRequest, lastValue ] ); @@ -229,34 +229,39 @@ export function AIControl( ) } - { showAccept && ! editRequest && value?.length > 0 && ( + { showAccept && ! editRequest && (
- - - - - + { ( value?.length > 0 || lastValue === null ) && ( + + { value.length > 0 && ( + + ) } + + + + ) }