Skip to content
Snippets Groups Projects
Commit c41d79d8 authored by Giannis Kopanas's avatar Giannis Kopanas
Browse files

fix(components): rewrite conditional checks to more clean

parent 0a6bd458
No related branches found
No related tags found
No related merge requests found
...@@ -93,8 +93,6 @@ const SuggestionsEditable = ({ readonly }) => ( ...@@ -93,8 +93,6 @@ const SuggestionsEditable = ({ readonly }) => (
</FormSection> </FormSection>
) )
const arrayToText = text => (text.length === 0 ? ['none'] : text).join(', ')
const SuggestionsNonEditable = ({ readonly, version }) => { const SuggestionsNonEditable = ({ readonly, version }) => {
const suggestions = version.suggestions || {} const suggestions = version.suggestions || {}
...@@ -102,20 +100,27 @@ const SuggestionsNonEditable = ({ readonly, version }) => { ...@@ -102,20 +100,27 @@ const SuggestionsNonEditable = ({ readonly, version }) => {
<Section id="suggestions.reviewers"> <Section id="suggestions.reviewers">
<Legend>Suggested or opposed reviewers</Legend> <Legend>Suggested or opposed reviewers</Legend>
<SubLegend>Suggested reviewers</SubLegend> <SubLegend>Suggested reviewers</SubLegend>
<div>{arrayToText((suggestions.reviewers || {}).suggested || [])}</div> <div>{suggestionsText(suggestions.reviewers, 'suggested')}</div>
<SubLegend>Opposed reviewers</SubLegend> <SubLegend>Opposed reviewers</SubLegend>
<div>{arrayToText((suggestions.reviewers || {}).opposed || [])}</div> <div>{suggestionsText(suggestions.reviewers, 'opposed')}</div>
</Section>, </Section>,
<Section id="suggestions.editors"> <Section id="suggestions.editors">
<Legend>Suggested or opposed editors</Legend> <Legend>Suggested or opposed editors</Legend>
<SubLegend>Suggested editors</SubLegend> <SubLegend>Suggested editors</SubLegend>
<div>{arrayToText((suggestions.editors || {}).suggested || [])}</div> <div>{suggestionsText(suggestions.editors, 'suggested')}</div>
<SubLegend>Opposed editors</SubLegend> <SubLegend>Opposed editors</SubLegend>
<div>{arrayToText((suggestions.editors || {}).opposed || [])}</div> <div>{suggestionsText(suggestions.editors, 'opposed')}</div>
</Section>, </Section>,
] ]
} }
const suggestionsText = (source, property) => {
if (source && Array.isArray(source[property]) && !!source[property].length) {
return source[property].join(', ')
}
return 'none'
}
export default branch( export default branch(
({ readonly }) => readonly === true, ({ readonly }) => readonly === true,
renderComponent(SuggestionsNonEditable), renderComponent(SuggestionsNonEditable),
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment