Skip to content

Conversation

@microbit-robert
Copy link
Contributor

The basics

The details

Resolves

Fixes #9457

Proposed Changes

This PR uses all preceding inputs to create a more comprehensive field row label.

There is a scenario where this fix won't do exactly the right thing. In the case where a block has multiple branches (e.g., an if block) and also doesn't have inline text for the statement input (e.g., there is no "do"), then the entire block to the current input index is going to be output, which might be something like "Begin if true then else if false...". Thoughts on this scenario are welcome. In such situations, getFieldRowLabel could be overridden by the developer, but I wonder if a better default can be provided.

@microbit-robert microbit-robert requested a review from a team as a code owner November 3, 2025 16:35
@microbit-robert microbit-robert requested review from BenHenning and removed request for a team November 3, 2025 16:35
@github-actions github-actions bot added the PR: fix Fixes a bug label Nov 3, 2025
Copy link
Contributor

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

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

Thanks @microbit-robert! I have a couple of comments but I also want to follow up on the issue itself.

if (!fieldRowLabel) {
const inputs = this.getSourceBlock().inputList;
const index = inputs.indexOf(this);
if (index > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems necessary to keep (at least, slice will probably misbehave without this check). That being said, I'm not sure it's even possible for this scenario to logically happen in practice, but it's definitely possible just from an API perspective.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[1, 2, 3].slice(0, 0) returns [], so this should do no harm, but I'm happy to keep the check in.

});
return fields;
})
.filter(Boolean)
Copy link
Contributor

Choose a reason for hiding this comment

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

I've actually never seen this syntax 'hack'. Is it effectively the same as .filter((value) => !!value)? Which, I suppose, is simply filtering out empty and null/undefined entries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is exactly what it does in terms of API and in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: fix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants