Skip to content

Commit

Permalink
fix(LEMS-2738): Convert Expression Editor Answer keys to strings (#2042)
Browse files Browse the repository at this point in the history
## Summary:
- Converts expression editor keys to strings
- Updates `onDelete` handler to use index instead of key

Issue: LEMS-2738

## Test plan:


https://github.com/user-attachments/assets/60424f5a-f654-4afc-901f-de47505e053c

Author: anakaren-rojas

Reviewers: catandthemachines, anakaren-rojas

Required Reviewers:

Approved By: catandthemachines

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ⏹️  [cancelled] Publish npm snapshot (ubuntu-latest, 20.x), ⏹️  [cancelled] Check builds for changes in size (ubuntu-latest, 20.x), ⏹️  [cancelled] Cypress (ubuntu-latest, 20.x), ⏹️  [cancelled] Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏹️  [cancelled] Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ⏹️  [cancelled] Publish npm snapshot (ubuntu-latest, 20.x), ⏹️  [cancelled] Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏹️  [cancelled] Cypress (ubuntu-latest, 20.x), ⏹️  [cancelled] Check builds for changes in size (ubuntu-latest, 20.x), ⏹️  [cancelled] Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ⏹️  [cancelled] Publish npm snapshot (ubuntu-latest, 20.x), ⏹️  [cancelled] Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ⏹️  [cancelled] Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏹️  [cancelled] Check builds for changes in size (ubuntu-latest, 20.x), ⏹️  [cancelled] Cypress (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x)

Pull Request URL: #2042
  • Loading branch information
anakaren-rojas authored Dec 20, 2024
1 parent ab294b6 commit 705d74b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-bugs-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus-editor": patch
---

fix for editor
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe("expression-editor", () => {
{
considered: "correct",
form: false,
key: 0,
key: "0",
simplify: false,
value: "",
},
Expand Down
14 changes: 10 additions & 4 deletions packages/perseus-editor/src/widgets/expression-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ class ExpressionEditor extends React.Component<Props, State> {
};

_newEmptyAnswerForm: () => any = () => {
const newKey = _makeNewKey(this.props.answerForms);
return {
considered: "correct",
form: false,

// note: the key means "n-th form created" - not "form in
// position n" and will stay the same for the life of this form
key: _makeNewKey(this.props.answerForms),
key: `${newKey}`,

simplify: false,
value: "",
Expand All @@ -211,7 +212,11 @@ class ExpressionEditor extends React.Component<Props, State> {
handleRemoveForm: (answerKey: number) => void = (i) => {
const answerForms = this.props.answerForms.slice();
answerForms.splice(i, 1);
this.change({answerForms});
const updatedAnswerForms = answerForms.map((form, index) => ({
...form,
key: `${index}`,
}));
this.change({answerForms: updatedAnswerForms});
};

// This function is designed to update the answerForm property
Expand Down Expand Up @@ -344,7 +349,7 @@ class ExpressionEditor extends React.Component<Props, State> {

render(): React.ReactNode {
const answerOptions: React.JSX.Element[] = this.props.answerForms.map(
(ans: AnswerForm) => {
(ans: AnswerForm, index: number) => {
const key = parseAnswerKey(ans);

const expressionProps: Partial<
Expand Down Expand Up @@ -376,7 +381,7 @@ class ExpressionEditor extends React.Component<Props, State> {
expressionProps={expressionProps}
form={ans.form}
simplify={ans.simplify}
onDelete={() => this.handleRemoveForm(key)}
onDelete={() => this.handleRemoveForm(index)}
onChangeSimplify={(simplify) =>
this.changeSimplify(key, simplify)
}
Expand Down Expand Up @@ -565,6 +570,7 @@ class AnswerOption extends React.Component<

handleImSure = () => {
this.props.onDelete();
this.handleCancelDelete();
};

handleCancelDelete = () => {
Expand Down

0 comments on commit 705d74b

Please sign in to comment.