-
Notifications
You must be signed in to change notification settings - Fork 123
fix: Numeric input with variables conversion to StringResponse #1767
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: open-release/sumac.master
Are you sure you want to change the base?
fix: Numeric input with variables conversion to StringResponse #1767
Conversation
Thanks for the pull request, @efortish! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
…answer contains variables
920ef0a
to
7d8cb26
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## open-release/sumac.master #1767 +/- ##
============================================================
Coverage ? 93.14%
============================================================
Files ? 1051
Lines ? 20448
Branches ? 4377
============================================================
Hits ? 19046
Misses ? 1340
Partials ? 62 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@mariajgrimaldi hello, this is the PR I was talking about ! |
@efortish: thanks for the contribution! Can you also share the PR against the master branch? That should be merged first, then we can backport the changes to the releases we support :) thank you! Also, can we add some tests for the approach? We'd really appreciate it! |
@efortish: friendly ping to my comment above :) thanks! |
Description
This PR adds support for numeric inputs containing variables by converting them to string response format when needed. The current implementation detects when a numeric input answer contains variables (letters other than 'e', which is used in scientific notation) and properly converts it to a string response format that can handle algebraic expressions.
Changes
Added a flag
convertedToStringResponse
to track when a numeric problem has been converted to string responseImplemented logic in
buildNumericalResponse
to detect variables in answers and generate string response format insteadExtended
buildNumericInput
to check this flag and render the appropriate OLX outputDiscussion
This solution detects whether, when creating a problem with Numerical Input, the problem's solution contains variables. If so, it converts the solution to stringResponse so that the OLX is properly constructed for the backend to process it as a string.
The issue with this solution is that the equation previewer provided by numericalResponse with its formulaequationinput stops working because the OLX has been modified to stringResponse. The main idea was to adapt a logic similar to the legacy editor, but the difference is that the legacy code handles these cases with a different structure in JavaScript.
In conclusion, the solution implemented in this PR ensures that problems containing variables work correctly, preventing the "undefined variables" error. However, as a consequence, the equation previewer no longer functions when entering a response.
Testing instructions
The OLX will have an structure like this:

Related issues:
Numerical Input Component Incorrectly Handles Formulas as numericalresponse
[Test failure] TC_AUTHOR_50: Numerical input component generates an error with the formula shown in the usage example.