Skip to content

Commit

Permalink
js: added CustomAffiliationsSuggestion component
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 committed Nov 25, 2024
1 parent 6efd343 commit 159a20f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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(
<span key={value}>
Source: {scheme.toUpperCase()} <span>(Preferred)</span>
</span>
);
} else if (scheme === "edmo") {
sources.push(
<span key={value}>Source: {scheme.toUpperCase()}</span>
);
} else {
const idEntry = makeIdEntry(identifier);
if (idEntry) idStrings.push(idEntry);
}
});

return (
<Grid key={id}>
<Grid.Row columns={2} verticalAlign="middle">
<Grid.Column width={12}>
<Header>
{displayName} {idStrings.length > 0 && <>({idStrings})</>}
{subheader && <Header.Subheader>{subheader}</Header.Subheader>}
</Header>
</Grid.Column>
<Grid.Column width={4} textAlign="right">
{sources.length > 0 && (
<Header as="h6" color="grey" style={{ margin: 0 }}>
{sources}
</Header>
)}
</Grid.Column>
</Grid.Row>
</Grid>
);
});
};
2 changes: 2 additions & 0 deletions assets/js/invenio_app_rdm/overridableRegistry/mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

0 comments on commit 159a20f

Please sign in to comment.