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 label ordering #22388
Fix label ordering #22388
Conversation
I liked the way I set up app-sepcific input types so much I converted all of the standard inputs the same 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.
This is great!
I'd love to see some tests
apps/src/block_utils.js
Outdated
* @param {object} customInputTypes A map of customType input names to their | ||
* definitions, which are objects that have `addInput` and `generateCode` | ||
* @param {object} inputTypes A map of input types to their definitions, which | ||
* are objects that have `addInput` and `generateCode` |
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: could we get a jsdoc @typedef
for input definitions?
apps/src/block_utils.js
Outdated
} | ||
}); | ||
const lastRow = inputRows[inputRows.length - 1]; | ||
if (inputRows[inputRows.length - 1].length > 0) { |
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: could just be lastRow.length
return Blockly.JavaScript.valueToCode(this, arg.name, ORDER_COMMA); | ||
} | ||
const inputConfig = inputConfigs.find(input => input.name === arg.name); | ||
return inputTypes[inputConfig.mode].generateCode(this, inputConfig); |
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 are some (clearly insufficient) unit tests in |
Trailing labels aren't being rendered correctly under the current custom block parser, e.g.:
Before:
After:
Things get really weird with multi-line blocks:
Before:
After:
The code change to make this happen was grouping inputs into
inputRows
and handling each one independently (replacing the broken and uglygetPreviousInput
approach I had tried earlier). EachinputRow
is just a group of inputs ending with a line-ending input, i.e. a value, statement, or dummy input. The labels and field inputs in each row can now be assembled in a fairly straightforward way:code-dot-org/apps/src/block_utils.js
Lines 577 to 590 in 33d6e59
For inline blocks, the rows all just string together in a long line, looking just like
blockText
(but a block),The other bit of refactoring that made sense to do here was adopting the
customInputTypes
config format for all the input types (this is the thing I added for the location picker input in #21955).