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

Reset interactive graph state when the graph type or number of segments changes #1345

Merged
merged 4 commits into from
Jun 17, 2024

Conversation

benchristel
Copy link
Member

Summary:

There was a bug in the exercise editor where the preview did not reflect
changes to the graph type or number of segments. This happened because
changes to the graph.type and graph.numSegments props were ignored.
We now reinitialize the graph state when those props change.

Issue: LEMS-2041

Test plan:

Deploy a dev build of Perseus into the a webapp ZND. Visit:

https://www.khanacademy.org/devadmin/content/exercises/linear-graph-exercise/x3239cabc044aa28b/x325a92c13bc37711

Change the graph type of one of the interactive graphs to "segment".
The preview on the right-hand side of the editor should update.

Change the number of segments on the graph. The preview should update.

@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/chilled-hats-tan.md, packages/perseus/src/widgets/interactive-graphs/mafs-graph.test.tsx, packages/perseus/src/widgets/interactive-graphs/mafs-graph.tsx, packages/perseus/src/widgets/interactive-graphs/reducer/initialize-graph-state.ts, packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-action.ts, packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.ts

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 June 13, 2024 20:42
Copy link
Contributor

github-actions bot commented Jun 13, 2024

Size Change: +274 B (+0.03%)

Total Size: 845 kB

Filename Size Change
packages/perseus/dist/es/index.js 407 kB +274 B (+0.07%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 38.2 kB
packages/kmath/dist/es/index.js 4.26 kB
packages/math-input/dist/es/index.js 80.1 kB
packages/math-input/dist/es/strings.js 1.73 kB
packages/perseus-core/dist/es/index.js 906 B
packages/perseus-editor/dist/es/index.js 271 kB
packages/perseus-error/dist/es/index.js 866 B
packages/perseus-linter/dist/es/index.js 21.8 kB
packages/perseus/dist/es/strings.js 3.21 kB
packages/pure-markdown/dist/es/index.js 3.67 kB
packages/simple-markdown/dist/es/index.js 12.4 kB

compressed-size-action

…ts changes

There was a bug in the exercise editor where the preview did not reflect
changes to the graph type or number of segments. This happened because
changes to the `graph.type` and `graph.numSegments` props were ignored.
We now reinitialize the graph state when those props change.

Issue: LEMS-2041

Test plan:

Deploy a dev build of Perseus into the a webapp ZND. Visit:

https://www.khanacademy.org/devadmin/content/exercises/linear-graph-exercise/x3239cabc044aa28b/x325a92c13bc37711

Change the graph type of one of the interactive graphs to "segment".
The preview on the right-hand side of the editor should update.

Change the number of segments on the graph. The preview should update.
Copy link
Contributor

github-actions bot commented Jun 13, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR1345

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

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

Copy link

codecov bot commented Jun 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.69%. Comparing base (56b2b9f) to head (97b19a7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1345      +/-   ##
==========================================
+ Coverage   69.52%   70.69%   +1.17%     
==========================================
  Files         488      492       +4     
  Lines      103276   103387     +111     
  Branches     7416    11138    +3722     
==========================================
+ Hits        71806    73093    +1287     
+ Misses      31289    30294     -995     
+ Partials      181        0     -181     

Impacted file tree graph

Files Coverage Δ
...seus/src/widgets/interactive-graphs/mafs-graph.tsx 97.81% <100.00%> (-1.81%) ⬇️
...teractive-graphs/reducer/initialize-graph-state.ts 86.70% <100.00%> (-8.62%) ⬇️
...ractive-graphs/reducer/interactive-graph-action.ts 100.00% <100.00%> (ø)
...active-graphs/reducer/interactive-graph-reducer.ts 86.96% <100.00%> (-0.07%) ⬇️

... and 139 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56b2b9f...97b19a7. Read the comment docs.

// This conditional prevents the state from being "reinitialized" right
// after the first render. This is an optimization, but also prevents
// a bug where the graph would be marked "incorrect" during grading
// even if the user never interacted with it.
Copy link
Member Author

Choose a reason for hiding this comment

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

I feel like there's probably a simpler way to achieve this that doesn't require keeping a ref to two props objects. Maybe I should extract a useEffectExceptOnMount hook — unless we already have one?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the exports from wonder-blocks-core, I'm not sure there's something that fits your use case. Maybe useIsMounted is the closest one? But I don't think that's the same thing... 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Question: What's the downside to having the two refs? If you can extract a hook that makes things simpler, that always sounds better to me :) Unless it is harder to follow of course.

Copy link
Contributor

@nishasy nishasy left a comment

Choose a reason for hiding this comment

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

LGTM. Testing this must have been annoying 🥲

// This conditional prevents the state from being "reinitialized" right
// after the first render. This is an optimization, but also prevents
// a bug where the graph would be marked "incorrect" during grading
// even if the user never interacted with it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the exports from wonder-blocks-core, I'm not sure there's something that fits your use case. Maybe useIsMounted is the closest one? But I don't think that's the same thing... 🤔

@benchristel benchristel merged commit 92990f1 into main Jun 17, 2024
13 checks passed
@benchristel benchristel deleted the benc/reinitialize branch June 17, 2024 20:45
nishasy added a commit that referenced this pull request Jun 17, 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/perseus@23.5.0

### Minor Changes

- [#1348](#1348)
[`73ba4f7c9`](73ba4f7)
Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph
Editor] Update the locked ellipse settings so they only take degrees as
input.


- [#1353](#1353)
[`e528c5b2b`](e528c5b)
Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph]
View a locked polygon


- [#1351](#1351)
[`9a6517ca2`](9a6517c)
Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph
Editor] Add blue and gold to locked figures colorset

### Patch Changes

- [#1350](#1350)
[`1e877c6d4`](1e877c6)
Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph
Editor] Add locked vector to storybook story for all locked figures


- [#1345](#1345)
[`92990f15f`](92990f1)
Thanks [@benchristel](https://github.com/benchristel)! - Fix a bug in
the exercise editor where the preview did not update after a change to
the graph type or number of line segments.

## @khanacademy/perseus-editor@6.11.0

### Minor Changes

- [#1348](#1348)
[`73ba4f7c9`](73ba4f7)
Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph
Editor] Update the locked ellipse settings so they only take degrees as
input.


- [#1353](#1353)
[`e528c5b2b`](e528c5b)
Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph]
View a locked polygon


- [#1351](#1351)
[`9a6517ca2`](9a6517c)
Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph
Editor] Add blue and gold to locked figures colorset


- [#1354](#1354)
[`e73373f48`](e73373f)
Thanks [@Myranae](https://github.com/Myranae)! - Fix interactive graph
editor in storybook to display and persist options

### Patch Changes

- [#1350](#1350)
[`1e877c6d4`](1e877c6)
Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph
Editor] Add locked vector to storybook story for all locked figures

- Updated dependencies
\[[`1e877c6d4`](1e877c6),
[`92990f15f`](92990f1),
[`73ba4f7c9`](73ba4f7),
[`e528c5b2b`](e528c5b),
[`9a6517ca2`](9a6517c)]:
    -   @khanacademy/perseus@23.5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants