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
Katleiah/gb danceparty fielddropdown #44313
Conversation
const isMissingSecondValue = menuGenerator.some( | ||
entry => entry.length === 1 | ||
); | ||
|
||
if (isMissingSecondValue) { | ||
menuGenerator = menuGenerator.map(entry => { | ||
return [entry[0], entry[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.
I think Ideally we could move a lot of this logic out of the constructor and into their own methods, but when I did that I got an error that I couldn't call this
before super()
. Open to ideas, but also ok leaving it here if that ends up making the most sense.
0705e89
to
4354c6d
Compare
apps/src/block_utils.js
Outdated
dropdownOptions.forEach(option => { | ||
if (option.length === 1) { | ||
newOptions.push([option[0], option[0]]); | ||
} else { | ||
newOptions.push(option); | ||
} | ||
}); |
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 this is a slightly more performant way to handle the logic. Let me know if you think this change makes sense!
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: might be slightly cleaner as a map like return options.map(option => option.length === 1 ? [option[0], option[0]] : option)
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 like doing this in a separate function so that we can have a doc comment for it :)
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.
great idea! updated here: eed89ab
apps/src/block_utils.js
Outdated
/** | ||
* Adds a second value to options array elements if a second one does not exist. | ||
* The second value is used as the generated code for that option. | ||
* Also required for backwards compatibility with existing blocks that are missing the second value. |
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.
tiny nit: remove "also"
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.
updated here: eed89ab!
Existing error:
Links
Jira Ticket
Testing story
Manually Testing:
PR Checklist: