Skip to content

Commit

Permalink
WIP: Forced-visible count in selected mode should include top-level o…
Browse files Browse the repository at this point in the history
…nly.
  • Loading branch information
lyzadanger committed Aug 12, 2020
1 parent feb4c13 commit 914dc0c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/sidebar/components/filter-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ export default function FilterStatus() {
// forced-visible threads out to get a correct count of actual filter matches.
// In 'selection' mode, rely on the count of selected annotations
const visibleCount = countVisible(rootThread);
const visibleAnnotationCount = rootThread.children.filter(
thread => thread.annotation && thread.visible
).length;

const resultCount =
filterMode === 'selection'
? filterState.selectedCount
: visibleCount - filterState.forcedVisibleCount;

const additionalCount =
filterMode === 'selection'
? visibleAnnotationCount - resultCount
: filterState.forcedVisibleCount;

let buttonText;
switch (filterMode) {
case 'selection':
Expand Down Expand Up @@ -130,7 +139,7 @@ export default function FilterStatus() {

// In most cases, the action button will clear the current (filter) selection,
// but when in 'focusOnly' mode, it will toggle activation of the focus
if (filterMode === 'focusOnly' && !filterState.forcedVisibleCount) {
if (filterMode === 'focusOnly' && !additionalCount) {
buttonProps.onClick = () => toggleFocusMode();
}

Expand All @@ -141,7 +150,7 @@ export default function FilterStatus() {
{resultCount > 0 && <span>Showing </span>}
<span className="filter-facet">
{resultCount > 0 ? resultCount : 'No'}{' '}
{filterMode === 'selection' && filterState.forcedVisibleCount > 0
{filterMode === 'selection' && additionalCount > 0
? 'selected '
: ''}
{filterMode === 'query' ? 'result' : 'annotation'}
Expand All @@ -165,10 +174,10 @@ export default function FilterStatus() {
</span>
</span>
)}
{filterState.forcedVisibleCount > 0 && (
{additionalCount > 0 && (
<span className="filter-facet--muted">
{' '}
(and {filterState.forcedVisibleCount} more)
(and {additionalCount} more)
</span>
)}
</div>
Expand Down

0 comments on commit 914dc0c

Please sign in to comment.