From c673ec8f770c26eade66eb4e60794d3b029cd6bb Mon Sep 17 00:00:00 2001
From: Audrey Hamelers <hamelers@ebi.ac.uk>
Date: Wed, 6 Feb 2019 16:22:26 +0000
Subject: [PATCH] move admin highlight terms to separate file

---
 .../submission-wizard/SubmitHighlights.jsx    | 99 +++++++++++++++++++
 .../submission-wizard/SubmitPage.jsx          | 99 ++-----------------
 2 files changed, 106 insertions(+), 92 deletions(-)
 create mode 100644 app/components/submission-wizard/SubmitHighlights.jsx

diff --git a/app/components/submission-wizard/SubmitHighlights.jsx b/app/components/submission-wizard/SubmitHighlights.jsx
new file mode 100644
index 000000000..e9d288ec4
--- /dev/null
+++ b/app/components/submission-wizard/SubmitHighlights.jsx
@@ -0,0 +1,99 @@
+import React from 'react'
+import { Button } from '@pubsweet/ui'
+import { Loading, LoadingIcon } from '../ui'
+
+const makeList = matchString => {
+  const sups = matchString.match(
+    /(supp(?!lemented|lementing|ort[\W]|ort(?!ing)|orting [^i]|ress|ly|li|ler)[\w.]*\s*[\w.]*|extended data)\s*(?!and)\w*(,?\s*(\d+|\w\d+))*((?!(\s*and\s*|-|\u2013|\u2014|&)supp|extended|fig|table)(\s*and\s*|-|\u2013|\u2014|&)\w*)?/gi,
+  )
+  const figs = matchString.match(
+    /(\W(supp[\w.]*|extended data)\s*|\W?)fig[\w.]*\s*(\d+|\w\d+)\w*(,?\s*(\d+|\w\d+))*((\s*and\s*|-|\u2013|\u2014|&)(?!supp|extended|fig|table)(\d+|\w\d+|\w+)\w*)*/gi,
+  )
+  const tables = matchString.match(
+    /\W((supp[\w.]*|extended data)\s*)?table[\w]*\s*(\d+|\w\d+)\w*(,?\s*(\d+|\w\d+))*((\s*and\s*|-|\u2013|\u2014|&)(?!supp|extended|fig|table)(\d+|\w\d+|\w+)\w*)*/gi,
+  )
+  const regexes = [
+    {
+      title: 'Supplements',
+      array: [
+        ...new Set(sups && sups.map(match => match.replace(/\s\s+/g, ' '))),
+      ],
+    },
+    {
+      title: 'Figures',
+      array: [
+        ...new Set(
+          figs &&
+            figs.map(match => match.replace(/^\W/, '').replace(/\s\s+/g, ' ')),
+        ),
+      ].filter(match => !/^(supp|extended data)/i.test(match)),
+    },
+    {
+      title: 'Tables',
+      array: [
+        ...new Set(
+          tables &&
+            tables.map(match =>
+              match.replace(/^\W/, '').replace(/\s\s+/g, ' '),
+            ),
+        ),
+      ].filter(match => !/^(supp|extended data)/i.test(match)),
+    },
+  ]
+  return regexes
+}
+
+class SubmitHighlights extends React.Component {
+  state = { references: 'Supplements' }
+  render() {
+    const { highlights } = this.props
+    const { references } = this.state
+    const regexes = makeList(highlights)
+    if (
+      !regexes ||
+      (regexes.length > 0 && !regexes.some(x => x.array.length > 0))
+    ) {
+      return <div>No results</div>
+    }
+    return (
+      <div style={{ padding: 0 }}>
+        <div style={{ display: 'flex', justifyContent: 'stretch' }}>
+          {regexes.map(regex => {
+            if (regex.array.length > 0) {
+              return (
+                <Button
+                  key={regex.title}
+                  onClick={() => this.setState({ references: regex.title })}
+                  primary={references !== regex.title}
+                  style={{ flex: 1, margin: '0 1px' }}
+                >
+                  {regex.title}
+                </Button>
+              )
+            }
+            return null
+          })}
+        </div>
+        {regexes.length === 0 && (
+          <Loading>
+            <LoadingIcon />
+          </Loading>
+        )}
+        {regexes.map(regex => {
+          if (references === regex.title) {
+            return (
+              <ul key={regex.title}>
+                {regex.array.sort().map(match => (
+                  <li key={match}>{match}</li>
+                ))}
+              </ul>
+            )
+          }
+          return null
+        })}
+      </div>
+    )
+  }
+}
+
+export default SubmitHighlights
diff --git a/app/components/submission-wizard/SubmitPage.jsx b/app/components/submission-wizard/SubmitPage.jsx
index 320167b89..51951b490 100755
--- a/app/components/submission-wizard/SubmitPage.jsx
+++ b/app/components/submission-wizard/SubmitPage.jsx
@@ -32,6 +32,7 @@ import Citation from './Citation'
 import GrantSearch from './GrantSearch'
 import SelectReviewer from './SelectReviewer'
 import SubmitForm from './SubmitForm'
+import SubmitHighlights from './SubmitHighlights'
 import { NoteMutations, ManuscriptMutations } from './SubmitMutations'
 
 const Alert = withTheme(({ children, theme }) => (
@@ -68,8 +69,7 @@ class Submit extends React.Component {
     super(props)
     this.state = {
       editing: null,
-      references: 'Supplements',
-      regexes: [],
+      highlights: '',
       status: '',
       error: '',
     }
@@ -82,52 +82,10 @@ class Submit extends React.Component {
     ) {
       const fake = document.createElement('div')
       // fake.innerHTML = this.props.currentVersion.source
-      this.makeList(fake.textContent)
+      this.setState({ highlights: fake.textContent })
     }
   }
   static contextType = UserContext
-  makeList = matchString => {
-    const sups = matchString.match(
-      /(supp(?!lemented|lementing|ort[\W]|ort(?!ing)|orting [^i]|ress|ly|li|ler)[\w.]*\s*[\w.]*|extended data)\s*(?!and)\w*(,?\s*(\d+|\w\d+))*((?!(\s*and\s*|-|\u2013|\u2014|&)supp|extended|fig|table)(\s*and\s*|-|\u2013|\u2014|&)\w*)?/gi,
-    )
-    const figs = matchString.match(
-      /(\W(supp[\w.]*|extended data)\s*|\W?)fig[\w.]*\s*(\d+|\w\d+)\w*(,?\s*(\d+|\w\d+))*((\s*and\s*|-|\u2013|\u2014|&)(?!supp|extended|fig|table)(\d+|\w\d+|\w+)\w*)*/gi,
-    )
-    const tables = matchString.match(
-      /\W((supp[\w.]*|extended data)\s*)?table[\w]*\s*(\d+|\w\d+)\w*(,?\s*(\d+|\w\d+))*((\s*and\s*|-|\u2013|\u2014|&)(?!supp|extended|fig|table)(\d+|\w\d+|\w+)\w*)*/gi,
-    )
-    const regexes = [
-      {
-        title: 'Supplements',
-        array: [
-          ...new Set(sups && sups.map(match => match.replace(/\s\s+/g, ' '))),
-        ],
-      },
-      {
-        title: 'Figures',
-        array: [
-          ...new Set(
-            figs &&
-              figs.map(match =>
-                match.replace(/^\W/, '').replace(/\s\s+/g, ' '),
-              ),
-          ),
-        ].filter(match => !/^(supp|extended data)/i.test(match)),
-      },
-      {
-        title: 'Tables',
-        array: [
-          ...new Set(
-            tables &&
-              tables.map(match =>
-                match.replace(/^\W/, '').replace(/\s\s+/g, ' '),
-              ),
-          ),
-        ].filter(match => !/^(supp|extended data)/i.test(match)),
-      },
-    ]
-    this.setState({ regexes })
-  }
   changeCitation = citation => {
     this.props.changeCitation(citation)
     this.setState({ editing: null, status: '' })
@@ -147,7 +105,7 @@ class Submit extends React.Component {
       formState,
     } = manuscript
     if (teams && allfiles) {
-      const { editing, references, regexes } = this.state
+      const { editing, highlights } = this.state
       const {
         fundingGroup: grants,
         releaseDelay = '',
@@ -324,50 +282,7 @@ class Submit extends React.Component {
 
       const highlightTerms = {
         title: 'Referenced attachments',
-        content:
-          !regexes ||
-          (regexes.length > 0 && !regexes.some(x => x.array.length > 0)) ? (
-            <div>No results</div>
-          ) : (
-            <div style={{ padding: 0 }}>
-              <div style={{ display: 'flex', justifyContent: 'stretch' }}>
-                {regexes.map(regex => {
-                  if (regex.array.length > 0) {
-                    return (
-                      <Button
-                        key={regex.title}
-                        onClick={() =>
-                          this.setState({ references: regex.title })
-                        }
-                        primary={references !== regex.title}
-                        style={{ flex: 1, margin: '0 1px' }}
-                      >
-                        {regex.title}
-                      </Button>
-                    )
-                  }
-                  return null
-                })}
-              </div>
-              {regexes.length === 0 && (
-                <Loading>
-                  <LoadingIcon />
-                </Loading>
-              )}
-              {regexes.map(regex => {
-                if (references === regex.title) {
-                  return (
-                    <ul key={regex.title}>
-                      {regex.array.sort().map(match => (
-                        <li key={match}>{match}</li>
-                      ))}
-                    </ul>
-                  )
-                }
-                return null
-              })}
-            </div>
-          ),
+        content: <SubmitHighlights highlights={highlights} />,
         edit: '',
         error: '',
       }
@@ -427,9 +342,9 @@ class Submit extends React.Component {
               <PanelContent>
                 <ManuscriptPreview
                   file={files.find(file => file.type === 'manuscript')}
-                  textContent={
+                  textContent={highlights =>
                     currentUser.admin && status === 'submitted'
-                      ? this.makeList
+                      ? this.setState({ highlights })
                       : false
                   }
                 />
-- 
GitLab