Skip to content

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

Open
wants to merge 3 commits into
base: open-release/sumac.master
Choose a base branch
from

Conversation

efortish
Copy link
Contributor

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 response

  • Implemented logic in buildNumericalResponse to detect variables in answers and generate string response format instead

  • Extended buildNumericInput to check this flag and render the appropriate OLX output

Discussion

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

  • Create a new problem with numerical input where the answer is a math expression like m*c^2:

image

The OLX will have an structure like this:
image

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.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Mar 28, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Mar 28, 2025

Thanks for the pull request, @efortish!

This repository is currently maintained by @bradenmacdonald.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@efortish efortish force-pushed the KS/fix-numericalInput-and-response branch from 920ef0a to 7d8cb26 Compare March 28, 2025 16:04
Copy link

codecov bot commented Mar 28, 2025

Codecov Report

Attention: Patch coverage is 21.21212% with 26 lines in your changes missing coverage. Please review.

Please upload report for BASE (open-release/sumac.master@4f04698). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ntainers/ProblemEditor/data/ReactStateOLXParser.js 21.21% 21 Missing and 5 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@efortish
Copy link
Contributor Author

efortish commented Mar 28, 2025

@mariajgrimaldi hello, this is the PR I was talking about !

@mphilbrick211 mphilbrick211 requested a review from a team April 1, 2025 20:51
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Apr 1, 2025
@mariajgrimaldi
Copy link
Member

mariajgrimaldi commented May 5, 2025

@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!

@mariajgrimaldi
Copy link
Member

@efortish: friendly ping to my comment above :) thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Status: Ready for Review
Development

Successfully merging this pull request may close these issues.

[Test failure] TC_AUTHOR_50: Numerical input component generates an error with the formula shown in the usage example.
3 participants