-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.js
169 lines (166 loc) · 5.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import React from 'react'
import { Component } from 'react'
import * as PropTypes from 'prop-types'
import { connect } from 'react-redux'
import Button from '../../components/Button'
import { Row } from 'react-bootstrap'
import { Modal } from '../../../components'
import PriorityDropdown from './PriorityDropdown'
import CriteriaDropdown from './CriteriaDropdown'
import { rejectTranslation } from '../../actions/review-trans-actions'
import update from 'immutability-helper'
import {
MINOR, MAJOR, CRITICAL, priorities, textState
} from '../../utils/reject-trans-util'
/**
* Modal to collect feedback on the reason for rejecting a translation.
*/
export class RejectTranslationModal extends Component {
static propTypes = {
show: PropTypes.bool.isRequired,
onHide: PropTypes.func.isRequired,
transUnitID: PropTypes.number.isRequired,
revision: PropTypes.number.isRequired,
localeId: PropTypes.string.isRequired,
criteria: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
editable: PropTypes.bool.isRequired,
description: PropTypes.string.isRequired,
priority: PropTypes.oneOf([MINOR, MAJOR, CRITICAL]).isRequired
})).isRequired,
addNewTransReview: PropTypes.func.isRequired
}
defaultState = {
review: {
selectedPriority: MINOR,
priorityId: 0,
selectedCriteria: '',
criteriaId: 1,
reviewComment: ''
}
}
constructor (props) {
super(props)
this.state = this.defaultState
}
componentWillReceiveProps (nextProps) {
this.setState(prevState => ({
review: update(prevState.review, {
selectedCriteria: {$set: nextProps.criteria[0].description},
selectedPriority: {$set: nextProps.criteria[0].priority}
})
}))
}
onPriorityChange = (event) => {
const selectedPriority = event.target.innerText
const priorityIdIndex = priorities.indexOf(event.target.innerText)
this.setState(prevState => ({
review: update(prevState.review, {
selectedPriority: {$set: selectedPriority},
priorityId: {$set: priorityIdIndex}
})
}))
}
onCriteriaChange = (event) => {
const selectedCriteria = event.target.innerText
const criteriaIdIndex = this.props.criteria.findIndex(
x => x.description === event.target.innerText)
const criteriaId = this.props.criteria[criteriaIdIndex]
this.setState(prevState => ({
review: update(prevState.review, {
selectedCriteria: {$set: selectedCriteria},
criteriaId: {$set: criteriaId}
})
}))
}
setReviewComment = (event) => {
const reviewComment = event.target.value
this.setState(prevState => ({
review: update(prevState.review, {
reviewComment: {$set: reviewComment}
})
}))
}
saveTransReview = () => {
const review = {
localeId: this.props.localeId,
transUnitId: this.props.transUnitID,
revision: this.props.revision,
criteriaId: this.state.review.criteriaId,
reviewComment: this.state.review.reviewComment
}
this.props.addNewTransReview(review)
this.props.onHide()
}
render () {
const {
show,
onHide,
criteria
} = this.props
const {
review
} = this.state
const priorityTextState = textState(review.selectedPriority)
return (
<Modal show={show}
onHide={onHide}
key='reject-translation-modal'
id='RejectTranslationModal'>
<Modal.Header>
<Modal.Title>Reject translation</Modal.Title>
</Modal.Header>
<Modal.Body>
<div className='flex'>
<span id='CriteriaTitle'>
Criteria
</span>
<CriteriaDropdown
criteriaList={criteria}
onCriteriaChange={this.onCriteriaChange}
selectedCriteria={review.selectedCriteria} />
<PriorityDropdown
textState={priorityTextState}
priority={review.selectedPriority}
priorityChange={this.onPriorityChange} />
</div>
<div className='EditorRejection-input'>
<textarea ref='input'
type='comment'
placeholder='Provide a comment for why this translation has been
rejected'
cols='50'
onChange={this.setReviewComment}
rows='10'
className='EditorInputGroup-input is-focused InputGroup--outlined
Commenting' />
</div>
</Modal.Body>
<Modal.Footer>
<span>
<Row>
<Button
className='EditorButton Button--large u-rounded
Button--secondary'
onClick={onHide}>
Cancel
</Button>
<Button
className='EditorButton Button--large u-rounded Button--primary'
onClick={this.saveTransReview}>
Reject translation
</Button>
</Row>
</span>
</Modal.Footer>
</Modal>
)
}
}
const mapDispatchToProps = dispatch => {
return {
addNewTransReview: (review) => dispatch(rejectTranslation(review)
)
}
}
export default connect(null, mapDispatchToProps)(RejectTranslationModal)