Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Journal Details section above Contacts section #519

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 80 additions & 56 deletions app/assets/scripts/components/documents/single-view/document-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const FragmentWithOptionalEditor = ({
atbd
}}
value={value}
whenEmpty={<EmptySection />}
whenEmpty={<EmptySection className={className} />}
/>
)}
{children}
Expand Down Expand Up @@ -299,7 +299,9 @@ const ContactItem = ({ id, label, contact, roles, affiliations }) => (
</AtbdSubSection>
);

const EmptySection = () => <p>No content available.</p>;
const EmptySection = ({ className }) => (
<p className={className}>No content available.</p>
);

/**
* Renders each element of the given array (by calling their `render` function)
Expand Down Expand Up @@ -905,63 +907,49 @@ const htmlAtbdContentSections = [
}
]
},
{
label: 'Contacts',
id: 'contacts',
render: ({ element, children, atbd, printMode }) => (
<AtbdSection
key={element.id}
id={element.id}
title={element.label}
atbd={atbd}
printMode={printMode}
>
{React.Children.count(children) ? (
children
) : (
<p>There are no contacts associated with this document</p>
)}
</AtbdSection>
),
children: ({ atbd }) => {
const contactsLink = atbd?.contacts_link || [];
return contactsLink.map(({ contact, roles, affiliations }, idx) => ({
label: getContactName(contact),
id: `contacts_${idx + 1}`,
render: ({ element }) => (
<ContactItem
key={element.id}
id={element.id}
label={element.label}
contact={contact}
roles={roles}
affiliations={affiliations}
/>
)
}));
}
},
{
label: 'Journal Details',
id: 'journal_details',
shouldRender: ({ atbd }) => isJournalPublicationIntended(atbd),
render: ({ element, children, atbd, printMode }) => (
<AtbdSection
key={element.id}
id={element.id}
title={printMode ? 'Significance Discussion' : element.label}
atbd={atbd}
printMode={printMode}
>
<p className='pdf-preview-hidden'>
<em>
If provided, the journal details are included only in the Journal
PDF.
</em>
</p>
{children}
</AtbdSection>
),
render: ({ element, children, atbd, printMode, document }) => {
function isJournalDiscussionEmpty() {
if (
!document.journal_discussion ||
!document.journal_discussion.children
) {
return true;
}

return document.journal_discussion.children.every((node) => {
if (node.type === 'p' && node.children?.every(({ text }) => !text)) {
return true;
}

return false;
});
}

return (
<AtbdSection
key={element.id}
id={element.id}
title={printMode ? 'Significance Discussion' : element.label}
atbd={atbd}
printMode={printMode}
className={
isJournalDiscussionEmpty() ? 'pdf-preview-hidden' : undefined
}
>
<p className='pdf-preview-hidden'>
<em>
If provided, the journal details are included only in the Journal
PDF.
</em>
</p>
{children}
</AtbdSection>
);
},
children: [
{
label: 'Key Points',
Expand All @@ -979,7 +967,7 @@ const htmlAtbdContentSections = [
<MultilineString
className='pdf-preview-hidden'
value={document.key_points}
whenEmpty={<EmptySection />}
whenEmpty={<EmptySection className='pdf-preview-hidden' />}
/>
</FragmentWithOptionalEditor>
)
Expand Down Expand Up @@ -1041,6 +1029,42 @@ const htmlAtbdContentSections = [
}
]
},
{
label: 'Contacts',
id: 'contacts',
render: ({ element, children, atbd, printMode }) => (
<AtbdSection
key={element.id}
id={element.id}
title={element.label}
atbd={atbd}
printMode={printMode}
>
{React.Children.count(children) ? (
children
) : (
<p>There are no contacts associated with this document</p>
)}
</AtbdSection>
),
children: ({ atbd }) => {
const contactsLink = atbd?.contacts_link || [];
return contactsLink.map(({ contact, roles, affiliations }, idx) => ({
label: getContactName(contact),
id: `contacts_${idx + 1}`,
render: ({ element }) => (
<ContactItem
key={element.id}
id={element.id}
label={element.label}
contact={contact}
roles={roles}
affiliations={affiliations}
/>
)
}));
}
},
{
label: 'References',
id: 'references',
Expand Down
Loading