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

useNestedSettingsUpdate: prevent unneeded syncing of falsy templateLock values #46357

Merged
merged 1 commit into from
Dec 8, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ _Parameters_

_Returns_

- `?string`: Block Template Lock
- `string|false`: Block Template Lock

### hasBlockMovingClientId

Expand Down
11 changes: 3 additions & 8 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1425,19 +1425,14 @@ export function getTemplate( state ) {
* @param {Object} state Editor state.
* @param {?string} rootClientId Optional block root client ID.
*
* @return {?string} Block Template Lock
* @return {string|false} Block Template Lock
*/
export function getTemplateLock( state, rootClientId ) {
if ( ! rootClientId ) {
return state.settings.templateLock;
return state.settings.templateLock ?? false;
}

const blockListSettings = getBlockListSettings( state, rootClientId );
if ( ! blockListSettings ) {
return undefined;
}

return blockListSettings.templateLock;
return getBlockListSettings( state, rootClientId )?.templateLock ?? false;
}

const checkAllowList = ( list, item, defaultResult = null ) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3733,15 +3733,15 @@ describe( 'selectors', () => {
} );

describe( 'getTemplateLock', () => {
it( 'should return the general template lock if no clientId was set', () => {
it( 'should return the general template lock if no clientId was specified', () => {
const state = {
settings: { templateLock: 'all' },
};

expect( getTemplateLock( state ) ).toBe( 'all' );
} );

it( 'should return undefined if the specified clientId was not found', () => {
it( 'should return false if the specified clientId was not found', () => {
const state = {
settings: { templateLock: 'all' },
blockListSettings: {
Expand All @@ -3751,10 +3751,10 @@ describe( 'selectors', () => {
},
};

expect( getTemplateLock( state, 'ribs' ) ).toBe( undefined );
expect( getTemplateLock( state, 'ribs' ) ).toBe( false );
} );

it( 'should return undefined if template lock was not set on the specified block', () => {
it( 'should return false if template lock was not set on the specified block', () => {
const state = {
settings: { templateLock: 'all' },
blockListSettings: {
Expand All @@ -3764,7 +3764,7 @@ describe( 'selectors', () => {
},
};

expect( getTemplateLock( state, 'ribs' ) ).toBe( undefined );
expect( getTemplateLock( state, 'chicken' ) ).toBe( false );
} );

it( 'should return the template lock for the specified clientId', () => {
Expand Down