feat: prototype MultipleChoiceWidget#2
Open
fillerwriter wants to merge 1 commit intoexamspark:mainfrom
Open
Conversation
Introduce a new widget to allow for input of multiple choice questions. Provides a basic data structure MultipleChoiceData that can be used to display data. No styling in current iteration, focus is on data structure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce a new widget to allow for input of multiple choice questions. Provides a basic data structure MultipleChoiceData that can be used to display data. I'm using this PR to describe how the work is organized, and where the work would focus on with followup PRs.
Requirements Doc
This PR establishes two primary components within the app, along with one type.
packages/c3-ui-editor/lib/components/MultipleChoiceWidget/MultipleChoiceData.ts
This type defines a structure that the
MultipleChoiceWidgetbuilds on.prompt: The question being asked.answers[]: An array of strings that represent one or more answers.correct: A JavaScript Set that defines which answers are the correct answers. Each value is tied to the array index foranswers. I chose to use a Set instead of an Array to make keeping track of one and only one version appearing in the Set easier, even though it slightly complicated setting upimmer.multiple: A boolean that determines whether or not multiple answers could be considered correct. I use this flag in the widget to determine checkbox behavior when setting correct values.packages/c3-ui-core/lib/components/MultipleChoiceItem.tsx
This is a widget that holds a text input and a checkbox to signal whether or not it is a correct answer. Based on the mockups, the checkbox holds the data for the "A", "B", "C" etc. selector for the widget, and would be styled accordingly in a future PR. This widget holds no internal state.
This component is in
c3-ui-corerather thanc3-ui-editorbecause it seems like something that might make sense in other components, assuming thatc3-ui-coreis a Campfire standard library. This is not a strongly held opinion, and could easily live inc3-ui-editorinstead.packages/c3-ui-editor/lib/components/MultipleChoiceWidget/MultipleChoiceWidget.tsx
This is the primary widget, and where the component state is stored. Some logic is baked into this component (including how multiple choice selection is handled). You can preview this in the Item Editor page of this app. Selecting a checkbox when multiple options is disabled results in all other options being deselected.
A new to me trick here is the use of
useEffectas a trigger to pass state up a onChange chain, so that ItemEditor can correctly catch an updated dataStore from this component.General notes on current PR
Expected followup PRs
MultipleChoiceData's structure is generally accepted by team.MultipleChoiceData's structure.MultipleChoiceWidget.MultipleChoiceWidgetto allow for adding new answers to a prompt.MultipleChoiceItemto trigger a deletion of an answer inMultipleChoiceWidget.