Skip to content

Conversation

@nishasy
Copy link
Contributor

@nishasy nishasy commented Oct 24, 2025

Summary:

Implement the save warnings for the expression widget within the new save warning utility.

Issue: https://khanacademy.atlassian.net/browse/LEMS-3643

Test plan:

pnpm jest packages/perseus/src/util/get-save-warnings-for-item.test.ts

Storybook
/?path=/story/editors-editorpage--with-save-warnings-new-util

Issue Save warning
no answers image
empty answer Screenshot 2025-10-24 at 1 34 56 PM
No correct answer image
Could not parse image
Simplification required image

…dget warnings

Implement the save warnings for the expression widget within the new save warning utility.

Issue: https://khanacademy.atlassian.net/browse/LEMS-3643

Test plan:
`pnpm jest packages/perseus/src/util/get-save-warnings-for-item.test.ts`

Storybook
`/?path=/story/editors-editorpage--with-save-warnings-new-util`
…arnings to new save warning utility. Not ready for use yet.
@nishasy nishasy self-assigned this Oct 24, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2025

🗄️ Schema Change: No Changes ✅

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2025

🛠️ Item Splitting: No Changes ✅

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2025

Size Change: +224 B (+0.05%)

Total Size: 498 kB

Filename Size Change
packages/perseus-core/dist/es/index.js 23.3 kB +224 B (+0.97%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.8 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 5.98 kB
packages/math-input/dist/es/index.js 99.2 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.item-splitting.js 13.1 kB
packages/perseus-editor/dist/es/index.js 96.6 kB
packages/perseus-linter/dist/es/index.js 7.21 kB
packages/perseus-score/dist/es/index.js 9.2 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/index.js 204 kB
packages/perseus/dist/es/strings.js 7.71 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2025

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (7e5ff57) and published it to npm. You
can install it using the tag PR2985.

Example:

pnpm add @khanacademy/perseus@PR2985

If you are working in Khan Academy's frontend, you can run the below command.

./dev/tools/bump_perseus_version.ts -t PR2985

If you are working in Khan Academy's webapp, you can run the below command.

./dev/tools/bump_perseus_version.js -t PR2985

@nishasy nishasy requested review from a team and jeremywiebe October 24, 2025 17:34
@github-actions github-actions bot added schema-change Attached to PRs when we detect Perseus Schema changes in it item-splitting-change and removed schema-change Attached to PRs when we detect Perseus Schema changes in it item-splitting-change labels Oct 24, 2025
Comment on lines 98 to 142
// TODO(LEMS-3643): Remove this function once the save warnings util is
// complete and in use.
getSaveWarnings: () => any = () => {
const issues: Array<any | string> = [];

if (this.props.answerForms.length === 0) {
issues.push("No answers specified");
} else {
const hasCorrect = this.props.answerForms.some((form) => {
return form.considered === "correct";
});
if (!hasCorrect) {
issues.push("No correct answer specified");
}

_(this.props.answerForms).each((form, ix) => {
if (this.props.value === "") {
issues.push(`Answer ${ix + 1} is empty`);
} else {
// note we're not using icu for content creators
const expression = KAS.parse(form.value, {
functions: this.props.functions,
});
if (!expression.parsed) {
issues.push(`Couldn't parse ${form.value}`);
} else if (
form.simplify &&
!expression.expr.isSimplified()
) {
issues.push(
`${form.value} isn't simplified, but is required" +
" to be`,
);
}
}
});

// TODO(joel) - warn about:
// - unreachable answers (how??)
// - specific answers following unspecific answers
// - incorrect answers as the final form
}

return issues;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if one way to bridge across without having a copy of the code is to call the new function here instead of keeping this logic in place.

Suggested change
// TODO(LEMS-3643): Remove this function once the save warnings util is
// complete and in use.
getSaveWarnings: () => any = () => {
return getSaveWarningsForExpressionWidget(this.props); // Ah! I see... we might not have props that are the same as the actual widget options... ok, maybe this won't work.
};


// TODO(LEMS-3643): Remove this function once the save warnings util is
// complete and in use.
getSaveWarnings: () => any = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am having a hard time figuring out replace the code here with the save warnings code migrated to the expression utils to reduce duplication.

@nishasy nishasy marked this pull request as ready for review October 28, 2025 00:43
@nishasy nishasy requested a review from jeremywiebe October 28, 2025 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants