-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Permit single field disabling (#4932) #4941
Permit single field disabling (#4932) #4941
Conversation
* Fixed lint error (moved && to end of line and adjusted line breaks accordingly)
Thinking about this more, I'm assuming we'd want to include if a given field was disabled in the block serialization. I |
* Call parent method in FieldDropdown's fromXml * Added protected helper methods to handle serialization/deserialization of enabled property/attribute of fields * Minor changes to annotations to account for field disabling and 4 spaces per line break per style guide
Thanks for your PR! I have assigned someone to look at it but just as a heads up we have an internal event this week so we might be a little bit slower than normal reviewing it. Thanks for your patience! Also, since we are getting close to releasing this will most likely go into the next release. Thanks again! |
Bump @maribethb now that we're done with releasing. |
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.
This looks good to me (with some minor comments). Sorry for the long delay in reviewing. Thanks for your work on this!
@@ -202,6 +202,13 @@ Blockly.Field.prototype.isDirty_ = true; | |||
*/ | |||
Blockly.Field.prototype.visible_ = true; | |||
|
|||
/** | |||
* Can the field value be changed using the editor on an editable block? |
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.
Nit: For consistency, "Whether the field value can be changed using the editor on an editable block."
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.
Sounds good, I made the change. I'm holding off on making another commit before the serialization questions are resolved.
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.
Actually one follow-up: Should other comments be changed as well? I used a question here because some other properties were commented that way.
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.
You're right, this is consistent with how this file does it. I wasn't familiar with this style inside of Blockly before. You can just leave it like you had it. Sorry for the churn.
Ope sorry! Somehow I missed the XML stuff before. This doesn't actually need to be serialized because it's not user-facing. Since it's only triggered by devs programmatically, we should just expect devs to re-trigger it if necessary (like how warnings work). |
I added code to serialize because I noticed that if a developer sets a block's |
Hmm I thought editablility was surfaced through the context menu, but you're totally right it's only available to the developer. In that case I'm of the opinion that neither of those things should be serialized. Either (a) the developer is triggering this setting based on other state, in which case all of the relevant information is already encoded in XML, or (b) the developer is surfacing this toggle to the user themselves, in which case it is the developer's responsibility to serialize it, not Blockly's. Does that feel logical? or does it feel like I'm off the mark? Sadly we can't get rid of the existing |
That seems reasonable to me and is consistent with how other developer-only facing attributes such as a block's color are handled. Serializing these attributes may be unnecessary or even undesirable in certain applications. It can also make maintenance of the core a little more difficult. That being said, as you noted in (b), it's possible some developers may decide to make one or more of these attributes user-facing. So if there's sufficient demand, perhaps a plugin could be created to detect and serialize attributes that can be changed by a user (or allows the developer to choose some subset of them for serialization).
For consistency, we could always add a context menu item allowing users to toggle the editability of a block. But this is probably not a good idea since it might be confused with disabling a block and adds a likely seldomly used option. |
This reverts commit 1964e86.
I reverted the (de)serialization code additions. |
Fwew I'm glad it sounds ok to you. Honestly I was going back and forth on it after posting my previous message. I do like consistency, and there's no really consistent solution here :/
Yeah definitely! And if enough people ask for it we can always add it directly into core too. I'm going to leave the final review of this to @maribethb =) Thanks for hashing this out with me hehe. |
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.
Thank you and Beka for working through the xml details :)
@@ -202,6 +202,13 @@ Blockly.Field.prototype.isDirty_ = true; | |||
*/ | |||
Blockly.Field.prototype.visible_ = true; | |||
|
|||
/** | |||
* Can the field value be changed using the editor on an editable block? |
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.
You're right, this is consistent with how this file does it. I wasn't familiar with this style inside of Blockly before. You can just leave it like you had it. Sorry for the churn.
core/field_dropdown.js
Outdated
* called by Blockly.Xml. | ||
* @param {!Element} fieldElement The element containing info about the | ||
* field's state. | ||
* Sets the field's value based on the given XML element. Should only be called |
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 think you could probably remove this file from the PR now right?
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 removed the file. It's not related to the pull request anymore, but I thought I would adjust the styling of the comment by (a) moving up "field's" to the previous line since the line would have 80 characters and (b) indenting the wrapped line with 4 spaces.
Regarding (b), I noticed that there is some inconsistency with comments' styling in general as some are indented by 4 spaces when they wrap to the next line and others are not.
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.
They should ideally be indented, but there are many places they aren't currently. However, we are Soon (TM) going to be using clang-format for indentation so we will never have to think about it (or line wrapping) ever again :D So for now it's fine as long as eslint doesn't complain.
I reverted to the question form, but as was the case with the indentation of comments, I'm not sure what the expected style is. I see that Boolean properties seem to have question annotations while Boolean parameters and return values use statements? |
It does look like we have a mix of both, and the style guide seems to have no opinion, so we should just be consistent with what's nearby. |
* Permit single field disabling (#4932) * Permit single field disabling (#4932) * Fixed lint error (moved && to end of line and adjusted line breaks accordingly) * Added XML Field (De)Serialization * Call parent method in FieldDropdown's fromXml * Added protected helper methods to handle serialization/deserialization of enabled property/attribute of fields * Minor changes to annotations to account for field disabling and 4 spaces per line break per style guide * Revert "Added XML Field (De)Serialization" This reverts commit 1964e86. * Comment style changes * Comment reversions * Indentation fix * Indentation reversion
The basics
The details
Resolves
#2763, #4932
Proposed Changes
Allows the developer to specify which fields on an editable block should be disabled.
Behavior Before Change
Editors for fields would appear when clicked exactly when their source blocks were editable. This meant that the developer could not call a core Blockly method to disable a block's field without disabling all other fields on that block. To enable/disable all fields on a block, he/she could call the Block's setEditable method.
Behavior After Change
The developer can now choose which fields to disable via the newly added
Field
methodsetEnabled
. To be clickable, the field must be enabled and its source block must be editable. A field can be enabled even if its source block is non-editable, it just won't be clickable.Reason for Changes
Developers may want to disable some fields without disabling all of them.
Test Coverage
Tested locally on block with multiple fields using the different combinations (editable block/enabled field, editable block/disabled field, non-editable block/enabled field, non-editable block/disabled field).
Documentation
Probably not beyond the property/function annotations that were added/updated, which I'm assuming are autogenerated.