From 03951dd7d67d24e9e102d4f1092563ada7cccbb6 Mon Sep 17 00:00:00 2001 From: Alexandru Munteanu <alexandru.munt@gmail.com> Date: Wed, 23 May 2018 13:45:42 +0300 Subject: [PATCH] refactor(various): remove unused code; create faraday-selectors --- .../component-faraday-selectors/package.json | 6 ++++ .../component-faraday-selectors/src/index.js | 18 +++++++++++ .../src/components/SideBarActions.js | 22 ++------------ .../src/components/Dashboard/DashboardCard.js | 30 +++++++++---------- .../src/components/Dashboard/TestComponent.js | 9 ------ .../src/components/Dashboard/withFactory.js | 13 -------- 6 files changed, 41 insertions(+), 57 deletions(-) create mode 100644 packages/component-faraday-selectors/package.json create mode 100644 packages/component-faraday-selectors/src/index.js delete mode 100644 packages/components-faraday/src/components/Dashboard/TestComponent.js delete mode 100644 packages/components-faraday/src/components/Dashboard/withFactory.js diff --git a/packages/component-faraday-selectors/package.json b/packages/component-faraday-selectors/package.json new file mode 100644 index 000000000..4374d892a --- /dev/null +++ b/packages/component-faraday-selectors/package.json @@ -0,0 +1,6 @@ +{ + "name": "pubsweet-component-faraday-selectors", + "version": "0.0.1", + "main": "src", + "license": "MIT" +} diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js new file mode 100644 index 000000000..52c72aad6 --- /dev/null +++ b/packages/component-faraday-selectors/src/index.js @@ -0,0 +1,18 @@ +import { get } from 'lodash' + +export const isHEToManuscript = (state, collectionId) => { + const currentUserId = get(state, 'currentUser.user.id') + const collections = get(state, 'collections') || [] + const collection = collections.find(c => c.id === collectionId) || {} + const collectionInvitations = get(collection, 'invitations') || [] + const userInvitation = collectionInvitations.find( + i => i.role === 'handlingEditor' && i.userId === currentUserId, + ) + + return userInvitation ? userInvitation.isAccepted : false +} + +export const canMakeRecommendation = (state, project) => { + const isHE = isHEToManuscript(state, project.id) + return isHE && get(project, 'status') === 'reviewCompleted' +} diff --git a/packages/component-manuscript/src/components/SideBarActions.js b/packages/component-manuscript/src/components/SideBarActions.js index 2e6140220..a8cc8acf2 100644 --- a/packages/component-manuscript/src/components/SideBarActions.js +++ b/packages/component-manuscript/src/components/SideBarActions.js @@ -1,13 +1,13 @@ import React from 'react' -import { get } from 'lodash' +import { compose } from 'recompose' import { connect } from 'react-redux' import styled from 'styled-components' import { th, Icon } from '@pubsweet/ui' -import { compose, withProps } from 'recompose' import ZipFiles from 'pubsweet-components-faraday/src/components/Files/ZipFiles' import { Recommendation } from 'pubsweet-components-faraday/src/components/MakeRecommendation' import { MakeDecision } from './' +import { canMakeRecommendation } from '../../../component-faraday-selectors/src' const SideBarActions = ({ project, @@ -36,25 +36,9 @@ const SideBarActions = ({ </Root> ) -const isHEToManuscript = (state, collectionId) => { - const currentUserId = get(state, 'currentUser.user.id') - const collections = get(state, 'collections') || [] - const collection = collections.find(c => c.id === collectionId) || {} - const collectionInvitations = get(collection, 'invitations') || [] - const userInvitation = collectionInvitations.find( - i => i.role === 'handlingEditor' && i.userId === currentUserId, - ) - - return userInvitation ? userInvitation.isAccepted : false -} - export default compose( connect((state, { project }) => ({ - isHEToManuscript: isHEToManuscript(state, project.id), - })), - withProps(({ isHEToManuscript, project }) => ({ - canMakeRecommendation: - isHEToManuscript && get(project, 'status') === 'reviewCompleted', + canMakeRecommendation: canMakeRecommendation(state, project), })), )(SideBarActions) diff --git a/packages/components-faraday/src/components/Dashboard/DashboardCard.js b/packages/components-faraday/src/components/Dashboard/DashboardCard.js index 720c6ea6f..a9af74ea5 100644 --- a/packages/components-faraday/src/components/Dashboard/DashboardCard.js +++ b/packages/components-faraday/src/components/Dashboard/DashboardCard.js @@ -4,7 +4,7 @@ import { connect } from 'react-redux' import PropTypes from 'prop-types' import { Button, Icon, th } from '@pubsweet/ui' import styled, { css, withTheme } from 'styled-components' -import { compose, getContext, withHandlers, withProps } from 'recompose' +import { compose, getContext, withHandlers } from 'recompose' import { withModal, ConfirmationModal, @@ -18,6 +18,7 @@ import { currentUserIs } from '../../redux/users' import { selectInvitation } from '../../redux/reviewers' import { ReviewerDecision, HandlingEditorSection } from './' import { parseVersion, parseJournalIssue, mapStatusToLabel } from './../utils' +import { canMakeRecommendation } from '../../../../component-faraday-selectors/src' import { ReviewerBreakdown } from '../Invitations' import { Recommendation } from '../MakeRecommendation' @@ -166,17 +167,17 @@ const DashboardCard = ({ ) : null } -const isHEToManuscript = (state, collectionId) => { - const currentUserId = get(state, 'currentUser.user.id') - const collections = get(state, 'collections') || [] - const collection = collections.find(c => c.id === collectionId) || {} - const collectionInvitations = get(collection, 'invitations') || [] - const userInvitation = collectionInvitations.find( - i => i.role === 'handlingEditor' && i.userId === currentUserId, - ) +// const isHEToManuscript = (state, collectionId) => { +// const currentUserId = get(state, 'currentUser.user.id') +// const collections = get(state, 'collections') || [] +// const collection = collections.find(c => c.id === collectionId) || {} +// const collectionInvitations = get(collection, 'invitations') || [] +// const userInvitation = collectionInvitations.find( +// i => i.role === 'handlingEditor' && i.userId === currentUserId, +// ) - return userInvitation ? userInvitation.isAccepted : false -} +// return userInvitation ? userInvitation.isAccepted : false +// } export default compose( getContext({ journal: PropTypes.object, currentUser: PropTypes.object }), @@ -188,12 +189,9 @@ export default compose( connect((state, { project }) => ({ isHE: currentUserIs(state, 'handlingEditor'), invitation: selectInvitation(state, project.id), - isHEToManuscript: isHEToManuscript(state, project.id), - })), - withProps(({ isHEToManuscript, project }) => ({ - canMakeRecommendation: - isHEToManuscript && get(project, 'status') === 'reviewCompleted', + canMakeRecommendation: canMakeRecommendation(state, project), })), + withHandlers({ canInviteReviewers: ({ currentUser, project }) => () => { const handlingEditor = get(project, 'handlingEditor') diff --git a/packages/components-faraday/src/components/Dashboard/TestComponent.js b/packages/components-faraday/src/components/Dashboard/TestComponent.js deleted file mode 100644 index 1a5c24a81..000000000 --- a/packages/components-faraday/src/components/Dashboard/TestComponent.js +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react' - -import withFactory from './withFactory' - -const TestComponent = ({ ceva, ...rest }) => <div>{ceva}</div> - -export default withFactory(props => ({ - ceva: 'hai sa vedem', -}))(TestComponent) diff --git a/packages/components-faraday/src/components/Dashboard/withFactory.js b/packages/components-faraday/src/components/Dashboard/withFactory.js deleted file mode 100644 index 30fffc01c..000000000 --- a/packages/components-faraday/src/components/Dashboard/withFactory.js +++ /dev/null @@ -1,13 +0,0 @@ -import { createFactory } from 'react' - -const withFactory = propsMapper => BaseComponent => { - const factory = createFactory(BaseComponent) - const WithFactory = props => - factory( - typeof propsMapper === 'function' ? propsMapper(props) : propsMapper, - ) - - return WithFactory -} - -export default withFactory -- GitLab