2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 import React, {Component} from 'react';
24 import {connect} from 'react-redux';
25 import moment from 'moment-timezone';
27 import Button from 'react-bootstrap/lib/Button.js';
28 import MenuItem from 'react-bootstrap/lib/MenuItem.js';
29 import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js';
30 import Popover from 'react-bootstrap/lib/Popover.js';
32 import DateRange from 'generic-components/dateRange/DateRange.jsx';
33 import {DATE_PICKER_PLACEHOLDER} from 'generic-components/dateRange/DateRangeConstants.js';
34 import DateRangeActions from 'generic-components/dateRange/DateRangeActions.js';
49 } from 'generic-components/dateRangeSelector/DateRangeSelectorConstants.js';
50 import DateRangeSelectorActions from 'generic-components/dateRangeSelector/DateRangeSelectorActions.js';
51 import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx';
53 import i18n from 'utils/i18n/i18n';
55 let currentDayWithTimeZone = moment(new Date()).tz(moment.tz.guess());
56 let mapStateToProps = ({dataIntegrity: {dateRangeSelectorData}}) => {
59 startDate = currentDayWithTimeZone,
60 endDate = currentDayWithTimeZone,
64 } = dateRangeSelectorData;
75 let mapActionToProps = (dispatch) => {
77 onNewDateSelection: (startMoment, endMoment, period) => {
78 let periodChangeAction = DateRangeSelectorActions.onPeriodChange(
79 startMoment, endMoment, period);
80 // notify all listeners that the period has changed
81 dispatch(periodChangeAction);
82 // update the DateRange component with the newly selected dates
83 dispatch(DateRangeActions.onStartDateChange(
84 periodChangeAction.data.dateRange.startDate,
85 periodChangeAction.data.dateRange.endDate));
90 export class DateRangeSelector extends Component {
92 startDate: React.PropTypes.instanceOf(moment),
93 endDate: React.PropTypes.instanceOf(moment),
94 period: React.PropTypes.string,
95 periodErrText: React.PropTypes.string,
96 periodErrSev: React.PropTypes.string
99 newDateSelection(period) {
100 this.props.onNewDateSelection(this.props.startDate, this.props.endDate,
102 this.refs.dateRangePopover.hide();
105 componentDidMount() {
106 let {startDate, endDate, period, onNewDateSelection} = this.props;
107 // whenever the DateRangeSelector is first mounted, want it
108 // initialized to today's date
109 startDate = currentDayWithTimeZone;
110 endDate = currentDayWithTimeZone;
111 onNewDateSelection(startDate, endDate, period);
115 let {period, periodErrSev, periodErrText} = this.props;
116 let displayDateRange = (this.props.startDate).format(
117 DATE_PICKER_PLACEHOLDER) + ' - ' +
118 (this.props.endDate).format(DATE_PICKER_PLACEHOLDER);
120 <div className='dateRangeSelector'>
121 <OverlayTrigger trigger='click' ref='dateRangePopover'
122 placement='bottom' overlay={
123 <Popover id='dateRangeSelectorPopover'>
124 <MenuItem active={period === TODAY ? true : false} onSelect={() =>
125 this.newDateSelection(TODAY)}>{i18n(LABEL_TODAY)}</MenuItem>
126 <MenuItem active={period === YESTERDAY ? true : false} onSelect={() =>
127 this.newDateSelection(YESTERDAY)}>{i18n(LABEL_YESTERDAY)}</MenuItem>
128 <MenuItem active={period === LAST_WEEK ? true : false} onSelect={() =>
129 this.newDateSelection(LAST_WEEK)}>{i18n(LABEL_LAST_WEEK)}</MenuItem>
130 <MenuItem active={period === LAST_MONTH ? true : false} onSelect={() =>
131 this.newDateSelection(LAST_MONTH)}>{i18n(LABEL_LAST_MONTH)}</MenuItem>
132 <OverlayTrigger trigger='click' placement='right' overlay={
133 <Popover id='customSearchPopover'>
134 <InlineMessage level={periodErrSev} messageTxt={periodErrText} />
136 <Button className='dateRangeSearchButton' bsSize='xsmall'
138 disabled={periodErrText !== '' ? true : false}
139 onClick={() => this.newDateSelection(CUSTOM)}>
140 {i18n(SEARCH_BUTTON_TEXT)}
144 <MenuItem active={period === CUSTOM ? true : false} >
145 {i18n(LABEL_CUSTOM_SEARCH)}
149 <Button className='dateRangeSelectorSearchButton' bsStyle='default'>
150 <i className={ICON_CLASS_CALENDAR} aria-hidden='true'></i>
151 <span>{displayDateRange} </span>
152 <i className={ICON_CLASS_DOWN_CARET} aria-hidden='true'></i>
159 export default connect(mapStateToProps, mapActionToProps)(DateRangeSelector);