Fix cases of draw with most common answers

This commit is contained in:
Joao Victor 2022-02-23 17:40:13 -03:00
parent aff0d4006e
commit febd19d740

View File

@ -174,20 +174,29 @@ const UserDatailsComponent = (props) => {
function renderPollItem(poll, answers) {
const { anonymous: isAnonymous, question, pollId } = poll;
const mostCommomAnswer = Object
const answersSorted = Object
.entries(pollVotesCount[pollId])
.sort(([, countA], [, countB]) => countB - countA)[0]?.[0];
.sort(([, countA], [, countB]) => countB - countA);
let mostCommonAnswer = answersSorted[0]?.[0];
const mostCommonAnswerCount = answersSorted[0]?.[1];
if (mostCommonAnswer && mostCommonAnswerCount) {
const hasDraw = answersSorted[1]?.[1] === mostCommonAnswerCount;
if (hasDraw) mostCommonAnswer = null;
}
return (
<div className="p-6 flex flex-row justify-between items-center">
<div className="min-w-[40%] text-ellipsis">{question}</div>
{ isAnonymous ? (
<div
className="min-w-[20%] grow text-center mx-3"
>
<span
title={intl.formatMessage({
id: 'app.learningDashboard.userDetails.anonymousAnswer',
defaultMessage: 'Anonymous Poll',
})}
className="mx-3"
>
<svg
xmlns="http://www.w3.org/2000/svg"
@ -204,17 +213,18 @@ const UserDatailsComponent = (props) => {
/>
</svg>
</span>
</div>
) : (
<div className="min-w-[20%] grow text-center mx-3">{answers.map((answer) => <p title={answer} className="overflow-hidden text-ellipsis">{answer}</p>)}</div>
) }
<div
className="min-w-[40%] text-ellipsis text-center overflow-hidden"
title={mostCommomAnswer
? `${String.fromCharCode(mostCommomAnswer.charCodeAt(0) - 32)}${mostCommomAnswer.substring(1)}`
title={mostCommonAnswer
? `${String.fromCharCode(mostCommonAnswer.charCodeAt(0) - 32)}${mostCommonAnswer.substring(1)}`
: null}
>
{ mostCommomAnswer
? `${String.fromCharCode(mostCommomAnswer.charCodeAt(0) - 32)}${mostCommomAnswer.substring(1)}`
{ mostCommonAnswer
? `${String.fromCharCode(mostCommonAnswer.charCodeAt(0) - 32)}${mostCommonAnswer.substring(1)}`
: intl.formatMessage({
id: 'app.learningDashboard.usersTable.notAvailable',
defaultMessage: 'N/A',