-
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 3c8da2d
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, 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> | ||
); | ||
}); | ||
}; |
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