-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js: added CustomAffiliationsSuggestion component
- Loading branch information
1 parent
6efd343
commit 159a20f
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
assets/js/components/react_invenio_forms/CustomAffiliationsSuggestions.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,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> | ||
); | ||
}); | ||
}; |
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