Skip to content
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

Fixing issue with Input Numbers that have a value of 0 #1888

Merged
merged 6 commits into from
Nov 20, 2024
Merged

Conversation

SonicScrewdriver
Copy link
Contributor

@SonicScrewdriver SonicScrewdriver commented Nov 20, 2024

Summary:

This PR fixes an issue with the Input Number Conversion project that specifically pertains to widgets that have a value of 0, as it results in a falsy situation. As a result of this issue, exercises that contain the offending widget settings would fail to render.

This PR updates the logic to a safer key, and ensures that it is not undefined.

Test:

  • Manual testing both in Storybook and Webapp to confirm that failing cases now render properly.

@SonicScrewdriver SonicScrewdriver self-assigned this Nov 20, 2024
@SonicScrewdriver SonicScrewdriver changed the title I really hope this isn't the fix. Sad Hypothesis Nov 20, 2024
Copy link
Contributor

github-actions bot commented Nov 20, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR1888

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1888

Copy link
Contributor

github-actions bot commented Nov 20, 2024

Size Change: +7 B (0%)

Total Size: 1.29 MB

Filename Size Change
packages/perseus/dist/es/index.js 423 kB +7 B (0%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 38.9 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.8 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-editor/dist/es/index.js 697 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/strings.js 3.55 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.4 kB

compressed-size-action

@SonicScrewdriver SonicScrewdriver changed the title Sad Hypothesis False starts Nov 20, 2024
@SonicScrewdriver SonicScrewdriver changed the title False starts Fixing issue with Input Numbers that have a value of 0 Nov 20, 2024
// input-number to numeric-input. In this case, we need to upgrade
// the widget options accordingly.
if (initialProps.value) {
if (initialProps.simplify) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given we were bitten by this type of "bare if()" check for value, I think it's much safer and clearer to use an explicit check against undefined. It appears that simplify is never null or an empty string in our published content (at least "en"), but I think we should move away from these truthy/falsey type of checks given how dangerous they can be in the face of 0 and "".

Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW, I used this shell command against the downloaded content tree to check:

$ rg '"type"\s*:\s*"input-number"' -l | xargs jq --slurp '.. | objects | select(has("widgets")) | .widgets[].options | select(has("value") and .value == 0) | .simplify' | sort | uniq

@SonicScrewdriver SonicScrewdriver marked this pull request as ready for review November 20, 2024 16:37
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/violet-melons-sneeze.md, packages/perseus/src/__stories__/server-item-renderer.stories.tsx, packages/perseus/src/__testdata__/server-item-renderer.testdata.ts, packages/perseus/src/widgets/numeric-input/numeric-input.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

@khan-actions-bot khan-actions-bot requested a review from a team November 20, 2024 16:37
Copy link
Contributor

@mark-fitzgerald mark-fitzgerald left a comment

Choose a reason for hiding this comment

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

Subtle but important change. Great job tracking this down!

@SonicScrewdriver SonicScrewdriver merged commit d0e7a03 into main Nov 20, 2024
15 of 17 checks passed
@SonicScrewdriver SonicScrewdriver deleted the sighseus branch November 20, 2024 17:26
SonicScrewdriver added a commit that referenced this pull request Nov 20, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @khanacademy/[email protected]

### Patch Changes

- [#1887](#1887)
[`4c2db8d38`](4c2db8d)
Thanks [@benchristel](https://github.com/benchristel)! - Internal: add
snapshot tests for `parseAndTypecheckPerseusItem`.


- [#1872](#1872)
[`7ca5bbf0e`](7ca5bbf)
Thanks [@benchristel](https://github.com/benchristel)! - Internal: make
the exhaustive test tool for PerseusItem parsing find the shortest input
file that repros each failure


- [#1871](#1871)
[`500315145`](5003151)
Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add
regression tests for PerseusItem parser


- [#1877](#1877)
[`44933f88e`](44933f8)
Thanks [@benchristel](https://github.com/benchristel)! - Internal: Add
README.md for packages/perseus/src/util/parse-perseus-json


- [#1888](#1888)
[`d0e7a0383`](d0e7a03)
Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! -
Fixing issue with Input Numbers that have a value of 0

## @khanacademy/[email protected]

### Patch Changes

- Updated dependencies
\[[`4c2db8d38`](4c2db8d),
[`7ca5bbf0e`](7ca5bbf),
[`500315145`](5003151),
[`44933f88e`](44933f8),
[`d0e7a0383`](d0e7a03)]:
    -   @khanacademy/[email protected]
SonicScrewdriver added a commit that referenced this pull request Nov 22, 2024
… logic (#1905)

## Summary:
In order to unblock Perseus, we are reverting the following commits: 

- [x] [#1888](#1888) [d0e7a03](d0e7a03) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fixing issue with Input Numbers that have a value of 0
- [x] [#1884](#1884) [b4cf444](b4cf444) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Ensuring UserInput and Rubric widget keys match for edge cases
- [x] [#1879](#1879) [04d6e60](04d6e60) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fixing conflicts that arose from scoring and widget conversion efforts
- [x] [#1753](#1753) [c1ba55f](c1ba55f) Thanks [@handeyeco](https://github.com/handeyeco)! - Change ServerItemRenderer scoring APIs to externalize scoring
- [x] [#1866](#1866) [94eba15](94eba15) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fixing a regression and a bug in the Input Conversion Logic
- [x] [#1859](#1859) [dcf1fbe](dcf1fbe) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Addition of a new alert for the content editors when Input numbers are converted to Numeric Inputs
- [x] [#1731](#1731) [27126aa](27126aa) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Conversion of Input Number to Numeric Input

## Test plan:
- manual testing

Author: SonicScrewdriver

Reviewers: catandthemachines, #perseus

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), ✅ gerald, 🚫 Publish npm snapshot (ubuntu-latest, 20.x), 🚫 Lint, Typecheck, Format, and Test (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), ✅ gerald, ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1905
benchristel pushed a commit that referenced this pull request Nov 26, 2024
… logic (#1905)

## Summary:
In order to unblock Perseus, we are reverting the following commits: 

- [x] [#1888](#1888) [d0e7a03](d0e7a03) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fixing issue with Input Numbers that have a value of 0
- [x] [#1884](#1884) [b4cf444](b4cf444) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Ensuring UserInput and Rubric widget keys match for edge cases
- [x] [#1879](#1879) [04d6e60](04d6e60) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fixing conflicts that arose from scoring and widget conversion efforts
- [x] [#1753](#1753) [c1ba55f](c1ba55f) Thanks [@handeyeco](https://github.com/handeyeco)! - Change ServerItemRenderer scoring APIs to externalize scoring
- [x] [#1866](#1866) [94eba15](94eba15) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Fixing a regression and a bug in the Input Conversion Logic
- [x] [#1859](#1859) [dcf1fbe](dcf1fbe) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Addition of a new alert for the content editors when Input numbers are converted to Numeric Inputs
- [x] [#1731](#1731) [27126aa](27126aa) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Conversion of Input Number to Numeric Input

## Test plan:
- manual testing

Author: SonicScrewdriver

Reviewers: catandthemachines, #perseus

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), ✅ gerald, 🚫 Publish npm snapshot (ubuntu-latest, 20.x), 🚫 Lint, Typecheck, Format, and Test (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), ✅ gerald, ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants