-
Notifications
You must be signed in to change notification settings - Fork 351
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
Conversation
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.
Size Change: +757 B (+0.09%) Total Size: 873 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (4192d3d) and published it to npm. You 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 |
…the new FreeResponse widget
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 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: "", | ||
}; |
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.
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?
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.
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?
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.
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.
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.
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.
packages/perseus/src/widgets/free-response/free-response.test.tsx
Outdated
Show resolved
Hide resolved
…ve commented-out code, refactor label HTML structure, update changeset file
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: