Fall back to response text when building question preview_text.
Some interactive questions only have readable wording in response slots; include that so admin bank lists and search have usable prompts. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
f2a1d6ccf5
commit
291e1837c7
|
|
@ -263,7 +263,7 @@ type OutboundQuestionContent struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveQuestionPreviewText returns learner-facing prompt text for list UIs and search keywords.
|
// 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).
|
// Prefer explicit question_text, then stimulus prompt text, then response text, then stored DB column.
|
||||||
func ResolveQuestionPreviewText(q QuestionWithDetails, catalog []QuestionTypeDefinition) string {
|
func ResolveQuestionPreviewText(q QuestionWithDetails, catalog []QuestionTypeDefinition) string {
|
||||||
payload := ResolveOutboundDynamicPayload(q, catalog)
|
payload := ResolveOutboundDynamicPayload(q, catalog)
|
||||||
if text := QuestionTextJSONField(q.QuestionType, q.QuestionText); text != nil && strings.TrimSpace(*text) != "" {
|
if text := QuestionTextJSONField(q.QuestionType, q.QuestionText); text != nil && strings.TrimSpace(*text) != "" {
|
||||||
|
|
@ -272,6 +272,9 @@ func ResolveQuestionPreviewText(q QuestionWithDetails, catalog []QuestionTypeDef
|
||||||
if s := StimulusTextFromPayload(payload); s != "" {
|
if s := StimulusTextFromPayload(payload); s != "" {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
if s := firstReadableTextFromElements(payloadResponseElements(payload)); s != "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
if s := strings.TrimSpace(q.QuestionText); s != "" {
|
if s := strings.TrimSpace(q.QuestionText); s != "" {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
@ -283,6 +286,56 @@ func ResolveQuestionPreviewText(q QuestionWithDetails, catalog []QuestionTypeDef
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func payloadResponseElements(payload *DynamicQuestionPayload) []DynamicElementInstance {
|
||||||
|
if payload == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return payload.Response
|
||||||
|
}
|
||||||
|
|
||||||
|
func firstReadableTextFromElements(elements []DynamicElementInstance) string {
|
||||||
|
for _, el := range elements {
|
||||||
|
if s := nestedReadableString(el.Value); s != "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func nestedReadableString(v interface{}) string {
|
||||||
|
if v == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
switch t := v.(type) {
|
||||||
|
case string:
|
||||||
|
s := strings.TrimSpace(t)
|
||||||
|
if s == "" || strings.HasPrefix(strings.ToLower(s), "http://") || strings.HasPrefix(strings.ToLower(s), "https://") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
case map[string]interface{}:
|
||||||
|
for _, key := range []string{"text", "content", "value", "label", "prompt", "instruction", "option_text"} {
|
||||||
|
if nested, ok := t[key]; ok {
|
||||||
|
if s := nestedReadableString(nested); s != "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, nested := range t {
|
||||||
|
if s := nestedReadableString(nested); s != "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case []interface{}:
|
||||||
|
for _, nested := range t {
|
||||||
|
if s := nestedReadableString(nested); s != "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// ResolveOutboundQuestionContent normalizes legacy rows to dynamic_payload for API responses.
|
// ResolveOutboundQuestionContent normalizes legacy rows to dynamic_payload for API responses.
|
||||||
func ResolveOutboundQuestionContent(q QuestionWithDetails, catalog []QuestionTypeDefinition) OutboundQuestionContent {
|
func ResolveOutboundQuestionContent(q QuestionWithDetails, catalog []QuestionTypeDefinition) OutboundQuestionContent {
|
||||||
payload := ResolveOutboundDynamicPayload(q, catalog)
|
payload := ResolveOutboundDynamicPayload(q, catalog)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user