-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
components: add affiliations suggestions display component
- Loading branch information
1 parent
735495a
commit c893900
Showing
3 changed files
with
134 additions
and
1 deletion.
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
123 changes: 123 additions & 0 deletions
123
src/lib/elements/contrib/invenioRDM/records/AffiliationsSuggestions.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 |
---|---|---|
@@ -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 ( | ||
<span key={identifier.identifier}> | ||
<a href={link} target="_blank" rel="noopener noreferrer"> | ||
<Image src={icon} className="inline-id-icon mr-5" verticalAlign="middle" /> | ||
{identifier.scheme === "orcid" ? identifier.identifier : null} | ||
</a> | ||
</span> | ||
); | ||
}; | ||
|
||
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, | ||
Check failure on line 70 in src/lib/elements/contrib/invenioRDM/records/AffiliationsSuggestions.js GitHub Actions / Tests (18.x)
|
||
) => { | ||
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: ( | ||
<Header> | ||
{name} {idString.length ? <>({idString})</> : null} | ||
<Header.Subheader>{subheader}</Header.Subheader> | ||
</Header> | ||
), | ||
}; | ||
}); | ||
|
||
if (showManualEntry) { | ||
results.push({ | ||
text: "Manual entry", | ||
value: "Manual entry", | ||
extra: "Manual entry", | ||
key: "manual-entry", | ||
content: ( | ||
<Header textAlign="center"> | ||
<Header.Content> | ||
<p> | ||
<Trans> | ||
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid*/} | ||
Couldn't find your person? You can <a>create a new entry</a>. | ||
</Trans> | ||
</p> | ||
</Header.Content> | ||
</Header> | ||
), | ||
}); | ||
} | ||
return results; | ||
}; |
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,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"; |