diff --git a/packages/component-faraday-ui/src/AuthorTagList.js b/packages/component-faraday-ui/src/AuthorTagList.js index f1d7ceb2fe0be30e0e28e78d70042fe09aeaedd7..0592061f2a9532edf837d160a61664d1c1b55084 100644 --- a/packages/component-faraday-ui/src/AuthorTagList.js +++ b/packages/component-faraday-ui/src/AuthorTagList.js @@ -1,6 +1,6 @@ import React from 'react' import styled from 'styled-components' -import { groupBy } from 'lodash' +import { groupBy, get } from 'lodash' import { th } from '@pubsweet/ui-toolkit' import { compose, withState, withHandlers, withProps } from 'recompose' @@ -13,7 +13,7 @@ import { AuthorWithTooltip, } from 'pubsweet-component-faraday-ui' -const parseAffiliationGroup = authors => { +const parseAffiliationGroup = (authors = []) => { const affiliationGroup = groupBy(authors, 'affiliation') const affiliationList = Object.keys(affiliationGroup) const list = affiliationList.reduce((acc, el, index) => { @@ -31,19 +31,20 @@ const parseAffiliationGroup = authors => { } const AuthorTagList = ({ - authorsAffiliations: { list = [], affiliationList = [] }, + authors = [], + affiliationList, separator = ',', authorKey = 'email', - tooltip = false, - affiliations = false, + withTooltip = false, + withAffiliations = false, showAffiliation = false, toggleAffiliation, }) => ( <Root> - {list + {authors .map( a => - tooltip ? ( + withTooltip ? ( <AuthorWithTooltip author={a} key={a[authorKey]} /> ) : ( <AuthorTag author={a} key={a[authorKey]} /> @@ -56,7 +57,7 @@ const AuthorTagList = ({ : [prev, separator, <span key={curr}> </span>, curr], [], )} - {affiliations && ( + {withAffiliations && ( <Item ml={1}> {showAffiliation ? ( <ActionLink icon="minus" onClick={toggleAffiliation(false)}> @@ -70,7 +71,7 @@ const AuthorTagList = ({ </Item> )} - {affiliations && + {withAffiliations && showAffiliation && ( <AffiliationRow> {affiliationList.map((a, i) => ( @@ -85,8 +86,13 @@ const AuthorTagList = ({ ) export default compose( withState('showAffiliation', 'setAffiliation', false), - withProps(({ authors = [] }) => ({ - authorsAffiliations: parseAffiliationGroup(authors), + withProps(({ authors = [], withAffiliations }) => ({ + authors: withAffiliations + ? get(parseAffiliationGroup(authors), 'list', []) + : authors, + affiliationList: + withAffiliations && + get(parseAffiliationGroup(authors), 'affiliationList', []), })), withHandlers({ toggleAffiliation: ({ setAffiliation }) => value => () => diff --git a/packages/component-faraday-ui/src/AuthorTagList.md b/packages/component-faraday-ui/src/AuthorTagList.md index df88f967ac69a8bdb8b7a36f757d501f6b9685e7..62cc3421ddc446e5d091424391a17a152cd20673 100644 --- a/packages/component-faraday-ui/src/AuthorTagList.md +++ b/packages/component-faraday-ui/src/AuthorTagList.md @@ -61,8 +61,16 @@ const authors = [ affiliation: 'US Presidency', affiliationNumber: 2, }, + { + id: 4, + email: 'barrack.obama@gmail.com', + firstName: 'Sebi', + lastName: 'Mihalache', + affiliation: 'US Presidency', + affiliationNumber: 2, + }, ] -;<AuthorTagList authors={authors} tooltip affiliations /> +;<AuthorTagList authors={authors} withTooltip withAffiliations /> ``` A list of author tags with tooltip @@ -88,7 +96,7 @@ const authors = [ lastName: 'Obama', }, ] -;<AuthorTagList authors={authors} tooltip /> +;<AuthorTagList authors={authors} withTooltip /> ``` Use a different separator and key for mapping the authors. diff --git a/packages/component-faraday-ui/src/ManuscriptCard.js b/packages/component-faraday-ui/src/ManuscriptCard.js index 97688bbcbd4cec6dccb0717cc5614106f222a0dc..40ea896cc0721b41f93658ddde628fe75d908562 100644 --- a/packages/component-faraday-ui/src/ManuscriptCard.js +++ b/packages/component-faraday-ui/src/ManuscriptCard.js @@ -45,7 +45,7 @@ const ManuscriptCard = ({ </Row> {authors.length > 0 && ( <Row alignItems="center" justify="flex-start" mb={1}> - <AuthorTagList authors={authors} tooltip /> + <AuthorTagList authors={authors} withTooltip /> </Row> )} <Row alignItems="center" justify="flex-start" mb={1}> diff --git a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js index 63c356d95c093e71546df8e9a38772491be480eb..2c5fa6dfff0af31cb69d10ea0fd1a3ab3429167e 100644 --- a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js +++ b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptHeader.js @@ -23,7 +23,12 @@ const ManuscriptHeader = ({ </Row> {authors.length > 0 && ( <Row alignItems="center" justify="flex-start" mb={1}> - <AuthorTagList authors={authors} tooltip /> + <AuthorTagList + affiliations + authors={authors} + withAffiliations + withTooltip + /> </Row> )} <Row alignItems="center" justify="flex-start" mb={1}>