fix: column ordering (#4621)

This commit is contained in:
Dhruwang Jariwala
2025-01-21 10:36:43 +05:30
committed by GitHub
parent 25f99da172
commit f68f87645f
3 changed files with 16 additions and 7 deletions
@@ -48,7 +48,9 @@ export const MatrixQuestionSummary = ({
return "";
};
const columns = questionSummary.data[0] ? Object.keys(questionSummary.data[0].columnPercentages) : [];
const columns = questionSummary.data[0]
? questionSummary.data[0].columnPercentages.map((c) => c.column)
: [];
return (
<div className="rounded-xl border border-slate-200 bg-white shadow-sm">
@@ -81,7 +83,7 @@ export const MatrixQuestionSummary = ({
<p className="max-w-40 overflow-hidden text-ellipsis whitespace-nowrap">{rowLabel}</p>
</TooltipRenderer>
</td>
{Object.entries(columnPercentages).map(([column, percentage]) => (
{columnPercentages.map(({ column, percentage }) => (
<td
key={column}
className="text-center text-slate-500 dark:border-slate-700 dark:text-slate-400">
@@ -778,13 +778,15 @@ export const getQuestionSummary = async (
totalResponsesForRow += countMap[row][col];
});
const columnPercentages = columns.reduce((acc, col) => {
const columnPercentages = columns.map((col) => {
const count = countMap[row][col];
const percentage =
totalResponsesForRow > 0 ? ((count / totalResponsesForRow) * 100).toFixed(2) : "0.00";
acc[col] = percentage;
return acc;
}, {});
return {
column: col,
percentage: Number(percentage),
};
});
return { rowLabel: row, columnPercentages, totalResponsesForRow };
});