From 0e35e1615d1da10e7fc136e3ed0fbc0c03f63c7b Mon Sep 17 00:00:00 2001
From: Bogdan Cochior <bogdan.cochior@thinslices.com>
Date: Thu, 8 Feb 2018 14:53:53 +0200
Subject: [PATCH] refactor(component): add countries list and fix height for
 dropdown menu

---
 .../src/components/AuthorList/AuthorAdder.js         |  8 +-------
 .../src/components/AuthorList/AuthorEditor.js        |  8 +-------
 .../src/components/AuthorList/AuthorList.js          | 11 +++--------
 .../src/components/AuthorList/FormItems.js           |  2 +-
 .../src/components/AuthorList/FormItems.local.scss   |  7 +++++++
 .../src/components/Dashboard/DashboardFilters.js     | 12 ------------
 6 files changed, 13 insertions(+), 35 deletions(-)

diff --git a/packages/components-faraday/src/components/AuthorList/AuthorAdder.js b/packages/components-faraday/src/components/AuthorList/AuthorAdder.js
index a3380004f..19a4bda77 100644
--- a/packages/components-faraday/src/components/AuthorList/AuthorAdder.js
+++ b/packages/components-faraday/src/components/AuthorList/AuthorAdder.js
@@ -7,18 +7,12 @@ import { reduxForm } from 'redux-form'
 import { compose, withProps } from 'recompose'
 import { selectCurrentUser } from 'xpub-selectors'
 
+import countries from './countries'
 import { Spinner } from '../UIComponents/'
 import classes from './AuthorList.local.scss'
 import { getAuthorFetching } from '../../redux/authors'
 import { MenuItem, ValidatedTextField } from './FormItems'
 
-const countries = [
-  { label: 'Romania', value: 'ro' },
-  { label: 'United Kingdom', value: 'uk' },
-  { label: 'Germany', value: 'de' },
-  { label: 'France', value: 'fr' },
-]
-
 const emailRegex = new RegExp(/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/)
 
 const emailValidator = value =>
diff --git a/packages/components-faraday/src/components/AuthorList/AuthorEditor.js b/packages/components-faraday/src/components/AuthorList/AuthorEditor.js
index 10f4f5a81..72ea87fc3 100644
--- a/packages/components-faraday/src/components/AuthorList/AuthorEditor.js
+++ b/packages/components-faraday/src/components/AuthorList/AuthorEditor.js
@@ -5,19 +5,13 @@ import { Button } from '@pubsweet/ui'
 import { connect } from 'react-redux'
 import { reduxForm } from 'redux-form'
 
+import countries from './countries'
 import { Spinner } from '../UIComponents'
 import { getAuthorFetching } from '../../redux/authors'
 import { ValidatedTextField, MenuItem } from './FormItems'
 
 import classes from './AuthorList.local.scss'
 
-const countries = [
-  { label: 'Romania', value: 'ro' },
-  { label: 'United Kingdom', value: 'uk' },
-  { label: 'Germany', value: 'de' },
-  { label: 'France', value: 'fr' },
-]
-
 const emailRegex = new RegExp(/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/)
 
 const emailValidator = value =>
diff --git a/packages/components-faraday/src/components/AuthorList/AuthorList.js b/packages/components-faraday/src/components/AuthorList/AuthorList.js
index 06f4f7bb2..222366bc6 100644
--- a/packages/components-faraday/src/components/AuthorList/AuthorList.js
+++ b/packages/components-faraday/src/components/AuthorList/AuthorList.js
@@ -1,6 +1,7 @@
 import React from 'react'
 import PropTypes from 'prop-types'
 import { connect } from 'react-redux'
+import { get } from 'lodash'
 import { withRouter } from 'react-router-dom'
 import {
   compose,
@@ -15,18 +16,12 @@ import { SortableList } from 'pubsweet-components-faraday/src/components'
 import { addAuthor } from '../../redux/authors'
 
 import Author from './Author'
+import countries from './countries'
 import StaticList from './StaticList'
 import AuthorAdder from './AuthorAdder'
 import AuthorEditor from './AuthorEditor'
 import { DragHandle } from './FormItems'
 
-const countries = [
-  { label: 'Romania', value: 'ro' },
-  { label: 'United Kingdom', value: 'uk' },
-  { label: 'Germany', value: 'de' },
-  { label: 'France', value: 'fr' },
-]
-
 const Authors = ({
   authors,
   moveAuthor,
@@ -111,7 +106,7 @@ export default compose(
       setFormAuthors(authors)
     },
     countryParser: () => countryCode =>
-      countries.find(c => c.value === countryCode).label,
+      get(countries.find(c => c.value === countryCode), 'label'),
     parseAuthorType: () => (isSubmitting, isCorresponding, index) => {
       if (isSubmitting) return `#${index + 1} Submitting author`
       if (isCorresponding) return `#${index + 1} Corresponding author`
diff --git a/packages/components-faraday/src/components/AuthorList/FormItems.js b/packages/components-faraday/src/components/AuthorList/FormItems.js
index a51969f62..96b8a93c4 100644
--- a/packages/components-faraday/src/components/AuthorList/FormItems.js
+++ b/packages/components-faraday/src/components/AuthorList/FormItems.js
@@ -21,7 +21,7 @@ export const ValidatedTextField = ({
 }
 
 export const MenuItem = ({ label, name, options }) => (
-  <div className={classnames(classes['validated-text'])}>
+  <div className={classnames(classes['validated-text'], classes['fix-height'])}>
     <span className={classnames(classes.label)}>{label}</span>
     <ValidatedField
       component={input => <Menu {...input} options={options} />}
diff --git a/packages/components-faraday/src/components/AuthorList/FormItems.local.scss b/packages/components-faraday/src/components/AuthorList/FormItems.local.scss
index 2ffbe8897..1a2e5c0fe 100644
--- a/packages/components-faraday/src/components/AuthorList/FormItems.local.scss
+++ b/packages/components-faraday/src/components/AuthorList/FormItems.local.scss
@@ -21,6 +21,13 @@
   }
 }
 
+.fix-height {
+  div[class^='Menu-local_options-'] {
+    height: 250px;
+    overflow-y: scroll;
+  }
+}
+
 .drag-handle {
   align-items: center;
   border-right: 1px solid #444;
diff --git a/packages/components-faraday/src/components/Dashboard/DashboardFilters.js b/packages/components-faraday/src/components/Dashboard/DashboardFilters.js
index 898778b14..782412639 100644
--- a/packages/components-faraday/src/components/Dashboard/DashboardFilters.js
+++ b/packages/components-faraday/src/components/Dashboard/DashboardFilters.js
@@ -6,18 +6,6 @@ import { compose, withHandlers } from 'recompose'
 import classes from './Dashboard.local.scss'
 import { changeFilter, changeSort } from './redux/filters'
 
-const statusFilterOptions = [
-  { label: 'All', value: 'all' },
-  { label: 'Submitted', value: 'submitted' },
-  { label: 'Draft', value: 'draft' },
-]
-
-const ownerFilterOptions = [
-  { label: 'Everyone', value: 'all' },
-  { label: 'My work', value: 'me' },
-  { label: `Other's work`, value: 'other' },
-]
-
 const sortOptions = [
   { label: 'Newest first', value: 'newest' },
   { label: 'Oldest first', value: 'oldest' },
-- 
GitLab