-
Notifications
You must be signed in to change notification settings - Fork 51
/
CriteriaDropdown.js
76 lines (75 loc) · 2.15 KB
/
CriteriaDropdown.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
import React from 'react'
import { Component } from 'react'
import { Icon } from '../../../components'
import * as PropTypes from 'prop-types'
import Dropdown from '../../components/Dropdown'
import {
MINOR, MAJOR, CRITICAL, UNSPECIFIED
} from '../../utils/reject-trans-util'
/**
* A Local Editor Dropdown coponent that selects the Criteria
* for a translation rejection
*/
class CriteriaDropdown extends Component {
static propTypes = {
criteriaList: PropTypes.arrayOf(PropTypes.shape({
commentRequired: PropTypes.bool.isRequired,
description: PropTypes.string.isRequired,
priority: PropTypes.oneOf([MINOR, MAJOR, CRITICAL]).isRequired
})).isRequired,
onCriteriaChange: PropTypes.func.isRequired,
onUnspecifiedCriteria: PropTypes.func.isRequired,
criteriaDescription: PropTypes.string.isRequired
}
constructor (props) {
super(props)
this.state = {
dropdownOpen: false
}
}
toggleDropdown = () => {
this.setState(prevState => ({
dropdownOpen: !prevState.dropdownOpen
}))
}
onCriteriaChange = (event) => {
if (event.target.innerText === UNSPECIFIED.description) {
this.props.onUnspecifiedCriteria()
} else {
this.props.onCriteriaChange(event)
}
this.toggleDropdown()
}
render () {
const { criteriaList, criteriaDescription } = this.props
const options = criteriaList.map((value, index) => {
return (
<li key={index}
className='EditorDropdown-item'
onClick={this.onCriteriaChange}>
{value.description}
</li>
)
})
return (
<Dropdown enabled isOpen={this.state.dropdownOpen}
onToggle={this.toggleDropdown}
className='dropdown-menu Criteria'>
<Dropdown.Button>
<a className='EditorDropdown-item ellipsis'>
{criteriaDescription}
<span className='arrow'>
<Icon className='n1' name='chevron-down' />
</span>
</a>
</Dropdown.Button>
<Dropdown.Content>
<ul>
{options}
</ul>
</Dropdown.Content>
</Dropdown>
)
}
}
export default CriteriaDropdown