diff --git a/projects/plugins/jetpack/changelog/change-jetpack-ai-list-to-table-top-level-only b/projects/plugins/jetpack/changelog/change-jetpack-ai-list-to-table-top-level-only
new file mode 100644
index 0000000000000..305409b4615a8
--- /dev/null
+++ b/projects/plugins/jetpack/changelog/change-jetpack-ai-list-to-table-top-level-only
@@ -0,0 +1,4 @@
+Significance: patch
+Type: other
+
+Jetpack AI: Only display "turn list into table" menu item for top level lists
diff --git a/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/ai-assistant-toolbar-dropdown/dropdown-content.tsx b/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/ai-assistant-toolbar-dropdown/dropdown-content.tsx
index 51bd269c5f849..85559ab42c041 100644
--- a/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/ai-assistant-toolbar-dropdown/dropdown-content.tsx
+++ b/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/ai-assistant-toolbar-dropdown/dropdown-content.tsx
@@ -3,6 +3,7 @@
*/
import { aiAssistantIcon } from '@automattic/jetpack-ai-client';
import { MenuItem, MenuGroup, Notice } from '@wordpress/components';
+import { select } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { post, postContent, postExcerpt, termDescription, blockTable } from '@wordpress/icons';
import React from 'react';
@@ -160,6 +161,7 @@ if ( getFeatureAvailability( 'ai-list-to-table-transform' ) ) {
options: {
userPrompt: 'make a table from this list, do not enclose the response in a code block',
alwaysTransformToAIAssistant: true,
+ rootParentOnly: true,
},
} );
}
@@ -169,6 +171,7 @@ export type AiAssistantDropdownOnChangeOptionsArgProps = {
language?: string;
userPrompt?: string;
alwaysTransformToAIAssistant?: boolean;
+ rootParentOnly?: boolean;
};
export type OnRequestSuggestion = (
@@ -182,6 +185,7 @@ type AiAssistantToolbarDropdownContentProps = {
disabled?: boolean;
onAskAiAssistant: () => void;
onRequestSuggestion: OnRequestSuggestion;
+ clientId: string;
};
/**
@@ -191,12 +195,18 @@ type AiAssistantToolbarDropdownContentProps = {
*/
export default function AiAssistantToolbarDropdownContent( {
blockType,
+ clientId,
disabled = false,
onAskAiAssistant,
onRequestSuggestion,
}: AiAssistantToolbarDropdownContentProps ): ReactElement {
const blockQuickActions = quickActionsList[ blockType ] ?? [];
+ const { getBlockParents } = select( 'core/block-editor' ) as unknown as {
+ getBlockParents: ( blockId: string ) => string[];
+ };
+ const blockParents = getBlockParents( clientId );
+
return (
<>
{ disabled && (
@@ -218,23 +228,29 @@ export default function AiAssistantToolbarDropdownContent( {
- { [ ...quickActionsList.default, ...blockQuickActions ].map( quickAction => (
-
- ) ) }
+ { [ ...quickActionsList.default, ...blockQuickActions ]
+ .filter(
+ quickAction => ! ( quickAction.options?.rootParentOnly && blockParents.length > 0 )
+ )
+ .map( quickAction => {
+ return (
+
+ );
+ } ) }
{
diff --git a/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/ai-assistant-toolbar-dropdown/index.tsx b/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/ai-assistant-toolbar-dropdown/index.tsx
index b21e4768532e3..8f30ed0e5f9c4 100644
--- a/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/ai-assistant-toolbar-dropdown/index.tsx
+++ b/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/ai-assistant-toolbar-dropdown/index.tsx
@@ -144,9 +144,12 @@ function AiAssistantBlockToolbarDropdownContent( {
tracks.recordEvent( 'jetpack_ai_assistant_prompt_show', { block_type: blockType } );
};
+ const [ clientId ] = getSelectedBlockClientIds();
+
return (