-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDatasetsDropdown.js
54 lines (47 loc) · 1.6 KB
/
DatasetsDropdown.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
import i18n from '@dhis2/d2-i18n'
import { DropDown } from '@dhis2/d2-ui-core'
import PropTypes from 'prop-types'
import React from 'react'
import { connect } from 'react-redux'
import { selectDataSet } from '../redux/actions/dataSet.js'
import { formLabel } from '../utils/styles/shared.js'
const hintTextLoading = i18n.t('Loading options...')
const hintTextDefault = i18n.t('Select Data Set')
export const DatasetsDropdown = (props) => (
<div>
<span className={formLabel.className}>{props.label}</span>
<DropDown
fullWidth={props.fullWidth}
value={props.selected.id}
onChange={props.onChange ? props.onChange : props.selectDataSet}
menuItems={props.options}
hintText={props.loading ? hintTextLoading : hintTextDefault}
disabled={props.loading}
/>
{formLabel.styles}
</div>
)
DatasetsDropdown.propTypes = {
loading: PropTypes.bool.isRequired,
options: PropTypes.array.isRequired,
selectDataSet: PropTypes.func.isRequired,
selected: PropTypes.object.isRequired,
fullWidth: PropTypes.bool,
label: PropTypes.string,
onChange: PropTypes.func,
}
DatasetsDropdown.defaultProps = {
onChange: null,
label: i18n.t('Data set'),
fullWidth: true,
filter: null,
}
const mapStateToProps = ({ dataSet: { loading, selected, options } }) => ({
loading,
selected,
options,
})
const mapDispatchToProps = (dispatch) => ({
selectDataSet: (event) => dispatch(selectDataSet(event.target.value)),
})
export default connect(mapStateToProps, mapDispatchToProps)(DatasetsDropdown)