Fix multi-slot pairing for matching, cloze, and MCQ correct answers.
Pair answer slots with inputs by schema position and give each MCQ slot its own radio group name. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
7e4c3fd3b9
commit
4eac111a7b
|
|
@ -32,7 +32,7 @@ import {
|
||||||
DynamicMatchingInputsSlot,
|
DynamicMatchingInputsSlot,
|
||||||
} from "./DynamicMatchingSlotField"
|
} from "./DynamicMatchingSlotField"
|
||||||
import {
|
import {
|
||||||
findMatchingInputsInFieldValues,
|
findMatchingInputsForAnswerRow,
|
||||||
type MatchingInputsSlotValue,
|
type MatchingInputsSlotValue,
|
||||||
} from "../../lib/matchingSlotValue"
|
} from "../../lib/matchingSlotValue"
|
||||||
import {
|
import {
|
||||||
|
|
@ -41,7 +41,7 @@ import {
|
||||||
} from "./DynamicSelectMissingWordsSlotField"
|
} from "./DynamicSelectMissingWordsSlotField"
|
||||||
import { DynamicSequenceOrderSlot } from "./DynamicSequenceOrderSlotField"
|
import { DynamicSequenceOrderSlot } from "./DynamicSequenceOrderSlotField"
|
||||||
import {
|
import {
|
||||||
findSelectMissingWordsStimulusInFieldValues,
|
findSelectMissingWordsStimulusForResponseRow,
|
||||||
type SelectMissingWordsStimulusValue,
|
type SelectMissingWordsStimulusValue,
|
||||||
} from "../../lib/selectMissingWordsSlotValue"
|
} from "../../lib/selectMissingWordsSlotValue"
|
||||||
|
|
||||||
|
|
@ -643,11 +643,14 @@ function DynamicMultipleChoiceSlot({
|
||||||
onChange,
|
onChange,
|
||||||
disabled,
|
disabled,
|
||||||
slotLabel: label,
|
slotLabel: label,
|
||||||
|
groupName,
|
||||||
}: {
|
}: {
|
||||||
value: string
|
value: string
|
||||||
onChange: (next: string) => void
|
onChange: (next: string) => void
|
||||||
disabled: boolean
|
disabled: boolean
|
||||||
slotLabel: string
|
slotLabel: string
|
||||||
|
/** Unique radio group name so multiple OPTION/MCQ slots do not share one Correct selection. */
|
||||||
|
groupName: string
|
||||||
}) {
|
}) {
|
||||||
const parsed = parseMultipleChoiceSlotValue(value)
|
const parsed = parseMultipleChoiceSlotValue(value)
|
||||||
|
|
||||||
|
|
@ -700,7 +703,7 @@ function DynamicMultipleChoiceSlot({
|
||||||
<label className="flex shrink-0 items-center gap-2 text-sm text-grayScale-600">
|
<label className="flex shrink-0 items-center gap-2 text-sm text-grayScale-600">
|
||||||
<input
|
<input
|
||||||
type="radio"
|
type="radio"
|
||||||
name={`mcq-correct-${label}`}
|
name={groupName}
|
||||||
checked={option.is_correct}
|
checked={option.is_correct}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
|
|
@ -861,17 +864,22 @@ export function DynamicSchemaSlotField({
|
||||||
const fieldLabel = `${slotLabel(row)}${row.required ? " *" : ""}`
|
const fieldLabel = `${slotLabel(row)}${row.required ? " *" : ""}`
|
||||||
const matchingInputs: MatchingInputsSlotValue | null =
|
const matchingInputs: MatchingInputsSlotValue | null =
|
||||||
mode === "matching_answer" && allFieldValues
|
mode === "matching_answer" && allFieldValues
|
||||||
? findMatchingInputsInFieldValues(
|
? findMatchingInputsForAnswerRow(
|
||||||
allFieldValues,
|
allFieldValues,
|
||||||
stimulusSchema,
|
stimulusSchema,
|
||||||
responseSchema,
|
responseSchema,
|
||||||
|
side,
|
||||||
|
row.id,
|
||||||
)
|
)
|
||||||
: null
|
: null
|
||||||
const clozeStimulus: SelectMissingWordsStimulusValue | null =
|
const clozeStimulus: SelectMissingWordsStimulusValue | null =
|
||||||
mode === "select_missing_words_answer" && allFieldValues
|
mode === "select_missing_words_answer" && allFieldValues
|
||||||
? findSelectMissingWordsStimulusInFieldValues(
|
? findSelectMissingWordsStimulusForResponseRow(
|
||||||
allFieldValues,
|
allFieldValues,
|
||||||
stimulusSchema,
|
stimulusSchema,
|
||||||
|
responseSchema,
|
||||||
|
side,
|
||||||
|
row.id,
|
||||||
)
|
)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
|
|
@ -915,6 +923,7 @@ export function DynamicSchemaSlotField({
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
slotLabel={fieldLabel}
|
slotLabel={fieldLabel}
|
||||||
|
groupName={`mcq-correct-${side}-${row.id}`}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
} from "./multipleChoiceSlotValue"
|
} from "./multipleChoiceSlotValue"
|
||||||
import {
|
import {
|
||||||
defaultMatchingInputsSlotValue,
|
defaultMatchingInputsSlotValue,
|
||||||
findMatchingInputsInFieldValues,
|
findMatchingInputsForAnswerRow,
|
||||||
matchingAnswerSlotHasContent,
|
matchingAnswerSlotHasContent,
|
||||||
matchingInputsSlotHasContent,
|
matchingInputsSlotHasContent,
|
||||||
parseMatchingAnswerSlotValue,
|
parseMatchingAnswerSlotValue,
|
||||||
|
|
@ -23,7 +23,7 @@ import {
|
||||||
} from "./matchingSlotValue"
|
} from "./matchingSlotValue"
|
||||||
import {
|
import {
|
||||||
defaultSelectMissingWordsStimulusSlotValue,
|
defaultSelectMissingWordsStimulusSlotValue,
|
||||||
findSelectMissingWordsStimulusInFieldValues,
|
findSelectMissingWordsStimulusForResponseRow,
|
||||||
parseSelectMissingWordsResponseSlotValue,
|
parseSelectMissingWordsResponseSlotValue,
|
||||||
parseSelectMissingWordsStimulusSlotValue,
|
parseSelectMissingWordsStimulusSlotValue,
|
||||||
selectMissingWordsResponseHasContent,
|
selectMissingWordsResponseHasContent,
|
||||||
|
|
@ -453,15 +453,6 @@ export function validateDefinitionQuestion(
|
||||||
if (!v)
|
if (!v)
|
||||||
return `Question ${n}: fill required response "${row.label || row.id}" (${row.kind}).`
|
return `Question ${n}: fill required response "${row.label || row.id}" (${row.kind}).`
|
||||||
}
|
}
|
||||||
const matchingInputs = findMatchingInputsInFieldValues(
|
|
||||||
fieldValues,
|
|
||||||
def.stimulus_schema,
|
|
||||||
def.response_schema,
|
|
||||||
)
|
|
||||||
const clozeStimulus = findSelectMissingWordsStimulusInFieldValues(
|
|
||||||
fieldValues,
|
|
||||||
def.stimulus_schema,
|
|
||||||
)
|
|
||||||
for (const row of def.stimulus_schema) {
|
for (const row of def.stimulus_schema) {
|
||||||
if (isNoInputComponentKind(row.kind)) continue
|
if (isNoInputComponentKind(row.kind)) continue
|
||||||
if (isMultipleChoiceKind(row.kind)) {
|
if (isMultipleChoiceKind(row.kind)) {
|
||||||
|
|
@ -491,6 +482,13 @@ export function validateDefinitionQuestion(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isMatchingAnswerKind(row.kind)) {
|
if (isMatchingAnswerKind(row.kind)) {
|
||||||
|
const matchingInputs = findMatchingInputsForAnswerRow(
|
||||||
|
fieldValues,
|
||||||
|
def.stimulus_schema,
|
||||||
|
def.response_schema,
|
||||||
|
"stimulus",
|
||||||
|
row.id,
|
||||||
|
)
|
||||||
const val = parseMatchingAnswerSlotValue(
|
const val = parseMatchingAnswerSlotValue(
|
||||||
fieldValues[`stimulus:${row.id}`],
|
fieldValues[`stimulus:${row.id}`],
|
||||||
matchingInputs,
|
matchingInputs,
|
||||||
|
|
@ -551,6 +549,13 @@ export function validateDefinitionQuestion(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isMatchingAnswerKind(row.kind)) {
|
if (isMatchingAnswerKind(row.kind)) {
|
||||||
|
const matchingInputs = findMatchingInputsForAnswerRow(
|
||||||
|
fieldValues,
|
||||||
|
def.stimulus_schema,
|
||||||
|
def.response_schema,
|
||||||
|
"response",
|
||||||
|
row.id,
|
||||||
|
)
|
||||||
const val = parseMatchingAnswerSlotValue(
|
const val = parseMatchingAnswerSlotValue(
|
||||||
fieldValues[`response:${row.id}`],
|
fieldValues[`response:${row.id}`],
|
||||||
matchingInputs,
|
matchingInputs,
|
||||||
|
|
@ -567,6 +572,13 @@ export function validateDefinitionQuestion(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isSelectMissingWordsKind(row.kind)) {
|
if (isSelectMissingWordsKind(row.kind)) {
|
||||||
|
const clozeStimulus = findSelectMissingWordsStimulusForResponseRow(
|
||||||
|
fieldValues,
|
||||||
|
def.stimulus_schema,
|
||||||
|
def.response_schema,
|
||||||
|
"response",
|
||||||
|
row.id,
|
||||||
|
)
|
||||||
const val = parseSelectMissingWordsResponseSlotValue(
|
const val = parseSelectMissingWordsResponseSlotValue(
|
||||||
fieldValues[`response:${row.id}`],
|
fieldValues[`response:${row.id}`],
|
||||||
clozeStimulus,
|
clozeStimulus,
|
||||||
|
|
|
||||||
|
|
@ -352,3 +352,50 @@ export function findMatchingInputsInFieldValues(
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SchemaSideRow = {
|
||||||
|
side: "stimulus" | "response"
|
||||||
|
row: { id: string; kind: string }
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchingFamilyRows(
|
||||||
|
stimulusSchema: { id: string; kind: string }[],
|
||||||
|
responseSchema: { id: string; kind: string }[],
|
||||||
|
kind: "MATCHING_INPUTS" | "MATCHING_ANSWER",
|
||||||
|
): SchemaSideRow[] {
|
||||||
|
const want = kind
|
||||||
|
const out: SchemaSideRow[] = []
|
||||||
|
for (const row of stimulusSchema) {
|
||||||
|
if (row.kind.trim().toUpperCase() === want) out.push({ side: "stimulus", row })
|
||||||
|
}
|
||||||
|
for (const row of responseSchema) {
|
||||||
|
if (row.kind.trim().toUpperCase() === want) out.push({ side: "response", row })
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pair the Nth MATCHING_ANSWER slot with the Nth MATCHING_INPUTS slot (schema order:
|
||||||
|
* stimulus then response). Falls back to first-of-kind when the positional target is empty.
|
||||||
|
*/
|
||||||
|
export function findMatchingInputsForAnswerRow(
|
||||||
|
fieldValues: Record<string, string>,
|
||||||
|
stimulusSchema: { id: string; kind: string }[],
|
||||||
|
responseSchema: { id: string; kind: string }[],
|
||||||
|
answerSide: "stimulus" | "response",
|
||||||
|
answerRowId: string,
|
||||||
|
): MatchingInputsSlotValue | null {
|
||||||
|
const inputRows = matchingFamilyRows(stimulusSchema, responseSchema, "MATCHING_INPUTS")
|
||||||
|
const answerRows = matchingFamilyRows(stimulusSchema, responseSchema, "MATCHING_ANSWER")
|
||||||
|
const idx = answerRows.findIndex(
|
||||||
|
(x) => x.side === answerSide && x.row.id === answerRowId,
|
||||||
|
)
|
||||||
|
const target = idx >= 0 ? inputRows[idx] : undefined
|
||||||
|
if (target) {
|
||||||
|
const parsed = parseMatchingInputsSlotValue(
|
||||||
|
fieldValues[`${target.side}:${target.row.id}`],
|
||||||
|
)
|
||||||
|
if (matchingInputsSlotHasContent(parsed)) return parsed
|
||||||
|
}
|
||||||
|
return findMatchingInputsInFieldValues(fieldValues, stimulusSchema, responseSchema)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { parseTableSlotValue } from "./dynamicTableValue"
|
||||||
import {
|
import {
|
||||||
finalizeMatchingAnswerPayload,
|
finalizeMatchingAnswerPayload,
|
||||||
finalizeMatchingInputsPayload,
|
finalizeMatchingInputsPayload,
|
||||||
findMatchingInputsInFieldValues,
|
findMatchingInputsForAnswerRow,
|
||||||
matchingAnswerSlotHasContent,
|
matchingAnswerSlotHasContent,
|
||||||
matchingInputsSlotHasContent,
|
matchingInputsSlotHasContent,
|
||||||
parseMatchingAnswerSlotValue,
|
parseMatchingAnswerSlotValue,
|
||||||
|
|
@ -12,7 +12,7 @@ import {
|
||||||
import {
|
import {
|
||||||
finalizeSelectMissingWordsResponsePayload,
|
finalizeSelectMissingWordsResponsePayload,
|
||||||
finalizeSelectMissingWordsStimulusPayload,
|
finalizeSelectMissingWordsStimulusPayload,
|
||||||
findSelectMissingWordsStimulusInFieldValues,
|
findSelectMissingWordsStimulusForResponseRow,
|
||||||
parseSelectMissingWordsResponseSlotValue,
|
parseSelectMissingWordsResponseSlotValue,
|
||||||
parseSelectMissingWordsStimulusSlotValue,
|
parseSelectMissingWordsStimulusSlotValue,
|
||||||
selectMissingWordsResponseHasContent,
|
selectMissingWordsResponseHasContent,
|
||||||
|
|
@ -192,10 +192,12 @@ function slotValueForRow(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMatchingAnswerKind(row.kind)) {
|
if (isMatchingAnswerKind(row.kind)) {
|
||||||
const matchingInputs = findMatchingInputsInFieldValues(
|
const matchingInputs = findMatchingInputsForAnswerRow(
|
||||||
fieldValues,
|
fieldValues,
|
||||||
stimulusRows,
|
stimulusRows,
|
||||||
responseRows,
|
responseRows,
|
||||||
|
side,
|
||||||
|
row.id,
|
||||||
)
|
)
|
||||||
const fromField = parseMatchingAnswerSlotValue(rawField, matchingInputs)
|
const fromField = parseMatchingAnswerSlotValue(rawField, matchingInputs)
|
||||||
if (matchingAnswerSlotHasContent(fromField)) {
|
if (matchingAnswerSlotHasContent(fromField)) {
|
||||||
|
|
@ -212,9 +214,12 @@ function slotValueForRow(
|
||||||
}
|
}
|
||||||
return { segments: [], word_bank: [], allow_reuse: false }
|
return { segments: [], word_bank: [], allow_reuse: false }
|
||||||
}
|
}
|
||||||
const clozeStimulus = findSelectMissingWordsStimulusInFieldValues(
|
const clozeStimulus = findSelectMissingWordsStimulusForResponseRow(
|
||||||
fieldValues,
|
fieldValues,
|
||||||
stimulusRows,
|
stimulusRows,
|
||||||
|
responseRows,
|
||||||
|
side,
|
||||||
|
row.id,
|
||||||
)
|
)
|
||||||
const fromField = parseSelectMissingWordsResponseSlotValue(
|
const fromField = parseSelectMissingWordsResponseSlotValue(
|
||||||
rawField,
|
rawField,
|
||||||
|
|
|
||||||
|
|
@ -516,3 +516,31 @@ export function findSelectMissingWordsStimulusInFieldValues(
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pair the Nth response SELECT_MISSING_WORDS with the Nth stimulus SELECT_MISSING_WORDS.
|
||||||
|
* Falls back to first-of-kind when the positional target is empty.
|
||||||
|
*/
|
||||||
|
export function findSelectMissingWordsStimulusForResponseRow(
|
||||||
|
fieldValues: Record<string, string>,
|
||||||
|
stimulusSchema: { id: string; kind: string }[],
|
||||||
|
responseSchema: { id: string; kind: string }[],
|
||||||
|
responseSide: "stimulus" | "response",
|
||||||
|
responseRowId: string,
|
||||||
|
): SelectMissingWordsStimulusValue | null {
|
||||||
|
const isCloze = (k: string) => k.trim().toUpperCase() === "SELECT_MISSING_WORDS"
|
||||||
|
const stimulusClozes = stimulusSchema.filter((r) => isCloze(r.kind))
|
||||||
|
const responseClozes = responseSchema.filter((r) => isCloze(r.kind))
|
||||||
|
const idx =
|
||||||
|
responseSide === "response"
|
||||||
|
? responseClozes.findIndex((r) => r.id === responseRowId)
|
||||||
|
: -1
|
||||||
|
const target = idx >= 0 ? stimulusClozes[idx] : undefined
|
||||||
|
if (target) {
|
||||||
|
const parsed = parseSelectMissingWordsStimulusSlotValue(
|
||||||
|
fieldValues[`stimulus:${target.id}`],
|
||||||
|
)
|
||||||
|
if (selectMissingWordsStimulusHasContent(parsed)) return parsed
|
||||||
|
}
|
||||||
|
return findSelectMissingWordsStimulusInFieldValues(fieldValues, stimulusSchema)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user