Skip to content

Commit

Permalink
Fix insertion point displaying when there are no inserter items (#32576)
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan authored and youknowriad committed Jun 21, 2021
1 parent ba36475 commit 76a2281
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
31 changes: 31 additions & 0 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 76a2281

Please sign in to comment.