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 3c8da2d
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, 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(
<span key={identifier.identifier}>
Source: {identifier.scheme.toUpperCase()} <span>(Preferred)</span>
</span>
);
} else if (identifier.scheme === "edmo") {
source.push(
<span key={identifier.identifier}>
Source: {identifier.scheme.toUpperCase()}
</span>
);
} else {
const idEntry = makeIdEntry(identifier);
if (idEntry) source.push(idEntry);
}
});

return (
<Grid key={creatibutor.id}>
<Grid.Row columns={2} verticalAlign="middle">
<Grid.Column width={12}>
<Header>
{name}
{subheader.length > 0 && <Header.Subheader>{subheader}</Header.Subheader>}
</Header>
</Grid.Column>
<Grid.Column width={4} textAlign="right">
{source.length > 0 && (
<Header as="h6" color="grey" style={{ margin: 0 }}>
{source}
</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 3c8da2d

Please sign in to comment.