+
+
(this.lower = r)} />
+
(this.upper = r)} />
+
+
+ Apply
+
)
@@ -78,10 +95,48 @@ class CustomTimeRange extends Component {
const upper = this.upperCal.getDate().toISOString()
onApplyTimeRange({lower, upper})
+
if (onClose) {
onClose()
}
}
+
+ handleTimeRangeShortcut(shortcut) {
+ return () => {
+ let lower
+ const upper = moment()
+
+ switch (shortcut) {
+ case 'pastWeek': {
+ lower = moment().subtract(1, 'week')
+ break
+ }
+ case 'pastMonth': {
+ lower = moment().subtract(1, 'month')
+ break
+ }
+ case 'pastYear': {
+ lower = moment().subtract(1, 'year')
+ break
+ }
+ case 'thisWeek': {
+ lower = moment().startOf('week')
+ break
+ }
+ case 'thisMonth': {
+ lower = moment().startOf('month')
+ break
+ }
+ case 'thisYear': {
+ lower = moment().startOf('year')
+ break
+ }
+ }
+
+ this.lowerCal.setValue(lower)
+ this.upperCal.setValue(upper)
+ }
+ }
}
const {func, shape, string} = PropTypes
diff --git a/ui/src/shared/components/TimeRangeDropdown.js b/ui/src/shared/components/TimeRangeDropdown.js
index 8a46d2964..e55ed4f09 100644
--- a/ui/src/shared/components/TimeRangeDropdown.js
+++ b/ui/src/shared/components/TimeRangeDropdown.js
@@ -85,10 +85,17 @@ class TimeRangeDropdown extends Component {
render() {
const {selected, preventCustomTimeRange} = this.props
const {isOpen, customTimeRange, isCustomTimeRangeOpen} = this.state
+ const isRelativeTimeRange = selected.upper === null
return (
-
+
this.toggleMenu()}
@@ -105,20 +112,25 @@ class TimeRangeDropdown extends Component {
autoHeight={true}
maxHeight={DROPDOWN_MENU_MAX_HEIGHT}
>
-
Time Range
{preventCustomTimeRange
? null
- :
-
- Custom Time Range
-
- }
+ :
}
+
+ {preventCustomTimeRange ? '' : 'Relative '}Time Ranges
+
{timeRanges.map(item => {
return (
diff --git a/ui/src/shared/data/timeRangeShortcuts.hson b/ui/src/shared/data/timeRangeShortcuts.hson
new file mode 100644
index 000000000..97c033602
--- /dev/null
+++ b/ui/src/shared/data/timeRangeShortcuts.hson
@@ -0,0 +1,26 @@
+[
+ {
+ "id": "pastWeek",
+ "name": "Past Week"
+ },
+ {
+ "id": "pastMonth",
+ "name": "Past Month"
+ },
+ {
+ "id": "pastYear",
+ "name": "Past Year"
+ },
+ {
+ "id": "thisWeek",
+ "name": "This Week"
+ },
+ {
+ "id": "thisMonth",
+ "name": "This Month"
+ },
+ {
+ "id": "thisYear",
+ "name": "This Year"
+ }
+]
diff --git a/ui/src/style/components/custom-time-range.scss b/ui/src/style/components/custom-time-range.scss
index 9c866a11c..48f2e924b 100644
--- a/ui/src/style/components/custom-time-range.scss
+++ b/ui/src/style/components/custom-time-range.scss
@@ -9,16 +9,25 @@
.custom-time--container {
display: none;
position: absolute;
- flex-direction: column;
- align-items: center;
+ flex-direction: row;
+ align-items: stretch;
top: 35px;
right: 0;
- background: $g5-pepper;
border-radius: $radius;
- padding: 8px;
z-index: 1000;
box-shadow: 0 2px 5px 0.6px rgba(15, 14, 21, 0.2);
}
+.custom-time--wrap,
+.custom-time--moving-dates {
+ display: flex;
+ flex-direction: column;
+}
+.custom-time--wrap {
+ padding: 8px;
+ align-items: center;
+ border-radius: 0 $radius $radius 0;
+ background: $g5-pepper;
+}
.custom-time--dates {
display: flex;
align-items: flex-start;
@@ -30,6 +39,33 @@
.custom-time--upper {
margin-left: 4px;
}
+.custom-time--shortcuts {
+ @include no-user-select();
+ align-items: stretch;
+ background-color: $g6-smoke;
+ border-radius: $radius 0 0 $radius;
+}
+.custom-time--shortcuts-header {
+ white-space: nowrap;
+ padding: 16px;
+ color: $g15-platinum;
+ font-weight: 700;
+}
+.custom-time--shortcut {
+ white-space: nowrap;
+ padding: 6px 16px;
+ transition:
+ color 0.25s ease,
+ background-color 0.25s ease;
+ color: $g11-sidewalk;
+ font-weight: 500;
+
+ &:hover {
+ cursor: pointer;
+ background-color: $g7-graphite;
+ color: $g17-whisper;
+ }
+}
$custom-time-arrow: 28px;
$rd-cell-size: 30px;
@@ -222,7 +258,7 @@ $rd-cell-size: 30px;
.custom-time--container .btn.custom-time--apply {
margin-top: 8px;
- width: 120px;
+ width: 210px;
}
/* Open State */