Add question preview_text so admin bank lists show readable prompts.
DYNAMIC and outbound-dynamic questions omit question_text; preview_text exposes the learner-facing wording for search and display. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
644a781cbb
commit
f2a1d6ccf5
|
|
@ -252,6 +252,8 @@ func UsesOutboundDynamicShape(payload *DynamicQuestionPayload) bool {
|
|||
type OutboundQuestionContent struct {
|
||||
DynamicPayload *DynamicQuestionPayload
|
||||
QuestionText *string
|
||||
// PreviewText is always a human-readable prompt for admin lists/search (legacy + DYNAMIC).
|
||||
PreviewText string
|
||||
VoicePrompt *string
|
||||
SampleAnswerVoicePrompt *string
|
||||
ImageURL *string
|
||||
|
|
@ -260,9 +262,31 @@ type OutboundQuestionContent struct {
|
|||
ShortAnswers []QuestionShortAnswer
|
||||
}
|
||||
|
||||
// ResolveQuestionPreviewText returns learner-facing prompt text for list UIs and search keywords.
|
||||
// Prefer explicit question_text, then stimulus prompt text, then the stored DB column (DYNAMIC search text).
|
||||
func ResolveQuestionPreviewText(q QuestionWithDetails, catalog []QuestionTypeDefinition) string {
|
||||
payload := ResolveOutboundDynamicPayload(q, catalog)
|
||||
if text := QuestionTextJSONField(q.QuestionType, q.QuestionText); text != nil && strings.TrimSpace(*text) != "" {
|
||||
return strings.TrimSpace(*text)
|
||||
}
|
||||
if s := StimulusTextFromPayload(payload); s != "" {
|
||||
return s
|
||||
}
|
||||
if s := strings.TrimSpace(q.QuestionText); s != "" {
|
||||
return s
|
||||
}
|
||||
if q.Tips != nil {
|
||||
if s := strings.TrimSpace(*q.Tips); s != "" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// ResolveOutboundQuestionContent normalizes legacy rows to dynamic_payload for API responses.
|
||||
func ResolveOutboundQuestionContent(q QuestionWithDetails, catalog []QuestionTypeDefinition) OutboundQuestionContent {
|
||||
payload := ResolveOutboundDynamicPayload(q, catalog)
|
||||
preview := ResolveQuestionPreviewText(q, catalog)
|
||||
if !UsesOutboundDynamicShape(payload) {
|
||||
var audioCorrect *string
|
||||
if q.AudioAnswer != nil && strings.TrimSpace(q.AudioAnswer.CorrectAnswerText) != "" {
|
||||
|
|
@ -273,6 +297,7 @@ func ResolveOutboundQuestionContent(q QuestionWithDetails, catalog []QuestionTyp
|
|||
return OutboundQuestionContent{
|
||||
DynamicPayload: payload,
|
||||
QuestionText: questionText,
|
||||
PreviewText: preview,
|
||||
VoicePrompt: q.VoicePrompt,
|
||||
SampleAnswerVoicePrompt: q.SampleAnswerVoicePrompt,
|
||||
ImageURL: q.ImageURL,
|
||||
|
|
@ -281,5 +306,8 @@ func ResolveOutboundQuestionContent(q QuestionWithDetails, catalog []QuestionTyp
|
|||
ShortAnswers: q.ShortAnswers,
|
||||
}
|
||||
}
|
||||
return OutboundQuestionContent{DynamicPayload: payload}
|
||||
return OutboundQuestionContent{
|
||||
DynamicPayload: payload,
|
||||
PreviewText: preview,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,4 +90,36 @@ func TestResolveOutboundDynamicPayload_legacyMCQ(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestResolveQuestionPreviewText_dynamicFromStimulus(t *testing.T) {
|
||||
payload := &DynamicQuestionPayload{
|
||||
Stimulus: []DynamicElementInstance{
|
||||
{ID: "q1", Kind: "QUESTION_TEXT", Value: "Describe your hometown"},
|
||||
},
|
||||
}
|
||||
q := QuestionWithDetails{
|
||||
Question: Question{
|
||||
QuestionText: "Describe your hometown",
|
||||
QuestionType: "DYNAMIC",
|
||||
DynamicPayload: payload,
|
||||
},
|
||||
}
|
||||
got := ResolveQuestionPreviewText(q, nil)
|
||||
if got != "Describe your hometown" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveQuestionPreviewText_legacyMCQ(t *testing.T) {
|
||||
q := QuestionWithDetails{
|
||||
Question: Question{
|
||||
QuestionText: "Pick the correct verb",
|
||||
QuestionType: "MCQ",
|
||||
},
|
||||
}
|
||||
got := ResolveQuestionPreviewText(q, nil)
|
||||
if got != "Pick the correct verb" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func int64Ptr(v int64) *int64 { return &v }
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ type questionRes struct {
|
|||
SharedStimulus []questionSharedStimulusRes `json:"shared_stimulus,omitempty"`
|
||||
EffectiveDynamicPayload *domain.DynamicQuestionPayload `json:"effective_dynamic_payload,omitempty"`
|
||||
QuestionText *string `json:"question_text,omitempty"`
|
||||
PreviewText string `json:"preview_text,omitempty"`
|
||||
QuestionType string `json:"question_type"`
|
||||
QuestionTypeDefinitionID *int64 `json:"question_type_definition_id,omitempty"`
|
||||
DynamicPayload *domain.DynamicQuestionPayload `json:"dynamic_payload,omitempty"`
|
||||
|
|
@ -134,6 +135,7 @@ func buildQuestionRes(q domain.QuestionWithDetails, catalog []domain.QuestionTyp
|
|||
return questionRes{
|
||||
ID: q.ID,
|
||||
QuestionText: outbound.QuestionText,
|
||||
PreviewText: outbound.PreviewText,
|
||||
QuestionType: q.QuestionType,
|
||||
QuestionTypeDefinitionID: domain.ResolveEffectiveQuestionTypeDefinitionID(
|
||||
q.QuestionTypeDefinitionID,
|
||||
|
|
@ -1310,6 +1312,7 @@ type questionSetItemRes struct {
|
|||
StimulusBlockKey *string `json:"stimulus_block_key,omitempty"`
|
||||
EffectiveDynamicPayload *domain.DynamicQuestionPayload `json:"effective_dynamic_payload,omitempty"`
|
||||
QuestionText *string `json:"question_text,omitempty"`
|
||||
PreviewText string `json:"preview_text,omitempty"`
|
||||
QuestionType string `json:"question_type"`
|
||||
DynamicPayload *domain.DynamicQuestionPayload `json:"dynamic_payload,omitempty"`
|
||||
DifficultyLevel *string `json:"difficulty_level,omitempty"`
|
||||
|
|
@ -1375,6 +1378,7 @@ func questionSetItemsToRes(
|
|||
StimulusBlockKey: item.StimulusBlockKey,
|
||||
EffectiveDynamicPayload: effectivePayload,
|
||||
QuestionText: outbound.QuestionText,
|
||||
PreviewText: outbound.PreviewText,
|
||||
QuestionType: item.QuestionType,
|
||||
DynamicPayload: outbound.DynamicPayload,
|
||||
DifficultyLevel: item.DifficultyLevel,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user