-
Notifications
You must be signed in to change notification settings - Fork 357
docs(changeset): Fixed bugs related to numCorrect not updating properly for the Radio widget #2630
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
base: um-correct
Are you sure you want to change the base?
Conversation
… updating properly for the Radio widget
Size Change: -55 B (-0.01%) Total Size: 472 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (2cccb7c) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2630 If you are working in Khan Academy's frontend, you can run the below command. ./tools/bump_perseus_version.js -t PR2630 If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -s n -t PR2630 |
let choices = this.props.choices; | ||
if (!multipleSelect) { | ||
const numCorrect = _.reduce( | ||
this.props.choices, |
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.
Should this be the local choices
object defined on line 123?
// we need to deselect all options | ||
let choices = this.props.choices; | ||
if (!multipleSelect) { | ||
const numCorrect = _.reduce( |
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.
Would this be a good time to remove underscore, or would that be a big distraction from the purpose of this PR?
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.
Let's do it! I'm down for any excuse to remove it
this.props.onChange({ | ||
multipleSelect: allowMultiple, | ||
}); | ||
const multipleSelect = allowMultiple.multipleSelect; |
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.
Do we have a naming convention for boolean values like this? For instance, isMultipleSelect
?
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.
Tbh I don't know! It just bugged me that we were extracting multipleSelect out of allowMultiple and then calling it allowMultiple. 😅 I'm happy to make it isMultipleSelect though!
// Check that multipleSelect is updated and numCorrect is calculated | ||
expect(onChangeMock).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
numCorrect: expect.any(Number), |
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.
How does this show that numCorrect
has been calculated?
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.
It doesn't! Apparently my tired Friday brain didn't quite finish up this PR. I've fixed this up quite a bit!
it("updates numCorrect when deleting an option", async () => { | ||
const onChangeMock = jest.fn(); | ||
|
||
function getCorrectChoice(): PerseusRadioChoice { |
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.
Can this function and its "incorrect" counterpart be hoisted to the describe
parent instead of rebuilt for each test?
@@ -116,39 +116,44 @@ class RadioEditor extends React.Component<RadioEditorProps> { | |||
}; | |||
|
|||
onMultipleSelectChange: (arg1: any) => any = (allowMultiple) => { | |||
allowMultiple = allowMultiple.multipleSelect; | |||
|
|||
const numCorrect = _.reduce( |
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.
No idea why were were doing this manually every time. We already have a nifty little method to handle this (deriveNumCorrect)!
const countChoices = count.countChoices; | ||
this.props.onChange({ | ||
countChoices, | ||
}); | ||
}; |
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 was silly naming, imo.
|
||
return numCorrect ?? choices.filter((c) => c.correct).length; | ||
return choices.filter((c) => c.correct).length; | ||
} |
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 could be a spicy move, but I really don't understand why we were ever returning numCorrect
in the first place, as everything I saw indicates that we always want to recalculate this value.
This is only used in the radio editor.tsx
file with undefined
for numCorrect
, and in our parser for converting a Radio widget from v1 to a v2 as v1 did not have this option.
… updating properly for the Radio widget, and cleaning up deriveNumCorrect.
|
||
return numCorrect ?? choices.filter((c) => c.correct).length; | ||
export function deriveNumCorrect( | ||
choices: PerseusRadioWidgetOptions["choices"], |
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.
should this be destructured?
choices: PerseusRadioWidgetOptions["choices"], | |
{choices} : PerseusRadioWidgetOptions, |
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.
Oooo it could, but I think we've generally used the first format 🤔.
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.
🌶️ move checks out
Summary:
We had 2 bugs reported related to the numCorrect value not correctly updating for the Radio Widget.
This PR fixes two of these bugs by ensuring that we're recalculating the numCorrect value when we delete choices, or switch in and out of multiple selection mode.
Unfortunately, I have not been able to recreate the third bug in the ticket.
Issue: LEMS-3230
Test plan: