diff --git a/packages/component-faraday-selectors/src/index.js b/packages/component-faraday-selectors/src/index.js index 95f9a5b80adf044e2ed228d636c9ce8d793869be..d95643452340c8c5607971adb3da46092e2a4801 100644 --- a/packages/component-faraday-selectors/src/index.js +++ b/packages/component-faraday-selectors/src/index.js @@ -75,6 +75,7 @@ export const canSeeReviewersReports = (state, collectionId) => { export const canMakeRevision = (state, collection, fragment) => { const currentUserId = get(state, 'currentUser.user.id') return ( + get(fragment, 'revision') && collection.status === 'revisionRequested' && fragment.owners.map(o => o.id).includes(currentUserId) ) diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js index 318822b55f342766aef036cc697548d2c17aca9c..ea90b83967e7dbbd429f89747956d3c7f97968f9 100644 --- a/packages/component-manuscript/src/components/ManuscriptLayout.js +++ b/packages/component-manuscript/src/components/ManuscriptLayout.js @@ -27,6 +27,7 @@ const ManuscriptLayout = ({ history, currentUser, editorInChief, + canMakeRevision, editorialRecommendations, project = {}, version = {}, @@ -56,7 +57,7 @@ const ManuscriptLayout = ({ fragment={version} startExpanded={isEmpty(version.revision)} /> - {version.revision && ( + {canMakeRevision && ( <SubmitRevision project={project} version={version} /> )} <ReviewsAndReports project={project} version={version} /> diff --git a/packages/component-manuscript/src/components/ManuscriptPage.js b/packages/component-manuscript/src/components/ManuscriptPage.js index a832022fdb722c6e9fe0dd077639eed86e449147..b6ff4faa6b97eed352a2ce4468fc2e97328484c8 100644 --- a/packages/component-manuscript/src/components/ManuscriptPage.js +++ b/packages/component-manuscript/src/components/ManuscriptPage.js @@ -29,6 +29,7 @@ import { getHandlingEditors, selectHandlingEditors, } from 'pubsweet-components-faraday/src/redux/editors' +import { canMakeRevision } from 'pubsweet-component-faraday-selectors/src' import ManuscriptLayout from './ManuscriptLayout' import { parseSearchParams, redirectToError } from './utils' @@ -64,6 +65,9 @@ export default compose( updateVersion: actions.updateFragment, }, ), + connect((state, { project, version }) => ({ + canMakeRevision: canMakeRevision(state, project, version), + })), ConnectPage(({ currentUser, handlingEditors, project }) => { const he = get(project, 'handlingEditor') if ( diff --git a/packages/component-manuscript/src/components/SideBarActions.js b/packages/component-manuscript/src/components/SideBarActions.js index 76a9369e78aecb0fca7ef61a44ae14629345773a..b3e9036a0a353e26d401bd021cd2de8622f9a6d7 100644 --- a/packages/component-manuscript/src/components/SideBarActions.js +++ b/packages/component-manuscript/src/components/SideBarActions.js @@ -1,9 +1,9 @@ import React from 'react' import { compose } from 'recompose' +import { Icon } from '@pubsweet/ui' import { connect } from 'react-redux' import styled from 'styled-components' import { th } from '@pubsweet/ui-toolkit' -import { Icon, Button } from '@pubsweet/ui' import { withRouter } from 'react-router-dom' import ZipFiles from 'pubsweet-components-faraday/src/components/Files/ZipFiles' import { @@ -14,23 +14,18 @@ import { import { createRevision } from 'pubsweet-component-wizard/src/redux/conversion' import { - canMakeRevision, canMakeDecision, canMakeRecommendation, -} from '../../../component-faraday-selectors' +} from 'pubsweet-component-faraday-selectors/src' const SideBarActions = ({ project, version, createRevision, - canMakeRevision, canMakeDecision, canMakeRecommendation, }) => ( <Root> - {canMakeRevision && ( - <DecisionButton onClick={createRevision}>Submit revision</DecisionButton> - )} {canMakeDecision && ( <Decision collectionId={project.id} @@ -63,7 +58,6 @@ export default compose( connect( (state, { project, version }) => ({ canMakeDecision: canMakeDecision(state, project), - canMakeRevision: canMakeRevision(state, project, version), canMakeRecommendation: canMakeRecommendation(state, project), }), (dispatch, { project, version, history }) => ({ @@ -86,17 +80,4 @@ const ClickableIcon = styled.div` opacity: 0.7; } ` - -const DecisionButton = styled(Button)` - align-items: center; - background-color: ${th('colorPrimary')}; - color: ${th('colorTextReverse')}; - display: flex; - font-family: ${th('fontReading')}; - font-size: ${th('fontSizeBaseSmall')}; - height: calc(${th('subGridUnit')} * 5); - padding: calc(${th('subGridUnit')} / 2) ${th('subGridUnit')}; - text-align: center; - white-space: nowrap; -` // #endregion diff --git a/packages/component-manuscript/src/components/utils.js b/packages/component-manuscript/src/components/utils.js index 2f7a3b5386e5a5560ea66df6371763b0241f5da2..3ad73509bb38957d078a00e46797914f37e5bbc3 100644 --- a/packages/component-manuscript/src/components/utils.js +++ b/packages/component-manuscript/src/components/utils.js @@ -1,5 +1,13 @@ import moment from 'moment' -import { get, find, capitalize, omit, isEmpty, debounce } from 'lodash' +import { + get, + find, + omit, + isEmpty, + debounce, + mergeWith, + capitalize, +} from 'lodash' import { actions } from 'pubsweet-client/src' import { change as changeForm } from 'redux-form' @@ -187,14 +195,25 @@ export const onReviewSubmit = ( }) } +const parseRevision = (values, fragment) => { + const v = omit(values, 'authorForm') + + return { + ...fragment, + revision: { + ...v, + metadata: mergeWith( + {}, + fragment.metadata, + v.metadata, + (obj, src) => (src === '' ? obj : src), + ), + }, + } +} + const _onRevisionChange = (values, dispatch, { project, version }) => { - const newValues = omit(values, 'authorForm') - dispatch( - actions.updateFragment(project, { - ...version, - revision: newValues, - }), - ) + dispatch(actions.updateFragment(project, parseRevision(values, version))) } export const onRevisionChange = debounce(_onRevisionChange, 1000, { maxWait: 5000, @@ -219,12 +238,10 @@ export const onRevisionSubmit = ( onConfirm: () => { submitRevision(project.id, version.id) .then(r => { - dispatch(actions.getFragments({ id: project.id })) - return r - }) - .then(r => { - history.push(`/projects/${r.collectionId}/version/${r.id}/details`) - hideModal() + dispatch(actions.getFragments({ id: project.id })).then(() => { + history.push(`/projects/${r.collectionId}/versions/${r.id}/details`) + hideModal() + }) }) .catch(e => setModalError('Something went wrong.')) },