Skip to content

Commit

Permalink
fix(ZNTA-2318): rejecting translation by keypress, MainContent now st…
Browse files Browse the repository at this point in the history
…ateless
  • Loading branch information
efloden committed Feb 8, 2018
1 parent c1ba106 commit 1a8ed72
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
Expand Up @@ -8,6 +8,7 @@ import {
savePhraseWithStatus } from './phrases-actions'
import { moveNext, movePrevious } from './phrase-navigation-actions'
import { copySuggestionN } from './suggestions-actions'
import { toggleReviewModal } from './review-trans-actions'
import {
STATUS_TRANSLATED,
STATUS_NEEDS_WORK,
Expand Down Expand Up @@ -211,7 +212,11 @@ function saveAs (status) {
if (isSaving || (isCurrentStatus && !hasTranslationChanged(phrase))) {
return
}
dispatch(savePhraseWithStatus(phrase, status))
if (status === STATUS_REJECTED) {
dispatch(toggleReviewModal())
} else {
dispatch(savePhraseWithStatus(phrase, status))
}
}
}
}
Expand Down
Expand Up @@ -6,6 +6,7 @@ import {
} from '../../actions/common-actions'
import { savePhraseWithStatus } from './phrases-actions'
import { STATUS_REJECTED } from '../utils/status-util'
import { createAction } from 'redux-actions'

export const ADD_REVIEW_REQUEST = 'ADD_REVIEW_REQUEST'
export const ADD_REVIEW_SUCCESS = 'ADD_REVIEW_SUCCESS'
Expand All @@ -14,6 +15,8 @@ export const GET_ALL_CRITERIA_REQUEST = 'GET_ALL_CRITERIA_REQUEST'
export const GET_ALL_CRITERIA_SUCCESS = 'GET_ALL_CRITERIA_SUCCESS'
export const GET_ALL_CRITERIA_FAILURE = 'GET_ALL_CRITERIA_FAILURE'

export const TOGGLE_REVIEW_MODAL = 'TOGGLE_REVIEW_MODAL'

/**
* Perform a save of a translation review with the given review data
*/
Expand Down Expand Up @@ -44,6 +47,8 @@ export function rejectTranslation (dispatch, review) {
}
}

export const toggleReviewModal = createAction(TOGGLE_REVIEW_MODAL)

export function fetchAllCriteria () {
const endpoint = `${apiUrl}/review`
const apiTypes = [
Expand Down
26 changes: 11 additions & 15 deletions server/zanata-frontend/src/app/editor/containers/MainContent.js
Expand Up @@ -5,7 +5,9 @@ import { Icon } from '../../components'
import TransUnit from '../components/TransUnit'
import { connect } from 'react-redux'
import { getCurrentPagePhraseDetail } from '../selectors'
import { fetchAllCriteria } from '../actions/review-trans-actions'
import {
fetchAllCriteria, toggleReviewModal
} from '../actions/review-trans-actions'
import { getCriteria } from '../reducers/review-trans-reducer'
import { MINOR, MAJOR, CRITICAL } from '../utils/reject-trans-util'
import RejectTranslationModal from '../containers/RejectTranslationModal'
Expand All @@ -17,7 +19,9 @@ import { isUndefined } from 'lodash'
class MainContent extends React.Component {
static propTypes = {
maximised: PropTypes.bool.isRequired,
showReviewModal: PropTypes.bool.isRequired,
phrases: PropTypes.arrayOf(PropTypes.object).isRequired,
toggleReviewModal: PropTypes.func.isRequired,
fetchAllCriteria: PropTypes.func.isRequired,
criteria: PropTypes.arrayOf(PropTypes.shape({
editable: PropTypes.bool.isRequired,
Expand All @@ -29,20 +33,9 @@ class MainContent extends React.Component {
}).isRequired,
selectedPhraseId: PropTypes.number
}
constructor (props) {
super(props)
this.state = {
showRejectModal: false
}
}
componentDidMount () {
this.props.fetchAllCriteria()
}
toggleRejectModal = () => {
this.setState(prevState => ({
showRejectModal: !prevState.showRejectModal
}))
}
render () {
const { maximised, phrases } = this.props
if (phrases.length === 0) {
Expand Down Expand Up @@ -71,7 +64,7 @@ class MainContent extends React.Component {
index={phrase.id}
phrase={phrase}
criteria={this.props.criteria}
toggleRejectModal={this.toggleRejectModal} />
toggleRejectModal={this.props.toggleReviewModal} />
</li>
)
})
Expand All @@ -97,8 +90,8 @@ class MainContent extends React.Component {
</ul>
</div>
<RejectTranslationModal
show={this.state.showRejectModal}
onHide={this.toggleRejectModal}
show={this.props.showReviewModal}
onHide={this.props.toggleReviewModal}
transUnitID={this.props.selectedPhraseId}
revision={selectedPhraseRevision}
localeId={this.props.translationLocale.id}
Expand All @@ -112,8 +105,10 @@ class MainContent extends React.Component {
function mapStateToProps (state, ownProps) {
// TODO replace with selector
const maximised = !state.ui.panels.navHeader.visible
const showReviewModal = state.review.showReviewModal
return {
maximised,
showReviewModal: showReviewModal,
criteria: getCriteria(state),
phrases: getCurrentPagePhraseDetail(state),
translationLocale: {
Expand All @@ -125,6 +120,7 @@ function mapStateToProps (state, ownProps) {

function mapDispatchToProps (dispatch) {
return {
toggleReviewModal: () => dispatch(toggleReviewModal()),
fetchAllCriteria: () => dispatch(fetchAllCriteria())
}
}
Expand Down
Expand Up @@ -2,11 +2,13 @@ import { handleActions } from 'redux-actions'
import update from 'immutability-helper'
import {
GET_ALL_CRITERIA_SUCCESS,
GET_ALL_CRITERIA_FAILURE
GET_ALL_CRITERIA_FAILURE,
TOGGLE_REVIEW_MODAL
} from '../actions/review-trans-actions'

const defaultState = {
notification: undefined,
showReviewModal: false,
criteria: []
}

Expand All @@ -33,6 +35,13 @@ const review = handleActions({
$set: `Failed to retrieve review criteria. ${getErrorMessage(action)}`
}
})
},
[TOGGLE_REVIEW_MODAL]: (state, action) => {
return update(state, {
showReviewModal: {
$set: !state.showReviewModal
}
})
}
}, defaultState)

Expand Down

0 comments on commit 1a8ed72

Please sign in to comment.