Repository navigation
Add the inline choice interaction editor #6303
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
rtibbles
merged 8 commits into
learningequality:unstable
from
AlexVelezLl:issue-6182-inline-choice-editor
Oct 26, 2026
+3,603
−222
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
80846aa
Write no warning when not every response can be scored
AlexVelezLl 6a20b89
Fit the prominent insert action in with the toolbar's other tools
AlexVelezLl b3d006f
Document that an expanded popup keeps the rich text editor open
AlexVelezLl 18479dc
Move the caret past inline choice chips instead of selecting them
AlexVelezLl 724a920
Read a rich text editor's stored HTML through one helper
AlexVelezLl ea3536b
Add the inline choice interaction editor
AlexVelezLl e3a4126
Make inline choice chips easier to use with a keyboard or screen reader
AlexVelezLl 30149d8
Show the insert icon on the inline choice Insert action
AlexVelezLl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
78 changes: 78 additions & 0 deletions
78
.../frontend/shared/views/QTIEditor/composables/__tests__/useInlineChoiceInteraction.spec.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { nextTick, ref } from 'vue'; | ||
| import { useInlineChoiceInteraction } from '../useInlineChoiceInteraction'; | ||
| import { inlineChoiceInteractionDescriptor } from '../../interactions/inlineChoice/Descriptor'; | ||
| import { QuestionType, ValidationError } from '../../constants'; | ||
| import { chip } from '../../interactions/inlineChoice/__tests__/renderPassage'; | ||
|
|
||
| const PASSAGE = `<p>The ${chip('r1', [ | ||
| ['a', 'Moon'], | ||
| ['b', 'Sun'], | ||
| ])} rises</p>`; | ||
|
|
||
| function setup(state = { prompt: '', passage: PASSAGE, shuffle: false }) { | ||
| const questionType = ref(QuestionType.INLINE_CHOICE); | ||
| const block = inlineChoiceInteractionDescriptor.buildXML(state, QuestionType.INLINE_CHOICE); | ||
| return useInlineChoiceInteraction(block, questionType); | ||
| } | ||
|
|
||
| describe('useInlineChoiceInteraction', () => { | ||
| it('reads the dropdowns out of the passage', () => { | ||
| const { dropdowns } = setup(); | ||
| expect(dropdowns.value).toEqual([ | ||
| { | ||
| responseIdentifier: 'r1', | ||
| options: [ | ||
| { id: 'a', text: 'Moon' }, | ||
| { id: 'b', text: 'Sun' }, | ||
| ], | ||
| correctId: null, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('sets the question', () => { | ||
| const { state, setPrompt } = setup(); | ||
| setPrompt('<p>Fill in the blanks</p>'); | ||
| expect(state.value.prompt).toBe('<p>Fill in the blanks</p>'); | ||
| }); | ||
|
|
||
| it('saves a cleared question as no question', () => { | ||
| const { state, bodyXml, setPrompt } = setup({ | ||
| prompt: '<p>Fill in the blanks</p>', | ||
| passage: PASSAGE, | ||
| shuffle: false, | ||
| }); | ||
| setPrompt('<p></p>'); | ||
| expect(state.value.prompt).toBe(''); | ||
| expect(bodyXml.value).not.toContain('data-studio-prompt'); | ||
| }); | ||
|
|
||
| it('sets the passage, and the dropdowns follow it', () => { | ||
| const { dropdowns, setPassage } = setup(); | ||
| setPassage(`<p>${chip('r2', [['c', 'Earth']], 'c')}</p>`); | ||
| expect(dropdowns.value.map(d => d.responseIdentifier)).toEqual(['r2']); | ||
| }); | ||
|
|
||
| it('writes Shuffle onto every dropdown in the saved XML', () => { | ||
| const { bodyXml, setShuffle } = setup({ | ||
| prompt: '', | ||
| passage: `<p>${chip('r1', [['a', 'x']], 'a')} ${chip('r2', [['b', 'y']], 'b')}</p>`, | ||
| shuffle: false, | ||
| }); | ||
| setShuffle(true); | ||
| const shuffles = [...bodyXml.value.matchAll(/shuffle="(\w+)"/g)].map(m => m[1]); | ||
| expect(shuffles).toEqual(['true', 'true']); | ||
| }); | ||
|
|
||
| it('reads Shuffle back from a saved item', () => { | ||
| const { state } = setup({ prompt: '', passage: PASSAGE, shuffle: true }); | ||
| expect(state.value.shuffle).toBe(true); | ||
| }); | ||
|
|
||
| it('reports a passage with no dropdown', async () => { | ||
| const { errors, setPassage } = setup(); | ||
| setPassage('<p>No dropdowns here</p>'); | ||
| await nextTick(); | ||
| expect(errors.value).toEqual([{ code: ValidationError.NO_INTERACTION }]); | ||
| }); | ||
| }); |
45 changes: 45 additions & 0 deletions
45
...contentcuration/frontend/shared/views/QTIEditor/composables/useInlineChoiceInteraction.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { computed, readonly } from 'vue'; | ||
| import { inlineChoiceInteractionDescriptor } from '../interactions/inlineChoice/Descriptor'; | ||
| import { getDropdowns } from '../interactions/inlineChoice/parse'; | ||
| import { hasRichTextContent } from '../utils/richText'; | ||
| import { useInteraction } from './useInteraction'; | ||
|
|
||
| /** | ||
| * Composable for the inline choice interaction editor. | ||
| * | ||
| * Extends useInteraction with the question-level mutations. A dropdown's options are not | ||
| * edited here: they live in the passage, and are changed through the passage editor's node | ||
| * commands so that each edit is one step of its history. | ||
| * | ||
| * @param {{ bodyXml: string, responseDeclarations: string[] }} interactionBlock | ||
| * @param {import('vue').Ref<string|null>} questionType | ||
| */ | ||
| export function useInlineChoiceInteraction(interactionBlock, questionType) { | ||
| const base = useInteraction(inlineChoiceInteractionDescriptor, interactionBlock, questionType); | ||
| const { state } = base; | ||
|
|
||
| /** Every dropdown in the passage, in document order. */ | ||
| const dropdowns = computed(() => getDropdowns(state.value.passage)); | ||
|
|
||
| // A cleared question is no question, rather than an empty paragraph saved into the body. | ||
| function setPrompt(html) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A cleared question is saved as |
||
| state.value = { ...state.value, prompt: hasRichTextContent(html) ? html : '' }; | ||
| } | ||
|
|
||
| function setPassage(html) { | ||
| state.value = { ...state.value, passage: html }; | ||
| } | ||
|
|
||
| function setShuffle(val) { | ||
| state.value = { ...state.value, shuffle: val }; | ||
| } | ||
|
|
||
| return { | ||
| ...base, | ||
| state: readonly(state), | ||
| dropdowns, | ||
| setPrompt, | ||
| setPassage, | ||
| setShuffle, | ||
| }; | ||
| } | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.