Skip to content

Commit 294ac6c

Browse files
authored
Fix orderer bug that was adding null/undefined values to user input (#2760)
## Summary: When we briefly turned on serverside scoring for Khan Academy, we saw errors like this coming from the Perseus service: ``` Failed to parse user input map: At (root)["orderer 1"].current[0] -- expected string, but got null ``` These nulls were erroneously getting into the user input because of a bug in the UI. This PR fixes the bug. The Orderer is not accessible and not recommended for use, so I am applying the minimal fix. Issue: https://khanacademy.atlassian.net/browse/LEMS-3343 ## Test plan: In Storybook, drag a few cards into an Orderer. Try to reorder the cards. A broken-looking "ghost card" will appear. Try dragging and dropping the ghost into the orderer. It should disappear. Author: benchristel Reviewers: benchristel, handeyeco, Myranae Required Reviewers: Approved By: handeyeco Checks: ✅ 10 checks were successful Pull Request URL: #2760
1 parent 962f89a commit 294ac6c

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

.changeset/purple-bulldogs-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/perseus": patch
3+
---
4+
5+
Fix a bug in Orderer that allowed learners to add cards with null content.

packages/perseus/src/widgets/orderer/orderer.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,18 @@ class Orderer
411411
const list = this.props.userInput.current.slice();
412412

413413
if (!inCardBank) {
414-
// Insert the new card into the position
415-
const newCard = {
416-
content: this.state.dragContent,
417-
key: _.uniqueId("perseus_draggable_card_"),
418-
width: this.state.dragWidth,
419-
} as const;
420-
421-
list.splice(index, 0, newCard.content);
414+
const cardContent: string | null | undefined =
415+
this.state.dragContent;
416+
if (typeof cardContent === "string") {
417+
// Insert the new card into the position
418+
const newCard = {
419+
content: cardContent,
420+
key: _.uniqueId("perseus_draggable_card_"),
421+
width: this.state.dragWidth,
422+
} as const;
423+
424+
list.splice(index, 0, newCard.content);
425+
}
422426
}
423427

424428
this.props.handleUserInput({

0 commit comments

Comments
 (0)