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

Add a basic FreeResponse widget #2273

Merged
merged 6 commits into from
Mar 5, 2025

Conversation

aag
Copy link
Member

@aag aag commented Mar 3, 2025

Summary:

This commit adds a basic version of the new FreeResponse widget. This
widget allows users to enter free text into an input field. The initial
use case is for "short answer" type questions.

The UX of the widget is not complete in this commit. Instead, the
intention is to get all of the files in place with a basic UI which will
then be iterated on with more widget options and more sophisticated
rendering.

Issue: https://khanacademy.atlassian.net/browse/LIT-1661

Test plan:

  • View the editor and rendered widget stories in Storybook.
  • Run the tests.

This commit adds a basic version of the new FreeResponse widget. This
widget allows users to enter free text into an input field. The initial
use case is for "short answer" type questions.

The UX of the widget is not complete in this commit. Instead, the
intention is to get all of the files in place with a basic UI which will
then be iterated on with more widget options and more sophisticated
rendering.

Issue: https://khanacademy.atlassian.net/browse/LIT-1661

Test plan:
- View the editor and rendered widget stories in Storybook.
- Run the tests.
@aag aag self-assigned this Mar 3, 2025
@aag aag marked this pull request as draft March 3, 2025 19:58
Copy link
Contributor

github-actions bot commented Mar 3, 2025

Size Change: +757 B (+0.09%)

Total Size: 873 kB

Filename Size Change
packages/perseus-core/dist/es/index.js 30 kB +134 B (+0.45%)
packages/perseus-editor/dist/es/index.js 277 kB +218 B (+0.08%)
packages/perseus/dist/es/index.js 368 kB +405 B (+0.11%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39.7 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 11.1 kB
packages/math-input/dist/es/index.js 78.2 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-linter/dist/es/index.js 22.8 kB
packages/perseus-score/dist/es/index.js 20.6 kB
packages/perseus/dist/es/strings.js 6.74 kB
packages/pure-markdown/dist/es/index.js 4.14 kB
packages/simple-markdown/dist/es/index.js 13.1 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Mar 3, 2025

npm Snapshot: Published

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

Example:

pnpm add @khanacademy/perseus@PR2273

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

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

@aag aag requested review from jeremywiebe and rgpass March 3, 2025 20:48
@aag aag marked this pull request as ready for review March 3, 2025 20:48
@aag aag requested review from a team and removed request for jeremywiebe March 3, 2025 21:17
Copy link
Member

@benchristel benchristel left a comment

Choose a reason for hiding this comment

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

Looks very nice! Thank you!

One thing you'll need to do before landing this is create a parser for this widget in packages/perseus-core/src/parse-perseus-json/perseus-parsers, and use it in the PerseusWidgetsMap parser in widgets-map.ts.

That said, I don't think anything will fail (for now) if the parsers aren't updated. The parser currently serves two purposes:

  • it alerts us (via Sentry logs) if it encounters data that doesn't match the schema.
  • it migrates old widget options formats to the latest version.

The parser allows widgets of an unrecognized type (since they might have been registered dynamically), so it won't fail if you feed it a free-response widget as-is. However, we probably don't want to rely on that behavior for first-party widgets. A failing test you could write is "parseWidgetsMap rejects a free-response widget with no question".


const defaultWidgetOptions: PerseusFreeResponseWidgetOptions = {
question: "",
};
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of this default? It looks like question is required in the widget options, so when would the default ever be used?

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 was following the pattern I see in other widgets, e.g. PassageWidget. I think it makes sense to have "" be the default question prop value in FreeResponseEditor, but I'm not sure how else the freeResponseLogic is used. Do you know what else it's used for?

Copy link
Contributor

Choose a reason for hiding this comment

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

Defaults are used both for upgrading widgets (specifically minor widget upgrades) and as the starting state in the widget editor. This part of the code is a little hazy to me, but I think this is fine to have although possibly not necessary.

@aag aag requested review from handeyeco and benchristel March 4, 2025 20:37
Copy link
Contributor

@handeyeco handeyeco left a comment

Choose a reason for hiding this comment

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

This is amazingly comprehensive and well-written. I don't see any blockers, especially since this is landing into a feature branch and not main.

I still have some architectural questions to answer before we land the feature branch, but I think this makes sense as y'all are roughing out an idea of how the widget will work.

…ve commented-out code, refactor

label HTML structure, update changeset file
@aag aag merged commit 15025d4 into feature/free-response-widget Mar 5, 2025
8 checks passed
@aag aag deleted the basic-free-response-widget branch March 5, 2025 19:59
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.

3 participants