From 258c096e3c23a7615f281525e0d910c9fd4f5508 Mon Sep 17 00:00:00 2001
From: Tania Fecheta <tania.fecheta@thinslices.com>
Date: Thu, 11 Oct 2018 14:21:48 +0300
Subject: [PATCH] feat((eicMakeDecisionFlow)): extend make decision contextual
 box and highlight editorial decision co

---
 .../ManuscriptEicDecision.js                  | 30 +++++++++----------
 .../src/components/EditorialCommentCard.js    | 10 +++++--
 .../src/components/ManuscriptLayout.js        |  6 +++-
 .../src/components/ManuscriptPage.js          | 16 +++++++++-
 .../components/MakeDecision/DecisionForm.js   |  2 +-
 5 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptEicDecision.js b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptEicDecision.js
index a6f66d373..fa3b5313c 100644
--- a/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptEicDecision.js
+++ b/packages/component-faraday-ui/src/manuscriptDetails/ManuscriptEicDecision.js
@@ -40,22 +40,20 @@ const ManuscriptEicDecision = ({
         </ItemOverrideAlert>
       </Row>
 
-      <Row mt={2}>
-        <Item vertical>
-          <Label required>
-            {
-              messagesLabel[
-                get(formValues, 'decision', 'return-to-handling-editor')
-              ]
-            }
-          </Label>
-          <ValidatedField
-            component={ValidatedTextArea}
-            name="message"
-            validate={[required]}
-          />
-        </Item>
-      </Row>
+      {get(formValues, 'decision') !== 'publish' && (
+        <Row mt={2}>
+          <Item vertical>
+            <Label required>
+              {messagesLabel[get(formValues, 'decision', 'reject')]}
+            </Label>
+            <ValidatedField
+              component={ValidatedTextArea}
+              name="message"
+              validate={[required]}
+            />
+          </Item>
+        </Row>
+      )}
 
       <Row justify="flex-end" mt={4}>
         <Button onClick={handleSubmit} primary size="medium">
diff --git a/packages/component-manuscript/src/components/EditorialCommentCard.js b/packages/component-manuscript/src/components/EditorialCommentCard.js
index aa9187971..67c882a3b 100644
--- a/packages/component-manuscript/src/components/EditorialCommentCard.js
+++ b/packages/component-manuscript/src/components/EditorialCommentCard.js
@@ -6,8 +6,14 @@ import {
   withFileDownload,
 } from 'pubsweet-component-faraday-ui'
 
-const EditorialCommentCard = ({ journal, reports = [] }) => (
-  <ContextualBox label="Editorial Comments" mb={2}>
+const EditorialCommentCard = ({ journal, reports = [], toggle, expanded }) => (
+  <ContextualBox
+    expanded={expanded}
+    label="Editorial Comments"
+    mb={2}
+    scrollIntoView
+    toggle={toggle}
+  >
     {reports.map(report => (
       <EditorialReportCard journal={journal} key={report.id} report={report} />
     ))}
diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js
index 2450088df..ae00e1870 100644
--- a/packages/component-manuscript/src/components/ManuscriptLayout.js
+++ b/packages/component-manuscript/src/components/ManuscriptLayout.js
@@ -26,7 +26,6 @@ const eicDecisions = [
 
 const messagesLabel = {
   'return-to-handling-editor': 'Comments for Handling Editor',
-  publish: 'Comments for Author',
   reject: 'Comments for Author',
 }
 
@@ -69,6 +68,8 @@ const ManuscriptLayout = ({
   reviewerRecommendations,
   toggleReviewerDetails,
   reviewerDetailsExpanded,
+  toggleHeRecommendation,
+  heRecommendationExpanded,
 }) => (
   <Root pb={30}>
     {!isEmpty(collection) && !isEmpty(fragment) ? (
@@ -103,8 +104,10 @@ const ManuscriptLayout = ({
         {get(currentUser, 'permissions.canViewReports', true) &&
           !!editorialRecommendations.length && (
             <EditorialCommentCard
+              expanded={heRecommendationExpanded}
               journal={journal}
               reports={editorialRecommendations}
+              toggle={toggleHeRecommendation}
             />
           )}
 
@@ -194,6 +197,7 @@ const ManuscriptLayout = ({
         {get(currentUser, 'permissions.canMakeDecision', false) && (
           <ManuscriptEicDecision
             formValues={get(formValues, 'eicDecision')}
+            highlight={editorialRecommendations.length > 0}
             messagesLabel={messagesLabel}
             mt={2}
             options={
diff --git a/packages/component-manuscript/src/components/ManuscriptPage.js b/packages/component-manuscript/src/components/ManuscriptPage.js
index aa69fb6d1..aaac6b3b8 100644
--- a/packages/component-manuscript/src/components/ManuscriptPage.js
+++ b/packages/component-manuscript/src/components/ManuscriptPage.js
@@ -425,6 +425,10 @@ export default compose(
     toggleReviewerDetails: toggle,
     reviewerDetailsExpanded: expanded,
   })),
+  fromRenderProps(RemoteOpener, ({ toggle, expanded }) => ({
+    toggleHeRecommendation: toggle,
+    heRecommendationExpanded: expanded,
+  })),
   withProps(({ currentUser, collection, submittedOwnRecommendation }) => ({
     getSignedUrl,
     shouldReview:
@@ -443,7 +447,13 @@ export default compose(
         clearCustomError,
         hasManuscriptFailure,
         fetchUpdatedCollection,
-        currentUser: { isInvitedHE, isInvitedToReview, isHEToManuscript },
+        editorialRecommendations,
+        currentUser: {
+          isInvitedHE,
+          isInvitedToReview,
+          isHEToManuscript,
+          isEIC,
+        },
       } = this.props
       if (hasManuscriptFailure) {
         history.push('/not-found')
@@ -479,6 +489,10 @@ export default compose(
       if (isHEToManuscript && !!reviewerReports.length) {
         this.props.toggleReviewerDetails()
       }
+
+      if (isEIC && !!editorialRecommendations.length) {
+        this.props.toggleHeRecommendation()
+      }
     },
   }),
 )(ManuscriptLayout)
diff --git a/packages/components-faraday/src/components/MakeDecision/DecisionForm.js b/packages/components-faraday/src/components/MakeDecision/DecisionForm.js
index 3fab58f21..b698cf1f4 100644
--- a/packages/components-faraday/src/components/MakeDecision/DecisionForm.js
+++ b/packages/components-faraday/src/components/MakeDecision/DecisionForm.js
@@ -73,7 +73,7 @@ const DecisionForm = ({
     {decision === 'return-to-handling-editor' && (
       <Row>
         <RowItem vertical>
-          <Label>Comments for Handling Editor</Label>
+          <Label>Comments for Author</Label>
           <ValidatedField
             component={TextAreaField}
             name="messageToHE"
-- 
GitLab