Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions client/src/components/ConditionalRender.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,26 @@ function RecursiveConditionalRender({ conditions, children }) {
let conditionMet = false;
if (position === "percentAgreement") {
const counts = {};
referenceValues.forEach((val) => {
const cleanValue =
typeof val === "string" ? val.toLowerCase().trim() : val;
counts[cleanValue] = (counts[cleanValue] || 0) + 1;
});
const maxCount = Math.max(...Object.values(counts));
conditionMet = compare(
(maxCount / referenceValues.length) * 100,
comparator,
value
);
const definedValues = referenceValues.filter(val => val !== undefined);

// If no defined values, no agreement is possible
if (definedValues.length === 0) {
conditionMet = false;
} else {
definedValues.forEach((val) => {
const cleanValue =
typeof val === "string" ? val.toLowerCase().trim() : val;
counts[cleanValue] = (counts[cleanValue] || 0) + 1;
});
const maxCount = Math.max(...Object.values(counts));
// Use total participants (referenceValues.length) as denominator
// to include undefined responses in the consensus calculation
conditionMet = compare(
(maxCount / referenceValues.length) * 100,
comparator,
value
);
}
} else if (position === "any") {
conditionMet = referenceValues.some((val) =>
compare(val, comparator, value)
Expand Down
Loading