Skip to content

Commit

Permalink
John conroy/publication collection aggs HMP-270 (#3172)
Browse files Browse the repository at this point in the history
* Get aggs for summary from associated collection if present

* Add changelog

* Add changelog

---------

Co-authored-by: John Conroy <[email protected]>
  • Loading branch information
john-conroy and john-conroy authored Jul 14, 2023
1 parent c6a26ee commit 82cd8c9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-publication-collection-aggs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Get publication summary data types and organs from associated collection if applicable.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
58 changes: 39 additions & 19 deletions context/app/static/js/components/publications/AggsList/hooks.js
Original file line number Diff line number Diff line change
@@ -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 };
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -74,15 +75,19 @@ function PublicationSummary({
childContainerComponent="div"
data-testid="publication-data-types"
>
<AggsList uuid={uuid} field="mapped_data_types" />
<AggsList uuid={uuid} field="mapped_data_types" associatedCollectionUUID={associatedCollectionUUID} />
</LabelledSectionText>
<LabelledSectionText
label="Organs"
bottomSpacing={2}
childContainerComponent="div"
data-testid="publication-organs"
>
<AggsList uuid={uuid} field="mapped_organ" />
<AggsList
uuid={uuid}
field="origin_samples.mapped_organ"
associatedCollectionUUID={associatedCollectionUUID}
/>
</LabelledSectionText>
<LabelledSectionText
label={isPublished ? 'Publication Date' : 'Preprint Date'}
Expand Down
7 changes: 6 additions & 1 deletion context/app/static/js/pages/Publication/Publication.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ function Publication({ publication, vignette_json }) {

return (
<DetailLayout sectionOrder={sectionOrder}>
<PublicationSummary {...publication} status={combinedStatus} hasDOI={hasDOI} />
<PublicationSummary
{...publication}
status={combinedStatus}
hasDOI={hasDOI}
associatedCollectionUUID={associatedCollectionUUID}
/>
<PublicationsDataSection
uuid={uuid}
datasetUUIDs={ancestor_ids}
Expand Down

0 comments on commit 82cd8c9

Please sign in to comment.