From e2fb3aa9424967d3e37b155ae217aee160657f1d Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Tue, 4 Dec 2018 11:05:16 +0100 Subject: [PATCH] re-add today view to date presets (1d) --- assets/src/js/components/DatePicker.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/assets/src/js/components/DatePicker.js b/assets/src/js/components/DatePicker.js index 2ad8f365..a9ef6abb 100644 --- a/assets/src/js/components/DatePicker.js +++ b/assets/src/js/components/DatePicker.js @@ -13,8 +13,16 @@ window.setInterval(() => { now = new Date(); }, 60000 ); -// today, yesterday, this week, last 7 days, last 30 days const availablePeriods = { + '1d': { + label: '1d', + start: function() { + return new Date(now.getFullYear(), now.getMonth(), now.getDate()); + }, + end: function() { + return this.start(); + }, + }, '1w': { label: '1w', start: function() { @@ -116,7 +124,12 @@ class DatePicker extends Component { end.setHours(23, 59, 59); let diff = Math.round((end - start) / 1000 / 60 / 60 / 24) - let groupBy = diff >= 31 ? 'month' : 'day'; + let groupBy = 'day'; + if(diff >= 31) { + groupBy = 'month'; + } else if( diff < 2) { + groupBy = 'hour'; + } this.setState({ period: period || '',