Skip to content

Commit 5021ed9

Browse files
authored
Merge pull request #74 from back4app/improve-analytics-features
Improve analytics features
2 parents 14a0c82 + 707d71b commit 5021ed9

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ export default class Performance extends DashboardView {
185185
<DateRange
186186
value={this.state.dateRange}
187187
onChange={(newValue) => (this.setState({ dateRange: newValue, mutated: true }))}
188-
align={Directions.RIGHT} />
188+
align={Directions.RIGHT}
189+
maxRange={30} />
189190
</span>
190191
<Button
191192
primary={true}
@@ -235,7 +236,8 @@ export default class Performance extends DashboardView {
235236
<Chart
236237
width={this.displaySize.width}
237238
height={this.displaySize.height}
238-
data={chartData} />
239+
data={chartData}
240+
formatter={(value) => value + ' requests/min'}/>
239241
);
240242
}
241243

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)