-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block Bindings: Don't provide default canUserEditValue
in reducer
#63628
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
canUserEditValue
canUserEditValue
in reducer
Size Change: 0 B Total Size: 1.75 MB
ℹ️ View Unchanged
|
@@ -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(); |
There was a problem hiding this comment.
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 🤷♂️
expect( source.canUserEditValue ).toBeUndefined(); | |
expect( source.canUserEditValue ).toBeFalsy(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested this (since I'm not sure how to set up a block to use bindings, and to set the canUserEditValue
property 😅 ), but the code looks good, and the test coverage gives some confidence that it should be fine to merge 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this by changing the Post Meta source's canUserEditValue()
value to return false. That change is respected in all of the covered cases 👍
However, tangentially related to this PR, I also tested setting the Pattern Override source's canUserEditValue()
to be false, and it had no effect, both on this branch and on trunk
. Is that expected?
Lastly, the button's rel
attribute was not affected by the locking mechanism, and I realized it's because we actually never added locking logic to the button's rel
attribute. Shall we open a separate issue for that?
ff9d6df
to
cc425c3
Compare
I believe it is not expected, although it isn't a big deal because pattern overrides are expected to be editable. If I am not mistaken, it is because we are not considering the
I would consider this a different issue not related to this pull request. If I am understanding it correctly, it is already present in |
Flaky tests detected in cc425c3. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10006015082
|
What?
This was suggested here by @gziolo .
Right now, we define a default function that returns
false
in the reducer to ensure that sources are not editable unless explicitly specified. However, I believe we can avoid that and just not calling the function when it is undefined.Why?
To keep consistency with the rest of the properties that don't have a default value.
How?
I changed where we are calling
canUserEditValue
to be called conditionally. If it is not defined, it will return undefined, which will lock the editing anyways.Testing Instructions
canUserEdit
are editable. These should be tested by post-meta and pattern-overrides.canUserEdit
should be locked. This should be covered in this test.