diff --git a/assets/js/components/react_invenio_forms/CustomAffiliationsSuggestions.js b/assets/js/components/react_invenio_forms/CustomAffiliationsSuggestions.js new file mode 100644 index 00000000..eb92cfe9 --- /dev/null +++ b/assets/js/components/react_invenio_forms/CustomAffiliationsSuggestions.js @@ -0,0 +1,59 @@ +import React from "react"; +import { Header, Grid } from "semantic-ui-react"; +import { makeIdEntry, makeSubheader } from "react-invenio-forms"; + + +export const CustomAffiliationsSuggestions = (creatibutors) => { + // Ensure creatibutors is always an array + const creatibutorsArray = Array.isArray(creatibutors) ? creatibutors : [creatibutors]; + + return creatibutorsArray.map((creatibutor) => { + const { creatibutor: creatibutorData } = creatibutor; + const { name, acronym, identifiers = [], id } = creatibutorData; + + const subheader = makeSubheader(creatibutorData, creatibutor.isOrganization); + const displayName = acronym ? `${name} (${acronym})` : name; + + const sources = []; + const idStrings = []; + + identifiers.forEach((identifier) => { + const { scheme, identifier: value } = identifier; + + if (scheme === "ror") { + sources.push( + + Source: {scheme.toUpperCase()} (Preferred) + + ); + } else if (scheme === "edmo") { + sources.push( + Source: {scheme.toUpperCase()} + ); + } else { + const idEntry = makeIdEntry(identifier); + if (idEntry) idStrings.push(idEntry); + } + }); + + return ( + + + +
+ {displayName} {idStrings.length > 0 && <>({idStrings})} + {subheader && {subheader}} +
+
+ + {sources.length > 0 && ( +
+ {sources} +
+ )} +
+
+
+ ); + }); +}; diff --git a/assets/js/invenio_app_rdm/overridableRegistry/mapping.js b/assets/js/invenio_app_rdm/overridableRegistry/mapping.js index 594c4f22..dc541dda 100644 --- a/assets/js/invenio_app_rdm/overridableRegistry/mapping.js +++ b/assets/js/invenio_app_rdm/overridableRegistry/mapping.js @@ -7,10 +7,12 @@ import { UpgradeLegacyRecordButton } from "../../components/landing_page/overrides/UpgradeLegacyRecordButton"; import { FileUploaderNewVersion } from "../../components/landing_page/overrides/FileUploaderNewVersion"; import SubcommunityCreateForm from "../../components/community/overrides/SubcommunityCreateForm"; +import { CustomAffiliationsSuggestions } from "../../components/react_invenio_forms/CustomAffiliationsSuggestions"; export const overriddenComponents = { "InvenioAppRdm.RecordLandingPage.RecordManagement.container": UpgradeLegacyRecordButton, "ReactInvenioDeposit.FileUploader.NewVersionButton.container": FileUploaderNewVersion, + "ReactInvenioForms.AffiliationsSuggestions.content": CustomAffiliationsSuggestions, "InvenioCommunities.CommunityCreateForm.layout": SubcommunityCreateForm };