diff --git a/src/lib/elements/contrib/invenioRDM/index.js b/src/lib/elements/contrib/invenioRDM/index.js index 2c6d0111..6a47b712 100644 --- a/src/lib/elements/contrib/invenioRDM/index.js +++ b/src/lib/elements/contrib/invenioRDM/index.js @@ -6,5 +6,6 @@ * // under the terms of the MIT License; see LICENSE file for more details. */ -export * from "./users"; export * from "./groups"; +export * from "./records"; +export * from "./users"; diff --git a/src/lib/elements/contrib/invenioRDM/records/AffiliationsSuggestions.js b/src/lib/elements/contrib/invenioRDM/records/AffiliationsSuggestions.js new file mode 100644 index 00000000..0eed32ef --- /dev/null +++ b/src/lib/elements/contrib/invenioRDM/records/AffiliationsSuggestions.js @@ -0,0 +1,123 @@ +/* + * // This file is part of React-Invenio-Forms + * // Copyright (C) 2024 CERN. + * // + * // React-Invenio-Forms is free software; you can redistribute it and/or modify it + * // under the terms of the MIT License; see LICENSE file for more details. + */ + +import React from "react"; +import { Image } from "../../../Image"; +import { Header } from "semantic-ui-react"; +import { Trans } from "react-i18next"; + +const makeIdEntry = (identifier) => { + let icon = null; + let link = null; + + if (identifier.scheme === "orcid") { + icon = "/static/images/orcid.svg"; + link = "https://orcid.org/" + identifier.identifier; + } else if (identifier.scheme === "gnd") { + icon = "/static/images/gnd-icon.svg"; + link = "https://d-nb.info/gnd/" + identifier.identifier; + } else if (identifier.scheme === "ror") { + return; // ROR doesn't recommend displaying ROR IDs + } else if (identifier.scheme === "isni" || identifier.scheme === "grid") { + return; + } else { + return ( + <> + {identifier.scheme}: {identifier.identifier} + + ); + } + + return ( + + + + {identifier.scheme === "orcid" ? identifier.identifier : null} + + + ); +}; + +const makeSubheader = (creatibutor, isOrganization) => { + if (isOrganization) { + const locationPart = [creatibutor?.location_name, creatibutor?.country_name] + .filter(Boolean) + .join(", "); + + const typesPart = creatibutor?.types + .map((type) => type.charAt(0).toUpperCase() + type.slice(1)) + .join(", "); + + return `${locationPart}${ + locationPart && typesPart ? " — " : "" + }${typesPart}`.trim(); + } else { + return ( + creatibutor?.affiliations?.map((affiliation) => affiliation.name)?.join(", ") || + "" + ); + } +}; + +export const AffiliationsSuggestions = ( + creatibutors, + isOrganization, + showManualEntry, +) => { + const results = creatibutors.map((creatibutor) => { + // ensure `affiliations` and `identifiers` are present + creatibutor.affiliations = creatibutor.affiliations || []; + creatibutor.identifiers = creatibutor.identifiers || []; + + const subheader = makeSubheader(creatibutor, isOrganization); + let name = creatibutor.name; + if (creatibutor.acronym) name += " (" + creatibutor.acronym + ")"; + + const idString = []; + creatibutor.identifiers?.forEach((i) => { + const idEntry = makeIdEntry(i); + if (idEntry) idString.push(idEntry); + }); + + return { + text: creatibutor.name, + value: creatibutor.id, + extra: creatibutor, + key: creatibutor.id, + id: creatibutor.id, + content: ( +
+ {name} {idString.length ? <>({idString}) : null} + {subheader} +
+ ), + }; + }); + + if (showManualEntry) { + results.push({ + text: "Manual entry", + value: "Manual entry", + extra: "Manual entry", + key: "manual-entry", + content: ( +
+ +

+ + {/* eslint-disable-next-line jsx-a11y/anchor-is-valid*/} + Couldn't find your person? You can create a new entry. + +

+
+
+ ), + }); + } + return results; +}; diff --git a/src/lib/elements/contrib/invenioRDM/records/index.js b/src/lib/elements/contrib/invenioRDM/records/index.js new file mode 100644 index 00000000..01814031 --- /dev/null +++ b/src/lib/elements/contrib/invenioRDM/records/index.js @@ -0,0 +1,9 @@ +/* + * // This file is part of React-Invenio-Forms + * // Copyright (C) 2024 CERN. + * // + * // React-Invenio-Forms is free software; you can redistribute it and/or modify it + * // under the terms of the MIT License; see LICENSE file for more details. + */ + +export { AffiliationsSuggestions } from "./AffiliationsSuggestions";