Skip to content

fix: correct "All" entry count in filter panels#428

Open
caro3801 wants to merge 7 commits intomainfrom
fix/all-filter-display-value
Open

fix: correct "All" entry count in filter panels#428
caro3801 wants to merge 7 commits intomainfrom
fix/all-filter-display-value

Conversation

@caro3801
Copy link
Copy Markdown
Contributor

@caro3801 caro3801 commented Mar 26, 2026

fix: correct "All" entry count in filter panels
related to ICIJ/datashare#2019
The "All" entry in filter panels (content type, language, recommended by, starred, etc.) was incorrectly showing searchStore.total - the global document count - instead of a count meaningful to each filter type.

Changes:

  • FilterType.vue: Computes bucketsTotal as the sum of doc_count across all loaded aggregation buckets and passes it as :count to FilterTypeAll. Returns null before any buckets are fetched (keeps count hidden until data arrives).

  • FilterTypeAll.vue: Replaces the computedTotal/searchStore coupling with a count prop (Number, default null). The hadTotal guard now uses an immediate watcher on count to prevent flickering on first render. Each filter type controls its own count semantics.

  • FilterTypeRecommendedBy.vue: Overrides the #all slot to pass recommendedStore.total (sum of all recommendation counts across selected indices) as the "All" count. Uses a waitFor so count is null until the fetch resolves, preventing a premature 0.

  • FilterTypeStarred.vue: Overrides the #all slot to pass the real document total from getTotal() as the "All" count. Uses waitFor for flicker-prevention reason. Also fixes a copy-paste bug where the "Not starred" entry had name="starred". Exposes fetch for testability.


AI disclaimer
Used to write the description more cleanly
use agent to do first draft of unit test (TDD like)

@caro3801 caro3801 force-pushed the fix/all-filter-display-value branch from 1e94a69 to 57f9a50 Compare March 26, 2026 15:58
@caro3801 caro3801 marked this pull request as ready for review March 26, 2026 16:06
@caro3801 caro3801 requested a review from a team March 26, 2026 16:06
Copy link
Copy Markdown
Member

@pirhoo pirhoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Unfortunately it doesn't work as expected (I tested it manually to confirm my analysis of the code) and the count is now wrong not only for the entities filter, but also for the other filters if they have unloaded buckets pages:

Image

You should focus on overriding the count display only on named entities filters (probably by creating a new FilterTypeEntities component). The test and calculation you made works because you are only testing it with component that actually do aggregation over type:Document and because all their bucket pages are loaded. The tricky part of the entities filter is the fact that the aggregation is done on type:NamedEntites.

const fromElasticSearch = computed(() => filter?.fromElasticSearch ?? false)
const bucketsTotal = computed(() => {
if (!pages.length) return null
return buckets.value.reduce((sum, b) => sum + b.doc_count, 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crucial: this is not correct, you're are adding the "doc_count" of each bucket which is not the number of documents but the number of named entities ("doc" means ElasticSearch document here) in each bucket. Although even that value was correct, you cannot use it because it means the total increases when user load the next bucket pages. So you might have the correct number in tests because there is only one bucket page and they are the same number of documents than named entities.

Co-authored-by: Pierre Romera Zhang <hello@pirhoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants