From 3c8da2dbaf4886fcbe8956fa2d8c56aef663677f Mon Sep 17 00:00:00 2001 From: Fatimah Zulfiqar Date: Mon, 25 Nov 2024 15:00:40 +0100 Subject: [PATCH] js: added CustomAffiliationsSuggestion component --- .../CustomAffiliationsSuggestions.js | 59 +++++++++++++++++++ .../overridableRegistry/mapping.js | 2 + 2 files changed, 61 insertions(+) create mode 100644 assets/js/components/react_invenio_forms/CustomAffiliationsSuggestions.js 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..936c0c54 --- /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, isOrganization) => { + const creatibutorsArray = Array.isArray(creatibutors) ? creatibutors : [creatibutors]; + + return creatibutorsArray.map((creatibutor) => { + const creatibutorCopy = { ...creatibutor.creatibutor }; + + creatibutorCopy.affiliations = creatibutorCopy.affiliations || []; + creatibutorCopy.identifiers = creatibutorCopy.identifiers || []; + + const subheader = makeSubheader(creatibutorCopy, isOrganization); + let name = creatibutorCopy.name; + if (creatibutorCopy.acronym) name += ` (${creatibutorCopy.acronym})`; + + const source = []; + + creatibutorCopy.identifiers?.forEach((identifier) => { + if (identifier.scheme === "ror") { + source.push( + + Source: {identifier.scheme.toUpperCase()} (Preferred) + + ); + } else if (identifier.scheme === "edmo") { + source.push( + + Source: {identifier.scheme.toUpperCase()} + + ); + } else { + const idEntry = makeIdEntry(identifier); + if (idEntry) source.push(idEntry); + } + }); + + return ( + + + +
+ {name} + {subheader.length > 0 && {subheader}} +
+
+ + {source.length > 0 && ( +
+ {source} +
+ )} +
+
+
+ ); + }); +}; 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 };