From 5d29e978eaf2dc98905199c97cd6eedcc0d7230b Mon Sep 17 00:00:00 2001 From: james hadfield Date: Wed, 12 Jun 2024 14:39:15 +1200 Subject: [PATCH] Update filter badges for multiple trees The previous implementation only reflected counts in the LHS tree, irregardless of any occurrences which may or may not be present in the RHS tree. We now communicate both. This also fixes a bug introduced in the previous commit where filtering to a traitName not present in the LHS tree would cause an uncaught exception. --- src/components/info/filtersSummary.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/info/filtersSummary.js b/src/components/info/filtersSummary.js index f905695ab..fce050231 100644 --- a/src/components/info/filtersSummary.js +++ b/src/components/info/filtersSummary.js @@ -33,6 +33,7 @@ const closeBracketSmall = a.value < b.value ? -1 : a.value > b.value ? 1 : 0) .map((item) => { let label = `${item.value}`; - if (filterName!==strainSymbol) label+= ` (${this.props.totalStateCounts[filterName].get(item.value)})`; + if (filterName!==strainSymbol) { + /* Add the _total_ occurrences in parentheses. We don't compute the intersections / visible values here - + e.g. we can have "England (5)" "North America (100)" even though such an intersection will deselect everything. + If we have two trees shown we show both values. + */ + const tree1count = this.props.totalStateCounts[filterName]?.get(item.value) ?? 0; + if (this.props.totalStateCountsSecondTree) { + const tree2count = this.props.totalStateCountsSecondTree[filterName]?.get(item.value) ?? 0; + label+=` (L: ${tree1count}, R: ${tree2count})`; + } else { + label+=` (${tree1count})`; + } + } return this.createIndividualBadge({filterName, item, label, onHoverMessage}); }); }