Skip to content

Commit

Permalink
Merge pull request #177 from nih-sparc/get-contributors-from-algolia
Browse files Browse the repository at this point in the history
Update contributors to pull from algolia
  • Loading branch information
egauzens authored Aug 10, 2024
2 parents 68df230 + 67618e1 commit fecf3b1
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions pages/datasets/[datasetId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ const getOrganizationNames = async (algoliaIndex) => {
}
}
// get contributors from Algolia and replace the list retrieved from Pennsieve because the Pennsieve list is based off
// the user's Pennsieve account names instead of the dataset_description.xlsx file which is the point of truth. Refer to
// the following tickets: https://www.wrike.com/open.htm?id=1257276600 and https://www.wrike.com/open.htm?id=1215925574
const getContributorsFromAlgolia = async (algoliaIndex, id) => {
try {
const response = await algoliaIndex.getObject(id)
return response?.contributors
} catch (error) {
return []
}
}
const tabs = [
{
label: 'Abstract',
Expand Down Expand Up @@ -225,7 +237,7 @@ export default {
const datasetTypeName = typeFacet !== undefined ? typeFacet.children[0].label : 'dataset'
const store = useMainStore()
try {
let [datasetDetails, versions, downloadsSummary, sparcOrganizationNames] = await Promise.all([
let [datasetDetails, versions, downloadsSummary, sparcOrganizationNames, algoliaContributors] = await Promise.all([
getDatasetDetails(
config,
datasetId,
Expand All @@ -235,10 +247,18 @@ export default {
),
getDatasetVersions(config, datasetId, $axios),
getDownloadsSummary(config, $axios),
getOrganizationNames(algoliaIndex)
getOrganizationNames(algoliaIndex),
getContributorsFromAlgolia(algoliaIndex, datasetId)
])
const datasetDetailsContributors = algoliaContributors?.map(contributor => {
return {
firstName: contributor.first.name,
lastName: contributor.last.name,
orcid: contributor.curie?.replace('ORCID:', '')
}
})
datasetDetails = propOr(datasetDetails, 'data', datasetDetails)
datasetDetails.contributors = datasetDetailsContributors
const latestVersion = compose(propOr(1, 'version'), head)(versions)
store.setDatasetInfo({ ...datasetDetails, 'latestVersion': latestVersion })
store.setDatasetFacetsData(datasetFacetsData)
Expand All @@ -250,17 +270,17 @@ export default {
name: propOr('', 'organizationName', datasetDetails)
}
]
const contributors = datasetDetails?.contributors?.map(contributor => {
const sameAs = contributor.orcid
? `http://orcid.org/${contributor.orcid}`
const contributors = algoliaContributors?.map(contributor => {
const sameAs = contributor.curie
? `http://orcid.org/${contributor.curie.replace('ORCID:', '')}`
: null
return {
'@type': 'Person',
sameAs,
givenName: contributor.firstName,
familyName: contributor.lastName,
name: `${contributor.firstName} ${contributor.lastName}`
givenName: contributor.first?.name,
familyName: contributor.last?.name,
name: `${contributor.first?.name} ${contributor.last?.name}`
}
})
Expand Down

0 comments on commit fecf3b1

Please sign in to comment.