-
Notifications
You must be signed in to change notification settings - Fork 357
Grapher: renderer user input state #2596
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
Conversation
Size Change: -6 B (0%) Total Size: 473 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (de89240) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2596 If you are working in Khan Academy's frontend, you can run the below command. ./tools/bump_perseus_version.js -t PR2596 If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -s n -t PR2596 |
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.
Looks good to me! And an great reminder that I do not like the grapher widget.
<Grapher {...(graphProps as PropsFor<typeof Grapher>)} /> | ||
); | ||
equationString = getEquationString( | ||
graphProps.userInput as GrapherAnswerTypes, |
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.
Can you use satisfies
instead of as
here?
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.
That didn't seem to work 🤔
## Summary: Issue: [LEMS-3208](https://khanacademy.atlassian.net/browse/LEMS-3208) Edit see the ticket for full context. **tl;dr: I need user input to be outside the chunk of state that Renderer stores arbitrary widget state in** (currently it's a mash of render props, user input, and whatever else widgets want to shove in there). This ticket is the shared changes of this work - things that multiple widgets need. For the most part, I tried to have the other PRs _only_ affect things that are _specific_ to the individual widget. Anything outside of the immediate scope of the widget went into this PR. The main ideas: - Renderer now has `userInput` state which is a `UserInputMap` - `UniversalWidgetProps` now passes `userInput` and `handleUserInput` down to components for them to consume - `WidgetExports` has some new optional APIs: - `getUserInputFromSerializedState` for restoring serialized state - `getStartUserInput` for initializing user input - `getCorrectUserInput` for static widgets - Marked a bunch of things as deprecated Note that besides some cleanup, no tests were harmed in the making of this PR. It's backwards compatible with our old way of doing things. --- Reviewers: handeyeco, benchristel, SonicScrewdriver, jeremywiebe, ivyolamit, mark-fitzgerald, anakaren-rojas, nishasy Child PRs: - [Categorizer](#2572) - [CSProgram](#2584) - [Dropdown](#2568) - [Expression](#2569) - [FreeResponse](#2585) - [Grapher](#2596) - [IFrame](#2582) - [InputNumber](#2589) - [InteractiveGraph](#2598) - [LabelImage](#2577) - [Matcher](#2575) - [Matrix](#2581) - [MockWidget](#2586) - [NumberLine](#2573) - [NumericInput](#2571) - [Orderer](#2592) - [Plotter](#2588) - [Sorter](#2578) - [Table](#2587) [LEMS-3208]: https://khanacademy.atlassian.net/browse/LEMS-3208?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Author: handeyeco Required Reviewers: Approved By: SonicScrewdriver, jeremywiebe Checks: ✅ 8 checks were successful Pull Request URL: #2566
Summary:
See the parent PR for more context. Part of LEMS-3208.
In #2566 I add additional APIs to let widgets consume
userInput
from a parent and to update that parent state usinghandleUserInput
, while also supporting the legacy way of storing user input (which was a combination of internal widget state and stashing state in a random blob in Renderer). This PR is part of a series of PRs that go widget-by-widget to use the new API.This is a generic summary I'm putting on each PR and not every point will be applicable to every widget, but the common themes are:
getSerializedState
andgetUserInputFromSerializedState
to keep supporting the expected results.userInput
state in Renderer. This means consuminguserInput
in the component and callinghandleUserInput
on change.transform
did something to initialize user input state, I moved the logic togetStartUserInput
.staticTransform
did something to get correct state in static widgets, I moved the logic togetCorrectUserInput
.Please see the parent PR for more information.
GrapherEditor does use Grapher, so this will affect the editing experience