Skip to content

Table: renderer user input state #2587

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

Merged
merged 4 commits into from
Jun 24, 2025
Merged

Conversation

handeyeco
Copy link
Contributor

@handeyeco handeyeco commented Jun 12, 2025

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 using handleUserInput, 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:

  • I added a test for serialization to make sure we're still backwards compatible (see LEMS-3185), then implemented the helpers getSerializedState and getUserInputFromSerializedState to keep supporting the expected results.
  • I moved user input for the component into the new userInput state in Renderer. This means consuming userInput in the component and calling handleUserInput on change.
  • When transform did something to initialize user input state, I moved the logic to getStartUserInput.
  • When staticTransform did something to get correct state in static widgets, I moved the logic to getCorrectUserInput.
  • Editors that use a widget to collect answer data are changed to support the new API.

Please see the parent PR for more information.


TableEditor does use Table, so this will affect the editing experience

Copy link
Contributor

github-actions bot commented Jun 12, 2025

Size Change: +18 B (0%)

Total Size: 473 kB

Filename Size Change
packages/perseus-editor/dist/es/index.js 91.2 kB +27 B (+0.03%)
packages/perseus/dist/es/index.js 201 kB -9 B (0%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.7 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 5.98 kB
packages/math-input/dist/es/index.js 98.6 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.js 20.4 kB
packages/perseus-linter/dist/es/index.js 7.14 kB
packages/perseus-score/dist/es/index.js 9.22 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/strings.js 7.56 kB
packages/pure-markdown/dist/es/index.js 1.22 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

@handeyeco handeyeco marked this pull request as ready for review June 16, 2025 16:06
@handeyeco handeyeco requested review from benchristel, nishasy, a team and catandthemachines and removed request for nishasy June 16, 2025 16:07
Copy link
Contributor

github-actions bot commented Jun 16, 2025

npm Snapshot: Published

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

Example:

pnpm add @khanacademy/perseus@PR2587

If you are working in Khan Academy's frontend, you can run the below command.

./tools/bump_perseus_version.js -t PR2587

If you are working in Khan Academy's webapp, you can run the below command.

./dev/tools/bump_perseus_version.js -s n -t PR2587

Copy link
Contributor

@SonicScrewdriver SonicScrewdriver left a comment

Choose a reason for hiding this comment

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

I'm going to approve this but I think you should add the deprecated comment to the getUserInputFromSerializedState!


type Props = WidgetProps<PerseusTableWidgetOptions, PerseusTableUserInput> &
type Props = WidgetProps<RenderProps, PerseusTableUserInput> &
ChangeableProps &
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be lovely to get rid of changeable again here, but I understand if you don't want to stuff too much work into this already large task. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to remove uses that were only related to user input. In my next leg of work I'll being looking at UI state which should remove more uses of Changeable. Then the only thing that will be left are uses for the editor.

}

function getUserInputFromSerializedState(
serializedState: any,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not too fussed as I know we want to remove the serialized state eventually, but I do think avoiding "any" wherever possible is probably going to help us.

I also think this method should have the deprecated comment you've added to the other serialized states across your PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

any is actually kind of correct here. We don't have a type for this - it's just a blob of data. That's a big part of why I want to remove the serialization stuff.

Comment added!

handeyeco added a commit that referenced this pull request Jun 24, 2025
## 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
@handeyeco handeyeco changed the base branch from renderer-user-input-core to feature/renderer-user-input June 24, 2025 17:08
An error occurred while trying to automatically change base from renderer-user-input-core to feature/renderer-user-input June 24, 2025 17:08
@handeyeco handeyeco merged commit 88a4f68 into feature/renderer-user-input Jun 24, 2025
11 of 13 checks passed
@handeyeco handeyeco deleted the rui-table branch June 24, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants