From 829f88e7f2434c5be2283c655dd53ba1fa5de48b Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Fri, 2 Jul 2021 17:47:00 +0800 Subject: [PATCH] Fix slash inserter for widgets screen (#33161) * Revert "Fix insertion point displaying when there are no inserter items (#32576)" This reverts commit 80ab980c72057644ab5efc6d367559932e51a1f2. * Avoid setting insertion point within locked templates --- .../block-list/use-in-between-inserter.js | 6 ++++ packages/block-editor/src/store/selectors.js | 12 +------ .../block-editor/src/store/test/selectors.js | 31 ------------------- 3 files changed, 7 insertions(+), 42 deletions(-) diff --git a/packages/block-editor/src/components/block-list/use-in-between-inserter.js b/packages/block-editor/src/components/block-list/use-in-between-inserter.js index 618811ec91ba64..2c385e50d181dc 100644 --- a/packages/block-editor/src/components/block-list/use-in-between-inserter.js +++ b/packages/block-editor/src/components/block-list/use-in-between-inserter.js @@ -25,6 +25,7 @@ export function useInBetweenInserter() { isBlockInsertionPointVisible, isMultiSelecting, getSelectedBlockClientIds, + getTemplateLock, } = useSelect( blockEditorStore ); const { showInsertionPoint, hideInsertionPoint } = useDispatch( blockEditorStore @@ -68,6 +69,11 @@ export function useInBetweenInserter() { rootClientId = blockElement.getAttribute( 'data-block' ); } + // Don't set the insertion point if the template is locked. + if ( getTemplateLock( rootClientId ) ) { + return; + } + const orientation = getBlockListSettings( rootClientId )?.orientation || 'vertical'; diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 30cf032ce36f4f..2ebbb5c2e8e13b 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1215,17 +1215,7 @@ export function getBlockInsertionPoint( state ) { * @return {?boolean} Whether the insertion point is visible or not. */ export function isBlockInsertionPointVisible( state ) { - const insertionPoint = state.insertionPoint; - - if ( ! state.insertionPoint ) { - return false; - } - - if ( getTemplateLock( state, insertionPoint.rootClientId ) ) { - return false; - } - - return true; + return state.insertionPoint !== null; } /** diff --git a/packages/block-editor/src/store/test/selectors.js b/packages/block-editor/src/store/test/selectors.js index 40194fad3c5c6b..0e67cc0f1d5515 100644 --- a/packages/block-editor/src/store/test/selectors.js +++ b/packages/block-editor/src/store/test/selectors.js @@ -2255,43 +2255,12 @@ 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 );