[DT-3766] Add counts, harmonize behavior across tabs#3758
Conversation
…e filters from other tabs.
There was a problem hiding this comment.
Pull request overview
This PR reworks the Data Library’s cross-tab behavior so tab counts, search, and filters remain consistent when users switch asset tabs, and adds a distinct “Datasets Cited (Publications)?” filter plus a required citation yes/no field for publications.
Changes:
- Adds a dedicated
size: 0Elasticsearch counts query (useLibraryTabCounts+libraryCounts.ts) and renders per-tab count badges inLibraryTabs. - Harmonizes cross-tab behavior by applying all active filters and a unified search field union (
ALL_SEARCH_FIELDS) on every tab, plus “Filters from other views” removable chips. - Introduces
publicationsDatasetsCitedas a separate boolean filter (URL parse/serialize, filter registry/config, publication transform + validation + tests).
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/utils/darFormUtils.spec.ts | Adds coverage for the new required publication citation field validation. |
| test/pages/researcher_console/DatasetSubmissions.spec.tsx | Updates useLibraryPageState mock shape for new tab counts + external-filter handling. |
| test/hooks/useLibraryUrlState.spec.tsx | Adds harness-based tests for independent boolean URL params and legacy alias handling. |
| test/hooks/useLibraryTabCounts.spec.tsx | New tests verifying one shared size:0 request and count derivation behavior. |
| test/hooks/useLibraryPageState.spec.tsx | New tests for tab-count wiring and external-filter removal handler behavior. |
| test/hooks/useLibraryData.spec.tsx | Updates query-building tests for shared search fields, shared filters, and removal of count-aggs from data queries. |
| test/components/data_library/LibraryTabs.spec.tsx | Adds tab count badge rendering tests. |
| test/components/data_library/LibraryFilters.spec.tsx | Adds tests for external filter chips, collapsed indicator count, and boolean filter label changes. |
| test/components/data_library/filterRegistry.spec.ts | Updates tests for new “active filters across tabs” behavior, external chip generation, and filter removal helper. |
| test/components/data_library/assets/publicationAsset.spec.ts | Updates expected filter key for publications citation filtering. |
| src/utils/darFormUtils.ts | Makes publication citation (yes/no) required in validation. |
| src/types/library.ts | Adds publicationsDatasetsCited filter state, plus ActiveFilterChip and new props for external filters. |
| src/types/elastic.ts | Adds a FilterAggregation type used by the counts query aggregation definitions. |
| src/libs/dataLibraryFilterConfig.ts | Registers publicationsDatasetsCited as visible on the Publications tab. |
| src/hooks/useLibraryUrlState.ts | Refactors boolean param parsing/serialization and makes citation params independent (with legacy alias support). |
| src/hooks/useLibraryTabCounts.ts | New hook fetching and caching all tab counts via one shared counts query. |
| src/hooks/useLibraryPageState.ts | Wires in tab counts + external filter chip modeling and adds a handler to remove external filter values. |
| src/hooks/useLibraryData.ts | Applies all active filters on every tab and switches search to the union of all asset search fields. |
| src/hooks/libraryCounts.ts | New shared aggregation builders and count computation for all tabs from one response. |
| src/components/publications_list/PublicationAddEdit.tsx | Adds required yes/no radio field for publication dataset citation. |
| src/components/data_library/LibraryTabs.tsx | Renders per-tab count badges using shared badge styling. |
| src/components/data_library/LibraryPageShell.tsx | Removes standalone total text and passes tabCounts + external filter props through to tabs/filters. |
| src/components/data_library/LibraryFilters.tsx | Adds “external filters” chip section and collapsed-panel active-filter count indicator. |
| src/components/data_library/filterRegistry.ts | Reworks registry to build clauses from all active filters, add external chip derivation, and add removeFilterValue. |
| src/components/data_library/countBadgeStyles.ts | New shared MUI sx pill style used for count badges. |
| src/components/data_library/assets/publicationAsset.ts | Switches publication filtering to publicationsDatasetsCited. |
| src/components/data_library/assets/index.ts | Exports ALL_SEARCH_FIELDS as the union of asset search fields. |
| src/components/data_library/assets/datasetAsset.ts | Extracts approved-controlled visibility clause for reuse by the counts query. |
rushtong
left a comment
There was a problem hiding this comment.
Address feedback as you see fit, either here or in separate tickets/PRs. I think this is still worth moving forward, great work 👍🏽
| }, | ||
| datasetsCited: { | ||
| label: 'Datasets Cited?', | ||
| label: 'Datasets Cited (Presentations)?', |
There was a problem hiding this comment.
I confirmed this Claude finding, the UX is worth cleaning up at some point:
A user sets 'No' on the Presentations tab and switches to Studies: studies with no presentations at all (the common case) vanish, though 'No' reads as 'did not cite'. The semantics predate this PR and the filter is visible/removable via external chips, but the PR widens its blast radius from one tab to all tabs — worth a product-level double-check that 'No' should require a presentation to exist.
There was a problem hiding this comment.
I think I'll hold off on this one to make sure Jonathan has time to think about this.
|



Addresses
DT-3766
Summary
Reworks the Data Library so filters, search, and item counts behave consistently across every asset tab.
Tab count badges
Filters harmonized across tabs
Search across tabs
Publications "Datasets Cited"
Tests
Have you read Terra's Contributing Guide lately? If not, do that first.