Add other answers to issue questions
This commit is contained in:
@@ -141,10 +141,11 @@ describe("issue thread interaction helpers", () => {
|
||||
{
|
||||
questionId: "question-1",
|
||||
optionIds: ["option-2", "option-1"],
|
||||
otherText: "A written answer",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(labels).toEqual(["Option 2", "Option 1"]);
|
||||
expect(labels).toEqual(["Option 2", "Option 1", "Other: A written answer"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -132,12 +132,15 @@ export function getQuestionAnswerLabels(args: {
|
||||
answers: readonly AskUserQuestionsAnswer[];
|
||||
}) {
|
||||
const { question, answers } = args;
|
||||
const selectedIds =
|
||||
answers.find((answer) => answer.questionId === question.id)?.optionIds ?? [];
|
||||
const answer = answers.find((candidate) => candidate.questionId === question.id);
|
||||
const selectedIds = answer?.optionIds ?? [];
|
||||
const optionLabelById = new Map(
|
||||
question.options.map((option) => [option.id, option.label] as const),
|
||||
);
|
||||
return selectedIds
|
||||
const labels = selectedIds
|
||||
.map((optionId) => optionLabelById.get(optionId))
|
||||
.filter((label): label is string => typeof label === "string");
|
||||
const otherText = answer?.otherText?.trim();
|
||||
if (otherText) labels.push(`Other: ${otherText}`);
|
||||
return labels;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user