-
Notifications
You must be signed in to change notification settings - Fork 361
New save warning utility - Expression widget warnings #2985
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: warnings-util
Are you sure you want to change the base?
Conversation
…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.
🗄️ Schema Change: No Changes ✅ |
🛠️ Item Splitting: No Changes ✅ |
|
Size Change: +224 B (+0.05%) Total Size: 498 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (7e5ff57) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2985If you are working in Khan Academy's frontend, you can run the below command. ./dev/tools/bump_perseus_version.ts -t PR2985If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -t PR2985 |
…gs-util-2-expression
…gs-util-2-expression
| // 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; | ||
| }; |
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 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.
| // 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 = () => { |
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 am having a hard time figuring out replace the code here with the save warnings code migrated to the expression utils to reduce duplication.
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.tsStorybook
/?path=/story/editors-editorpage--with-save-warnings-new-util