Skip to content

Commit

Permalink
refactor(publications): rename softwares to software
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Nov 14, 2024
1 parent cf59614 commit 6713b9b
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 120 deletions.
4 changes: 2 additions & 2 deletions client/src/api/networks/network/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export const CONFIG = {
},
},
software: {
field: "softwares.id_name",
aggregation: "softwares.id_name.keyword",
field: "software.id_name",
aggregation: "software.id_name.keyword",
co_aggregation: "co_software.keyword",
url: (_: string, label: string) => `/search/publications?q="${label.replace(/ /g, "+")}"`,
terminology: {
Expand Down
2 changes: 1 addition & 1 deletion client/src/api/publications/[id]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function getPublicationById(id: string): Promise<Publication> {
_source: [
"title", "summary", "authors.fullName", "authors.person", "authors.role", "authors.affiliations",
"domains", "affiliations", "source", "isOa", 'type', 'id', "year", "oaEvidence", "projects", "externalIds",
"pdfUrl", "landingPage", "softwares",
"pdfUrl", "landingPage", "software",
],
query: {
bool: {
Expand Down
8 changes: 4 additions & 4 deletions client/src/api/publications/_utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export const FIELDS = [
"source.publisher",
"affiliations.id",
"affiliations.label.*",
"softwares.softwareName",
"softwares.contexts",
"softwares.wikidata",
"software.softwareName",
"software.contexts",
"software.wikidata",
"projects.id",
"projects.label.*",
"projects.acronym.*"
"projects.acronym.*",
]
export const LIGHT_SOURCE = ["title.*", "authors.fullName", "authors.person", "authors.role", "source.*", "isOa", 'type', 'id', "year", "landingPage", "externalIds"]
81 changes: 27 additions & 54 deletions client/src/pages/publications/[id]/components/publication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,46 @@ import Identifiers from "../../../../components/identifiers";
import MoreLikeThis from "../../../../components/more-like-this";
import { Publication } from "../../../../types/publication";
import { encode } from "../../../../utils/string";
import Softwares from "./softwares";
import Software from "./software"

export default function PublicationPage({ data }: { data: Publication }) {
const intl = useIntl();
const { screen } = useScreenSize();
const intl = useIntl()
const { screen } = useScreenSize()

const authors =
data.authors?.filter((author) => author.role === "author") || [];
const wikis = data?.domains?.filter((domain) => domain.type === "wikidata");
const authors = data.authors?.filter((author) => author.role === "author") || []
const wikis = data?.domains?.filter((domain) => domain.type === "wikidata")

const affiliations = data?.authors
?.flatMap(({ affiliations }) =>
affiliations?.filter((affiliation) => affiliation.name)
)
?.flatMap(({ affiliations }) => affiliations?.filter((affiliation) => affiliation.name))
.reduce((acc, cur) => {
if (!cur) return acc;
if (!cur) return acc
if (cur.rnsr) {
return [...acc.filter((a) => a.rnsr), cur];
return [...acc.filter((a) => a.rnsr), cur]
}
if (acc.filter((a) => a.rnsr).length > 0) {
return acc;
return acc
}
return [...acc, cur];
return [...acc, cur]
}, [])
.reduce((acc, cur) => {
if (acc.find((a) => a.name === cur.name)) {
return acc;
return acc
}
return [...acc, cur];
return [...acc, cur]
}, [])
.map((affiliation, index) => {
const authors = data.authors
?.filter((author) =>
author.affiliations?.find((a) => a.name === affiliation.name)
)
.map((author) => author.fullName);
return { ...affiliation, index, authors };
});
?.filter((author) => author.affiliations?.find((a) => a.name === affiliation.name))
.map((author) => author.fullName)
return { ...affiliation, index, authors }
})

return (
<Container fluid>
<Row gutters={!["sm", "xs"].includes(screen)}>
<Col xs="12" md="8">
<Container fluid className="fr-mb-6w">
<PublicationsHeader
data={data}
authors={authors}
affiliations={affiliations}
/>
<PublicationsHeader data={data} authors={authors} affiliations={affiliations} />
</Container>
<Container fluid>
<PageContent>
Expand All @@ -83,9 +74,7 @@ export default function PublicationPage({ data }: { data: Publication }) {
<sup>{affiliation.index + 1}</sup>{" "}
<div>
{affiliation?.rnsr ? (
<Link href={`/organizations/${affiliation.rnsr}`}>
{affiliation.name}
</Link>
<Link href={`/organizations/${affiliation.rnsr}`}>{affiliation.name}</Link>
) : (
affiliation.name
)}
Expand Down Expand Up @@ -114,14 +103,14 @@ export default function PublicationPage({ data }: { data: Publication }) {
size="lead"
icon="code-s-slash-line"
title={intl.formatMessage({
id: "publications.section.softwares.title",
id: "publications.section.software.title",
})}
description={intl.formatMessage({
id: "publications.section.softwares.legend",
id: "publications.section.software.legend",
})}
show={!!data?.softwares?.length}
show={!!data?.software?.length}
>
<Softwares softwares={data?.softwares} />
<Software software={data?.software} />
</PageSection>
<PageSection
size="lead"
Expand All @@ -133,11 +122,7 @@ export default function PublicationPage({ data }: { data: Publication }) {
>
<MoreLikeThis id={data._id} api="publications" />
</PageSection>
<PageSection
title="Data JSON"
description=""
show={import.meta.env.DEV}
>
<PageSection title="Data JSON" description="" show={import.meta.env.DEV}>
<div>
<pre>{JSON.stringify(data || "", null, 2)}</pre>
</div>
Expand All @@ -153,13 +138,7 @@ export default function PublicationPage({ data }: { data: Publication }) {
>
<ButtonGroup size="sm">
{data.pdfUrl && (
<Button
as="a"
href={data.pdfUrl}
target="_blank"
icon="file-download-line"
iconPosition="right"
>
<Button as="a" href={data.pdfUrl} target="_blank" icon="file-download-line" iconPosition="right">
{intl.formatMessage({
id: "publications.section.access.download",
})}
Expand Down Expand Up @@ -192,16 +171,10 @@ export default function PublicationPage({ data }: { data: Publication }) {
>
<Identifiers data={data?.externalIds} />
</PageSection>
<PageSection
title={intl.formatMessage({ id: "publications.section.wikis" })}
show={!!wikis?.length}
>
<PageSection title={intl.formatMessage({ id: "publications.section.wikis" })} show={!!wikis?.length}>
<Wiki wikis={wikis} />
</PageSection>
<PageSection
title={intl.formatMessage({ id: "publications.section.share" })}
show
>
<PageSection title={intl.formatMessage({ id: "publications.section.share" })} show>
<Share />
</PageSection>
<PageSection
Expand All @@ -227,5 +200,5 @@ export default function PublicationPage({ data }: { data: Publication }) {
</Col>
</Row>
</Container>
);
)
}
Original file line number Diff line number Diff line change
@@ -1,75 +1,88 @@
import { Row, Col, Text, useDSFRConfig, Link } from "@dataesr/dsfr-plus";
import { SoftwareMention } from "../../../../../types/publication";
import { getWikidataPreviews } from "../../../../../components/wiki/api";
import { useQuery } from "@tanstack/react-query";
import { WikipediaResult } from "../../../../../components/wiki/types";
import { Fragment } from "react/jsx-runtime";
import { Row, Col, Text, useDSFRConfig, Link } from "@dataesr/dsfr-plus"
import { SoftwareMention } from "../../../../../types/publication"
import { getWikidataPreviews } from "../../../../../components/wiki/api"
import { useQuery } from "@tanstack/react-query"
import { WikipediaResult } from "../../../../../components/wiki/types"
import { Fragment } from "react/jsx-runtime"

export default function Softwares({ softwares }: { softwares: SoftwareMention[] }) {
const { locale } = useDSFRConfig();
export default function Software({ software }: { software: SoftwareMention[] }) {
const { locale } = useDSFRConfig()

const codes = softwares
const codes = software
.map((software) => software.wikidata)
.filter((wikidata) => !!wikidata)
.map((wikidata) => ({ code: wikidata }));
.map((wikidata) => ({ code: wikidata }))

const { data: wikis } = useQuery<WikipediaResult[]>({
queryKey: ["wikidatas", codes.map(c => c.code), locale],
queryKey: ["wikidatas", codes.map((c) => c.code), locale],
queryFn: () => getWikidataPreviews(codes, locale),
enabled: !!codes?.length,
});
})

const getSoftwareContexts = (softwareName: string, contexts?: string[]) => {
if (!contexts.length) return null;
if (!contexts.length) return null
const newContexts = contexts.map((context) => {
const name = softwareName.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&')
const name = softwareName.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&")
try {
const regexp = new RegExp(name, "ig")
const newContext = context.replace(regexp, `<strong>${softwareName}</strong>`);
return newContext;
const newContext = context.replace(regexp, `<strong>${softwareName}</strong>`)
return newContext
} catch (e) {
return context;
return context
}
});
})
const stringContexts = newContexts.reduce((acc, cur) => {
if (acc.length === 0) return cur;
if (acc.length > 300) return acc;
return `${acc} ... ${cur}`;
}, "");
if (acc.length === 0) return cur
if (acc.length > 300) return acc
return `${acc} ... ${cur}`
}, "")

return <span dangerouslySetInnerHTML={{ __html: stringContexts }} />
}

const _softwares = softwares.map((software) => {
const wiki = wikis?.find((w) => w.code === software.wikidata);
return { ...software, wiki };
const _software = software.map((software) => {
const wiki = wikis?.find((w) => w.code === software.wikidata)
return { ...software, wiki }
})


if (!softwares.length) return null;
if (!software.length) return null
return (
<Row gutters>
<Col xs="12">
{_softwares.map((software) => (
{_software.map((software) => (
<div key={software.id_name}>
<Text size="lg" className="fr-mb-0" bold>
{software.softwareName}
{software?.wiki?.code && <span className="pointer fr-icon-information-line fr-text-default--info fr-icon--sm fr-ml-1v fr-text-mention--grey" aria-describedby={`software-${software.wiki.code}`} />}
{software?.wiki?.code && (
<span
className="pointer fr-icon-information-line fr-text-default--info fr-icon--sm fr-ml-1v fr-text-mention--grey"
aria-describedby={`software-${software.wiki.code}`}
/>
)}
</Text>
{software?.wiki?.code && (
<Fragment key={software.wiki.code}>
<span className="fr-tooltip fr-placement" id={`software-${software.wiki.code}`} role="tooltip" aria-hidden="true">
<span
className="fr-tooltip fr-placement"
id={`software-${software.wiki.code}`}
role="tooltip"
aria-hidden="true"
>
<div className="fr-p-2w">
<div className="wiki-text">
<Text bold size="lg">
{software.wiki?.title}
</Text>
<Text size="sm">
{software.wiki?.extract}
</Text>
<Text size="sm">{software.wiki?.extract}</Text>
</div>
{software.wiki?.image && (
<img style={{ objectFit: "cover" }} width="100%" height="100px" src={software.wiki.image} aria-hidden />
<img
style={{ objectFit: "cover" }}
width="100%"
height="100px"
src={software.wiki.image}
aria-hidden
/>
)}
<hr className="fr-my-1w" />
<Link href={software.wiki.url} target="_blank">
Expand All @@ -88,5 +101,5 @@ export default function Softwares({ softwares }: { softwares: SoftwareMention[]
))}
</Col>
</Row>
);
)
}
4 changes: 2 additions & 2 deletions client/src/pages/publications/[id]/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"publications.signals.author": "Einen Autor identifizieren",
"publications.signals.fundings": "Finanzierung hinzufügen",
"publications.signals.bug": "Einen Fehler melden",
"publications.section.softwares.title": "Softwareerwähnungen",
"publications.section.softwares.legend": "Softwareerwähnungen, die von scanR in der Veröffentlichung gefunden wurden."
"publications.section.software.title": "Softwareerwähnungen",
"publications.section.software.legend": "Softwareerwähnungen, die von scanR in der Veröffentlichung gefunden wurden."
}
4 changes: 2 additions & 2 deletions client/src/pages/publications/[id]/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"publications.signals.author": "Identify an author",
"publications.signals.fundings": "Add funding",
"publications.signals.bug": "Report an error",
"publications.section.softwares.title": "Software mentions",
"publications.section.softwares.legend": "Software mentions found by scanR in the publication.",
"publications.section.software.title": "Software mentions",
"publications.section.software.legend": "Software mentions found by scanR in the publication.",
"search.publications.thesis.by": " by "
}
4 changes: 2 additions & 2 deletions client/src/pages/publications/[id]/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"publications.signals.author": "Identificar un autor",
"publications.signals.fundings": "Agregar financiamiento",
"publications.signals.bug": "Reportar un error",
"publications.section.softwares.title": "Menciones de Software",
"publications.section.softwares.legend": "Menciones de software encontradas por scanR en la publicación."
"publications.section.software.title": "Menciones de Software",
"publications.section.software.legend": "Menciones de software encontradas por scanR en la publicación."
}
4 changes: 2 additions & 2 deletions client/src/pages/publications/[id]/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"publications.signals.author": "Identifier un auteur",
"publications.signals.fundings": "Ajouter un financement",
"publications.signals.bug": "Signaler une erreur",
"publications.section.softwares.title": "Mentions de logiciels",
"publications.section.softwares.legend": "Les mentions de logiciels retrouvées par scanR dans la publication.",
"publications.section.software.title": "Mentions de logiciels",
"publications.section.software.legend": "Les mentions de logiciels retrouvées par scanR dans la publication.",
"search.publications.thesis.by": " par ",
"search.publications.openAccess": "Accès ouvert",
"search.publications.closedAccess": "Accès fermé",
Expand Down
Loading

0 comments on commit 6713b9b

Please sign in to comment.