From 80ab980c72057644ab5efc6d367559932e51a1f2 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Wed, 16 Jun 2021 08:09:56 +0800 Subject: [PATCH] Fix insertion point displaying when there are no inserter items (#32576) --- packages/block-editor/src/store/selectors.js | 12 ++++++- .../block-editor/src/store/test/selectors.js | 31 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 2ebbb5c2e8e13..30cf032ce36f4 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1215,7 +1215,17 @@ export function getBlockInsertionPoint( state ) { * @return {?boolean} Whether the insertion point is visible or not. */ export function isBlockInsertionPointVisible( state ) { - return state.insertionPoint !== null; + const insertionPoint = state.insertionPoint; + + if ( ! state.insertionPoint ) { + return false; + } + + if ( getTemplateLock( state, insertionPoint.rootClientId ) ) { + return false; + } + + return true; } /** diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index 0e67cc0f1d551..40194fad3c5c6 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -2255,12 +2255,43 @@ describe( 'selectors', () => { expect( isBlockInsertionPointVisible( state ) ).toBe( false ); } ); + it( 'should return false if the rootClientId has a truthy template lock', () => { + const state = { + insertionPoint: { + rootClientId: 'testClientId', + index: 5, + }, + blockListSettings: { + testClientId: { + templateLock: 'all', + }, + }, + }; + + expect( isBlockInsertionPointVisible( state ) ).toBe( false ); + } ); + + it( 'should return false if the rootClientId is undefined, and the settings has a template lock', () => { + const state = { + insertionPoint: { + rootClientId: undefined, + index: 5, + }, + settings: { + templateLock: 'all', + }, + }; + + expect( isBlockInsertionPointVisible( state ) ).toBe( false ); + } ); + it( 'should return true if assigned insertion point', () => { const state = { insertionPoint: { rootClientId: undefined, index: 5, }, + settings: {}, }; expect( isBlockInsertionPointVisible( state ) ).toBe( true );