Add other answers to issue questions

This commit is contained in:
Dotta
2026-05-25 15:06:38 +00:00
parent f360fcbbb3
commit 4afe5ab7cb
9 changed files with 230 additions and 16 deletions
+2 -1
View File
@@ -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"]);
});
});
+6 -3
View File
@@ -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;
}