-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
c6a26ee
commit 82cd8c9
Showing
5 changed files
with
60 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 39 additions & 19 deletions
58
context/app/static/js/components/publications/AggsList/hooks.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters