Skip to content

Commit

Permalink
fix(authors): Tag cloud now use authors/domains data
Browse files Browse the repository at this point in the history
  • Loading branch information
folland87 committed Sep 19, 2024
1 parent 701ab1e commit bf4f71f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 41 deletions.
39 changes: 15 additions & 24 deletions client/src/api/authors/[id]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const PUBLICATION_LIGHT_SOURCE = [

const AUTHOR_SOURCE = [
"_id", "id", "idref", "orcid", "fullName", "firstName", "lastName",
"externalIds", "awards", "recentAffiliations",
"externalIds", "awards", "recentAffiliations", "domains"
]

async function getAuthorsPublicationsById(id: string): Promise<AuthorsPublications> {
Expand All @@ -18,17 +18,6 @@ async function getAuthorsPublicationsById(id: string): Promise<AuthorsPublicatio
query: { bool: { filter: [{ term: { "authors.person.keyword": id } }] } },
sort: [{ year: { order: "desc" } }],
aggs: {
wikis: {
filter: { term: { "domains.type.keyword": "wikidata" } },
aggs: {
wiki: {
terms: {
size: 30,
field: "domains.label.default.keyword",
}
}
}
},
byYear: {
terms: {
field: "year",
Expand Down Expand Up @@ -86,30 +75,32 @@ async function getAuthorsPublicationsById(id: string): Promise<AuthorsPublicatio
normalizedCount: element.doc_count * 100 / _100Year,
}
}).sort((a, b) => a.label - b.label).reduce(fillWithMissingYears, []) || [];
const wikis = aggregations?.wikis?.wiki?.buckets?.map((element) => {
return {
value: element.key,
count: element.doc_count,
label: element.key,
}
}) || [];

return { publications, publicationsCount, coAuthors, wikis, reviews, byYear }
return { publications, publicationsCount, coAuthors, reviews, byYear }
}

export async function getAuthorById(id: string): Promise<Author> {
const body: any = {
_source: AUTHOR_SOURCE,
query: { bool: { filter: [{term: { "id.keyword": id }}] } },
query: { bool: { filter: [{ term: { "id.keyword": id } }] } },
}
const authorQuery = fetch(
`${authorsIndex}/_search`,
{method: 'POST', body: JSON.stringify(body), headers: postHeaders}
{ method: 'POST', body: JSON.stringify(body), headers: postHeaders }
).then(r => r.json())
const publicationsQuery = getAuthorsPublicationsById(id)
const [author, publications] = await Promise.all([authorQuery, publicationsQuery])
const authorData = author?.hits?.hits?.[0]?._source || {}
const _id = author?.hits?.hits?.[0]?._id
if (!Object.keys(authorData).length) throw new Error('404');
return { ...authorData, _id, publications }
}
const wikis = authorData?.domains
?.filter((el) => el.type === 'wikidata')
?.sort((a, b) => b.count - a.count)
?.slice(0, 30)
?.map((el) => ({
label: el.label?.default,
value: el.code,
count: el.count,
})) || []
return { ...authorData, wikis, _id, publications }
}
4 changes: 2 additions & 2 deletions client/src/components/tag-cloud/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ export default function TagCloud({ data, order = 'random' }: { data: Aggregation
color="blue-cumulus"
href={`/search/publications?q="${element.value}"`}
>
{element.value}
{element.label}
{/* <span className="fr-tooltip fr-placement" id={`tooltip-${element.value}-${element.weight}`} role="tooltip" aria-hidden="true">
{element.count > 1 ? 'résultats' : 'résultat'}
</span> */}
</Badge>
))}
</BadgeGroup>
)
}
}
10 changes: 5 additions & 5 deletions client/src/pages/authors/[id]/components/author.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getOaInfo(publi) {
export default function AuthorPage({ data }: { data: Author }) {
const intl = useIntl();
const { publications: publicationsObject, awards } = data;
const { wikis, coAuthors, reviews, byYear, publications } =
const { coAuthors, reviews, byYear, publications } =
publicationsObject;

const maxCommonPublications =
Expand All @@ -44,14 +44,14 @@ export default function AuthorPage({ data }: { data: Author }) {
return (
publi.type === "thesis" &&
publi.authors.find((author) => author.person === data.id)?.role ===
"author"
"author"
);
});
const thesisParticipations = publications?.filter((publi) => {
return (
publi.type === "thesis" &&
publi.authors.find((author) => author.person === data.id)?.role !==
"author"
"author"
);
});
const others = publications?.filter((publi) => publi.type !== "thesis");
Expand Down Expand Up @@ -96,13 +96,13 @@ export default function AuthorPage({ data }: { data: Author }) {
<PageSection
icon="lightbulb-line"
size="lead"
show={!!wikis?.length}
show={!!data?.wikis?.length}
title={intl.formatMessage({ id: "authors.section.wiki.title" })}
description={intl.formatMessage({
id: "authors.section.wiki.desc",
})}
>
<TagCloud data={wikis} order="random" />
<TagCloud data={data?.wikis} order="random" />
</PageSection>
<PageSection
size="lead"
Expand Down
13 changes: 3 additions & 10 deletions client/src/types/author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type Author = {
fullName: string;
firstName?: string;
lastName?: string;
wikis: Aggregation[];
externalIds: {
id: string;
type: string;
Expand All @@ -57,21 +58,13 @@ export type Author = {
label: string;
}[];
recentAffiliations: RecentAffiliation[];
publications: {
publicationsCount: number;
publications: LightPublication[];
coAuthors: Aggregation[];
wikis: Aggregation[];
reviews: Aggregation[];
byYear: Aggregation[];
}
publications: AuthorsPublications
}

export type AuthorsPublications = {
publicationsCount: number;
publications: LightPublication[];
coAuthors: Aggregation[];
wikis: Aggregation[];
reviews: Aggregation[];
byYear: Aggregation[];
}
Expand Down Expand Up @@ -105,4 +98,4 @@ export type RecentAffiliation = {
id: string;
year: string;
}[];
};
};

0 comments on commit bf4f71f

Please sign in to comment.