Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slash inserter for widgets screen #33161

Merged
merged 2 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function useInBetweenInserter() {
isBlockInsertionPointVisible,
isMultiSelecting,
getSelectedBlockClientIds,
getTemplateLock,
} = useSelect( blockEditorStore );
const { showInsertionPoint, hideInsertionPoint } = useDispatch(
blockEditorStore
Expand Down Expand Up @@ -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';
Expand Down
12 changes: 1 addition & 11 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

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