From 82cd8c98c9c3ece81b1c299faf6bd41b789d1d5c Mon Sep 17 00:00:00 2001 From: John Conroy <62477388+john-conroy@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:56:10 -0400 Subject: [PATCH] John conroy/publication collection aggs HMP-270 (#3172) * Get aggs for summary from associated collection if present * Add changelog * Add changelog --------- Co-authored-by: John Conroy --- CHANGELOG-publication-collection-aggs.md | 1 + .../publications/AggsList/AggsList.jsx | 10 +++- .../components/publications/AggsList/hooks.js | 58 +++++++++++++------ .../PublicationSummary/PublicationSummary.jsx | 9 ++- .../js/pages/Publication/Publication.jsx | 7 ++- 5 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 CHANGELOG-publication-collection-aggs.md diff --git a/CHANGELOG-publication-collection-aggs.md b/CHANGELOG-publication-collection-aggs.md new file mode 100644 index 0000000000..c2fa5cf813 --- /dev/null +++ b/CHANGELOG-publication-collection-aggs.md @@ -0,0 +1 @@ +- Get publication summary data types and organs from associated collection if applicable. \ No newline at end of file diff --git a/context/app/static/js/components/publications/AggsList/AggsList.jsx b/context/app/static/js/components/publications/AggsList/AggsList.jsx index a3b6d632c3..b9586442de 100644 --- a/context/app/static/js/components/publications/AggsList/AggsList.jsx +++ b/context/app/static/js/components/publications/AggsList/AggsList.jsx @@ -2,10 +2,14 @@ import React from 'react'; import BulletedList from 'js/shared-styles/lists/bulleted-lists/BulletedList'; import BulletedListItem from 'js/shared-styles/lists/bulleted-lists/BulletedListItem'; -import { useAncestorSearchAggs } from './hooks'; +import { usePublicationDatasetsAggs } from './hooks'; -function AggsList({ uuid, field }) { - const { searchData } = useAncestorSearchAggs(uuid, field); +function AggsList({ uuid, field, associatedCollectionUUID }) { + const { searchData } = usePublicationDatasetsAggs({ + descendantUUID: uuid, + aggsField: field, + associatedCollectionUUID, + }); const buckets = searchData?.aggregations?.[field]?.buckets; diff --git a/context/app/static/js/components/publications/AggsList/hooks.js b/context/app/static/js/components/publications/AggsList/hooks.js index cb8be26e67..2b714dd42e 100644 --- a/context/app/static/js/components/publications/AggsList/hooks.js +++ b/context/app/static/js/components/publications/AggsList/hooks.js @@ -1,26 +1,46 @@ -import { useMemo } from 'react'; +import useSearchData, { useSearchHits } from 'js/hooks/useSearchData'; +import { getAncestorsQuery, getIDsQuery } from 'js/helpers/queries'; -import useSearchData from 'js/hooks/useSearchData'; -import { getAncestorsQuery } from 'js/helpers/queries'; - -function useAncestorSearchAggs(descendantUUID, aggsField) { - const query = useMemo( - () => ({ - query: getAncestorsQuery(descendantUUID, 'dataset'), - aggs: { - [aggsField]: { - terms: { - field: `${aggsField}.keyword`, - size: 10000, - }, +function getAggsClause(aggsField) { + return { + aggs: { + [aggsField]: { + terms: { + field: `${aggsField}.keyword`, + size: 10000, }, }, - size: 0, - }), - [aggsField, descendantUUID], - ); + }, + size: 0, + }; +} + +function getCollectionDatasetsQuery(collectionUUID) { + return { + query: getIDsQuery(collectionUUID), + _source: 'datasets.uuid', + size: 10000, + }; +} + +function usePublicationDatasetsAggs({ descendantUUID, aggsField, associatedCollectionUUID }) { + const { searchHits: collectionDatasets } = useSearchHits(getCollectionDatasetsQuery(associatedCollectionUUID)); + + const collectionDatasetsUUIDs = + // eslint-disable-next-line no-underscore-dangle + collectionDatasets.length > 0 ? collectionDatasets[0]?._source?.datasets.map(({ uuid }) => uuid) : []; + + const query = associatedCollectionUUID + ? { + query: getIDsQuery(collectionDatasetsUUIDs), + ...getAggsClause(aggsField), + } + : { + query: getAncestorsQuery(descendantUUID, 'dataset'), + ...getAggsClause(aggsField), + }; return useSearchData(query); } -export { useAncestorSearchAggs }; +export { usePublicationDatasetsAggs }; diff --git a/context/app/static/js/components/publications/PublicationSummary/PublicationSummary.jsx b/context/app/static/js/components/publications/PublicationSummary/PublicationSummary.jsx index 3401b1bf08..383a5a04ab 100644 --- a/context/app/static/js/components/publications/PublicationSummary/PublicationSummary.jsx +++ b/context/app/static/js/components/publications/PublicationSummary/PublicationSummary.jsx @@ -27,6 +27,7 @@ function PublicationSummary({ hubmap_id, publication_date, publication_status: isPublished, + associatedCollectionUUID, }) { const hasDOI = Boolean(publication_doi); const doiURL = `https://doi.org/${publication_doi}`; @@ -74,7 +75,7 @@ function PublicationSummary({ childContainerComponent="div" data-testid="publication-data-types" > - + - + - +