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

Block Bindings: Don't provide default canUserEditValue in reducer #63628

Merged
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
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function RichTextWrapper(
binding.source
);
if (
! blockBindingsSource?.canUserEditValue( {
! blockBindingsSource?.canUserEditValue?.( {
select,
context: blockContext,
args: binding.args,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function ButtonEdit( props ) {
return {
lockUrlControls:
!! metadata?.bindings?.url &&
! blockBindingsSource?.canUserEditValue( {
! blockBindingsSource?.canUserEditValue?.( {
select,
context,
args: metadata?.bindings?.url?.args,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export function ImageEdit( {
return {
lockUrlControls:
!! metadata?.bindings?.url &&
! blockBindingsSource?.canUserEditValue( {
! blockBindingsSource?.canUserEditValue?.( {
select,
context,
args: metadata?.bindings?.url?.args,
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export default function Image( {
return {
lockUrlControls:
!! urlBinding &&
! urlBindingSource?.canUserEditValue( {
! urlBindingSource?.canUserEditValue?.( {
select,
context,
args: urlBinding?.args,
Expand All @@ -494,7 +494,7 @@ export default function Image( {
hasParentPattern,
lockAltControls:
!! altBinding &&
! altBindingSource?.canUserEditValue( {
! altBindingSource?.canUserEditValue?.( {
select,
context,
args: altBinding?.args,
Expand All @@ -508,7 +508,7 @@ export default function Image( {
: __( 'Connected to dynamic data' ),
lockTitleControls:
!! titleBinding &&
! titleBindingSource?.canUserEditValue( {
! titleBindingSource?.canUserEditValue?.( {
select,
context,
args: titleBinding?.args,
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ describe( 'blocks', () => {
expect( source.setValue ).toBeUndefined();
expect( source.setValues ).toBeUndefined();
expect( source.getPlaceholder ).toBeUndefined();
expect( source.canUserEditValue() ).toBe( false );
expect( source.canUserEditValue ).toBeUndefined();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also .toBeFalsy() (which is a slightly looser assertion and would work both with and without the other changes in this PR, thus "bridging" the change).

It's also a really small detail, so feel free to ignore 🤷‍♂️

Suggested change
expect( source.canUserEditValue ).toBeUndefined();
expect( source.canUserEditValue ).toBeFalsy();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about that, thanks for the tip 🙂 On the other hand, I prefer keeping it undefined to keep consistency with the rest of the properties, and because it is actually expected to be undefined and not false after these changes.

unregisterBlockBindingsSource( 'core/valid-source' );
} );

Expand Down
3 changes: 1 addition & 2 deletions packages/blocks/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,7 @@ export function blockBindingsSources( state = {}, action ) {
setValue: action.setValue,
setValues: action.setValues,
getPlaceholder: action.getPlaceholder,
canUserEditValue:
action.canUserEditValue || ( () => false ),
canUserEditValue: action.canUserEditValue,
},
};
case 'REMOVE_BLOCK_BINDINGS_SOURCE':
Expand Down
Loading