Skip to content

Commit 707d71b

Browse files
committed
Add maxRange on dateRange
1 parent 06a8fff commit 707d71b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/components/DateRange/DateRange.react.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import Icon from 'components/Icon/Icon.react';
1111
import {
1212
monthDayStringUTC,
1313
monthsFrom,
14-
daysFrom
14+
daysFrom,
15+
daysToMilli
1516
} from 'lib/DateUtils';
1617
import Popover from 'components/Popover/Popover.react';
1718
import Position from 'lib/Position';
@@ -30,7 +31,8 @@ export default class DateRange extends React.Component {
3031
open: false,
3132
position: null,
3233
start: val.start || monthsFrom(new Date(), -1),
33-
end: val.end || new Date()
34+
end: val.end || new Date(),
35+
maxRange: props.maxRange,
3436
};
3537
}
3638

@@ -59,6 +61,7 @@ export default class DateRange extends React.Component {
5961
if (start > end) {
6062
end = daysFrom(start, 1);
6163
}
64+
if (this.state.maxRange && end - start > daysToMilli(this.state.maxRange)) end = daysFrom(start, this.state.maxRange)
6265
this.setState({ start, end });
6366
}
6467

@@ -67,6 +70,7 @@ export default class DateRange extends React.Component {
6770
if (start > end) {
6871
start = daysFrom(end, -1);
6972
}
73+
if (this.state.maxRange && end - start > daysToMilli(this.state.maxRange)) start = daysFrom(end, -this.state.maxRange)
7074
this.setState({ start, end });
7175
}
7276

@@ -143,4 +147,7 @@ DateRange.propTypes = {
143147
align: PropTypes.string.describe(
144148
'The side to align the range selector with. Possible options are Constants.Directions.LEFT or Constants.Directions.RIGHT.'
145149
),
150+
maxRange: PropTypes.number.describe(
151+
'The maximum range in days that can be seted in the date range. If is null, any range can be seted.'
152+
)
146153
};

src/dashboard/Analytics/Performance/Performance.react.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ export default class Performance extends DashboardView {
182182
<DateRange
183183
value={this.state.dateRange}
184184
onChange={(newValue) => (this.setState({ dateRange: newValue, mutated: true }))}
185-
align={Directions.RIGHT} />
185+
align={Directions.RIGHT}
186+
maxRange={30} />
186187
</span>
187188
<Button
188189
primary={true}

src/lib/DateUtils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,8 @@ export function pad(number) {
164164
}
165165
return r;
166166
}
167+
168+
export function daysToMilli(days) {
169+
if (!days) return days
170+
return days * (1000 * 60 * 60 * 24)
171+
}

0 commit comments

Comments
 (0)