Skip to content

[DT-3766] Add counts, harmonize behavior across tabs#3758

Open
otchet-broad wants to merge 8 commits into
developfrom
otchet-dt-3766-asset-counts
Open

[DT-3766] Add counts, harmonize behavior across tabs#3758
otchet-broad wants to merge 8 commits into
developfrom
otchet-dt-3766-asset-counts

Conversation

@otchet-broad

Copy link
Copy Markdown
Contributor

Addresses

DT-3766

Summary

Reworks the Data Library so filters, search, and item counts behave consistently across every asset tab.

Tab count badges

  • Every tab now shows a count badge. Counts for all tabs are fetched in a single size: 0 Elasticsearch request (new useLibraryTabCounts hook + libraryCounts.ts), independent of the active tab, pagination, and sort — fetched once and reused as the user pages, sorts, and switches tabs (previous counts stay visible while refetching to avoid flicker).
  • Counts derive from one shared aggregation: total_studies (cardinality) → Studies, a datasets_count filter agg → Datasets, and a shared studies agg fed through each asset's own transformResponse, so a tab's count always matches what its grid renders.
  • STUDY_ASSET_TABS is derived from the AssetType enum, so newly added asset types are counted automatically.
  • Datasets count reuses the extracted APPROVED_CONTROLLED_SHOULD clause shared with datasetAsset.buildQuery, so badge and grid can't diverge.
  • Removed the standalone total-count text from LibraryPageShell (counts now live in the tabs). New shared COUNT_BADGE_SX pill style; new FilterAggregation elastic type.

Filters harmonized across tabs

  • Filters are no longer dropped when switching tabs. buildActiveFilterClauses applies all active filters regardless of which tab set them, so they combine like facets across tabs.
  • Filters owned by another tab appear as removable "Filters from other views" chips (getExternalActiveFilters + removeFilterValue), so users can drop them without switching tabs. New ActiveFilterChip type wired through useLibraryPageState → LibraryPageShell → LibraryFilters.
  • Active-filter indicator counts by category (stable across tabs) and shows a count badge on the collapsed panel.

Search across tabs

  • New ALL_SEARCH_FIELDS (union of every asset's search fields); search now matches the same fields on every tab, keeping grids consistent with the count badges.

Publications "Datasets Cited"

  • Added a distinct publicationsDatasetsCited boolean filter (separate from presentations' datasetsCited), with its own filter definition, URL param handling, and disambiguated labels ("...(Publications)?" vs. "...(Presentations)?"). Publications tab now exposes this filter.
  • PublicationAddEdit gains a required yes/no "Did you cite the dataset(s) used in this publication?" field, with validation in darFormUtils.

Tests

  • Added/updated specs across LibraryFilters, LibraryTabs, filterRegistry, useLibraryData, useLibraryPageState, useLibraryUrlState, the new useLibraryTabCounts, publicationAsset, and darFormUtils.

Have you read Terra's Contributing Guide lately? If not, do that first.

  • Label PR with a Jira ticket number and include a link to the ticket
  • Label PR with a security risk modifier [no, low, medium, high]
  • PR describes scope of changes
  • Get a minimum of one thumbs worth of review, preferably two if enough team members are available
  • Get PO sign-off for all non-trivial UI or workflow changes
  • Verify all tests go green
  • Test this change deployed correctly and works on dev environment after deployment

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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: 0 Elasticsearch counts query (useLibraryTabCounts + libraryCounts.ts) and renders per-tab count badges in LibraryTabs.
  • 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 publicationsDatasetsCited as 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.

Comment thread test/components/data_library/LibraryTabs.spec.tsx Outdated
Comment thread src/hooks/libraryCounts.ts
Comment thread src/components/data_library/LibraryFilters.tsx
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for DUOS Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 86.06% 9983 / 11600
🔵 Statements 85.49% 10584 / 12380
🔵 Functions 82.24% 2909 / 3537
🔵 Branches 77.96% 6096 / 7819
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/components/data_library/LibraryFilters.tsx 88.4% 83.5% 80.64% 88.05% 63, 84-91, 125, 191, 216-229, 290-296
src/components/data_library/LibraryPageShell.tsx 75% 77.77% 50% 75% 63-69, 118
src/components/data_library/LibraryTabs.tsx 100% 100% 100% 100%
src/components/data_library/countBadgeStyles.ts 100% 100% 100% 100%
src/components/data_library/filterRegistry.ts 85% 77.96% 91.3% 85.89% 173, 216-220, 224-231, 353-360, 405-409, 429-443, 461-468, 506-513, 524-536, 565, 599
src/components/data_library/assets/biospecimenAsset.ts 85.1% 73.17% 90.9% 86.95% 13, 14, 27, 32, 35, 42, 51
src/components/data_library/assets/clinicalTrialAsset.ts 86.36% 82.6% 90.9% 88.37% 18, 19, 32, 36, 40, 45
src/components/data_library/assets/datasetAsset.ts 96.15% 79.16% 100% 96.15% 71-77
src/components/data_library/assets/definition.ts 100% 100% 100% 100%
src/components/data_library/assets/fundingResourceAsset.ts 100% 86.66% 100% 100%
src/components/data_library/assets/index.ts 100% 100% 100% 100%
src/components/data_library/assets/intellectualPropertyAsset.ts 100% 87.5% 100% 100%
src/components/data_library/assets/modelAsset.ts 100% 87.5% 100% 100%
src/components/data_library/assets/presentationAsset.ts 100% 90.9% 100% 100%
src/components/data_library/assets/publicationAsset.ts 96.42% 89.58% 100% 96.42% 13
src/components/data_library/assets/workspaceAsset.ts 100% 85.71% 100% 100%
src/components/publications_list/PublicationAddEdit.tsx 77.46% 85.54% 80.95% 80.32% 59-63, 132, 185, 190, 205, 214-219, 236-238
src/hooks/libraryCounts.ts 94.11% 80% 100% 94.11% 38
src/hooks/useLibraryData.ts 100% 92.3% 100% 100%
src/hooks/useLibraryPageState.ts 78.78% 65.78% 64.51% 79.03% 92-94, 121, 124-126, 130, 132, 161, 173, 190-194
src/hooks/useLibraryTabCounts.ts 100% 100% 100% 100%
src/hooks/useLibraryUrlState.ts 94.65% 91.01% 100% 94.3% 145, 156-158, 171, 178, 283
src/libs/dataLibraryFilterConfig.ts 100% 100% 100% 100%
src/pages/DataLibrary.tsx 91.42% 94.73% 91.66% 91.04% 94, 105-106, 133-134, 141
src/pages/researcher_console/DatasetSubmissions.tsx 94.73% 50% 100% 100% 48, 95
src/types/library.ts 100% 100% 100% 100%
src/utils/darFormUtils.ts 84.18% 80.93% 100% 84.21% 139, 154, 219, 224, 227-235, 264, 270, 276, 287-294, 297, 307, 310-319, 340, 343, 346, 355
Generated in workflow #6281 for commit bbb65ea by the Vitest Coverage Report Action

@otchet-broad otchet-broad marked this pull request as ready for review July 10, 2026 13:34
@otchet-broad otchet-broad requested a review from a team as a code owner July 10, 2026 13:34
@otchet-broad otchet-broad requested review from fboulnois, kevinmarete and rushtong and removed request for a team July 10, 2026 13:34

@rushtong rushtong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Address feedback as you see fit, either here or in separate tickets/PRs. I think this is still worth moving forward, great work 👍🏽

Comment thread test/pages/researcher_console/DatasetSubmissions.spec.tsx
Comment thread src/components/data_library/filterRegistry.ts Outdated
Comment thread src/hooks/libraryCounts.ts Outdated
Comment thread src/hooks/libraryCounts.ts
Comment thread src/components/data_library/filterRegistry.ts Outdated
Comment thread src/hooks/useLibraryUrlState.ts
},
datasetsCited: {
label: 'Datasets Cited?',
label: 'Datasets Cited (Presentations)?',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I'll hold off on this one to make sure Jonathan has time to think about this.

@sonarqubecloud

Copy link
Copy Markdown

@kevinmarete kevinmarete left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent work 👍🏾

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.

4 participants