chore: improve accessibility for matrix question (#5320)

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
Dhruwang Jariwala
2025-04-12 10:10:24 +05:30
committed by GitHub
parent ca4f8385e4
commit c533f37983
3 changed files with 34 additions and 8 deletions
@@ -71,7 +71,11 @@ const getQuestionColumnsData = (
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2 overflow-hidden">
<span className="h-4 w-4">{QUESTIONS_ICON_MAP["matrix"]}</span>
<span className="truncate">{getLocalizedValue(matrixRow, "default")}</span>
<span className="truncate">
{getLocalizedValue(question.headline, "default") +
" - " +
getLocalizedValue(matrixRow, "default")}
</span>
</div>
</div>
);
+1 -1
View File
@@ -390,7 +390,7 @@ export const getResponseDownloadUrl = async (
"Notes",
"Tags",
...metaDataFields,
...questions,
...questions.flat(),
...variables,
...hiddenFields,
...userAttributes,
+28 -6
View File
@@ -472,7 +472,13 @@ export const extractSurveyDetails = (survey: TSurvey, responses: TResponse[]) =>
const metaDataFields = responses.length > 0 ? extracMetadataKeys(responses[0].meta) : [];
const questions = survey.questions.map((question, idx) => {
const headline = getLocalizedValue(question.headline, "default") ?? question.id;
return `${idx + 1}. ${headline}`;
if (question.type === "matrix") {
return question.rows.map((row) => {
return `${idx + 1}. ${headline} - ${getLocalizedValue(row, "default")}`;
});
} else {
return [`${idx + 1}. ${headline}`];
}
});
const hiddenFields = survey.hiddenFields?.fieldIds || [];
const userAttributes =
@@ -487,7 +493,7 @@ export const extractSurveyDetails = (survey: TSurvey, responses: TResponse[]) =>
export const getResponsesJson = (
survey: TSurvey,
responses: TResponse[],
questions: string[],
questionsHeadlines: string[][],
userAttributes: string[],
hiddenFields: string[]
): Record<string, string | number>[] => {
@@ -519,10 +525,26 @@ export const getResponsesJson = (
});
// survey response data
questions.forEach((question, i) => {
const questionId = survey?.questions[i].id || "";
const answer = response.data[questionId];
jsonData[idx][question] = processResponseData(answer);
questionsHeadlines.forEach((questionHeadline) => {
const questionIndex = parseInt(questionHeadline[0]) - 1;
const question = survey?.questions[questionIndex];
const answer = response.data[question.id];
if (question.type === "matrix") {
// For matrix questions, we need to handle each row separately
questionHeadline.forEach((headline, index) => {
if (answer) {
const row = question.rows[index];
if (row && row.default && answer[row.default] !== undefined) {
jsonData[idx][headline] = answer[row.default];
} else {
jsonData[idx][headline] = "";
}
}
});
} else {
jsonData[idx][questionHeadline[0]] = processResponseData(answer);
}
});
survey.variables?.forEach((variable) => {