forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeZoneSelect.js
More file actions
46 lines (37 loc) · 1.26 KB
/
Copy pathTimeZoneSelect.js
File metadata and controls
46 lines (37 loc) · 1.26 KB
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
import React from 'react'
import _ from 'underscore'
import I18n from 'i18n!edit_timezone'
const { array } = React.PropTypes;
class TimeZoneSelect extends React.Component {
containsZone (timezones, zone) {
return (_.find(timezones, (z) => {return z.name === zone.name}));
}
filterTimeZones (timezones, priority_timezones) {
return timezones.filter((zone) => {
return !this.containsZone(priority_timezones, zone);
});
}
renderOptions (timezones) {
return timezones.map((zone) => {
return <option key={zone.name} value={zone.name}>{zone.localized_name}</option>
});
}
render () {
const timeZonesWithoutPriorities = this.filterTimeZones(this.props.timezones, this.props.priority_timezones);
return (
<select {...this.props}>
<optgroup label={I18n.t('Common Timezones')}>
{this.renderOptions(this.props.priority_timezones)}
</optgroup>
<optgroup label={I18n.t('Other Timezones')}>
{this.renderOptions(timeZonesWithoutPriorities)}
</optgroup>
</select>
);
}
}
TimeZoneSelect.propTypes = {
timezones: array.isRequired,
priority_timezones: array.isRequired
};
export default TimeZoneSelect