diff --git a/assets/js/dashboard/datepicker.js b/assets/js/dashboard/datepicker.js index 72fd04278..38957dc20 100644 --- a/assets/js/dashboard/datepicker.js +++ b/assets/js/dashboard/datepicker.js @@ -17,24 +17,37 @@ class DatePicker extends React.Component { document.removeEventListener("keyup", this.handleKeyup); } + queryWithPeriod(period, date) { + const query = new URLSearchParams(window.location.search) + query.set('period', period) + + if (date) { + query.set('date', date) + } else { + query.delete('date') + } + + return query.toString() + } + handleKeyup(e) { const {query, history} = this.props if (e.key === 'ArrowLeft') { if (query.period === 'day') { const prevDate = formatISO(shiftDays(query.date, -1)) - history.push('?period=day&date=' + prevDate) + history.push({search: this.queryWithPeriod('day', prevDate)}) } else if (query.period === 'month') { const prevMonth = formatISO(shiftMonths(query.date, -1)) - history.push('?period=month&date=' + prevMonth) + history.push({search: this.queryWithPeriod('month', prevMonth)}) } } else if (e.key === 'ArrowRight') { if (query.period === 'day') { const nextDate = formatISO(shiftDays(query.date, 1)) - history.push('?period=day&date=' + nextDate) + history.push({search: this.queryWithPeriod('day', nextDate)}) } else if (query.period === 'month') { const nextMonth = formatISO(shiftMonths(query.date, 1)) - history.push('?period=month&date=' + nextMonth) + history.push({search: this.queryWithPeriod('month', nextMonth)}) } } } @@ -64,12 +77,12 @@ class DatePicker extends React.Component { renderArrow(period, prevDate, nextDate) { return (
- + - + @@ -105,11 +118,11 @@ class DatePicker extends React.Component {
- Today - Last 7 days - Last 30 days - Last 3 months - Last 6 months + Today + Last 7 days + Last 30 days + Last 3 months + Last 6 months
) diff --git a/assets/js/dashboard/stats/visitor-graph.js b/assets/js/dashboard/stats/visitor-graph.js index d59beb74a..da230988f 100644 --- a/assets/js/dashboard/stats/visitor-graph.js +++ b/assets/js/dashboard/stats/visitor-graph.js @@ -149,12 +149,17 @@ class LineGraph extends React.Component { } onClick(e) { + const query = new URLSearchParams(window.location.search) const element = this.chart.getElementsAtEventForMode(e, 'index', {intersect: false})[0] const date = element._chart.config.data.labels[element._index] if (this.props.graphData.interval === 'month') { - this.props.history.push('?period=month&date=' + date) + query.set('period', 'month') + query.set('date', date) + this.props.history.push({search: query.toString()}) } else if (this.props.graphData.interval === 'date') { - this.props.history.push('?period=day&date=' + date) + query.set('period', 'day') + query.set('date', date) + this.props.history.push({search: query.toString()}) } }