From 0c95202e57461b248502e0030a5c7f1a1166b137 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 7 Jan 2022 11:25:04 +0200 Subject: [PATCH] use `isSelected` prop and only show on top level blocks --- .../block-library/src/query/edit/index.js | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/query/edit/index.js b/packages/block-library/src/query/edit/index.js index ab75bdcaeb084d..84aaff2ff7f036 100644 --- a/packages/block-library/src/query/edit/index.js +++ b/packages/block-library/src/query/edit/index.js @@ -29,13 +29,14 @@ import { getFirstQueryClientIdFromBlocks } from '../utils'; const TEMPLATE = [ [ 'core/post-template' ] ]; -function ResetQueryLoopMenuItem( { clientId } ) { - const selectedBlockClientId = useSelect( - ( select ) => select( blockEditorStore ).getSelectedBlockClientId(), - [] +function ResetQueryLoopMenuItem( { clientId, isSelected } ) { + const rootClientId = useSelect( + ( select ) => + select( blockEditorStore ).getBlockRootClientId( clientId ), + [ clientId ] ); const { replaceInnerBlocks } = useDispatch( blockEditorStore ); - if ( selectedBlockClientId !== clientId ) { + if ( ! isSelected || rootClientId ) { return null; } return ( @@ -55,7 +56,12 @@ function ResetQueryLoopMenuItem( { clientId } ) { ); } -export function QueryContent( { attributes, setAttributes, clientId } ) { +export function QueryContent( { + attributes, + setAttributes, + clientId, + isSelected, +} ) { const { queryId, query, @@ -132,7 +138,10 @@ export function QueryContent( { attributes, setAttributes, clientId } ) { setDisplayLayout={ updateDisplayLayout } /> - +