diff --git a/tools/rum/elements/daterange-picker.js b/tools/rum/elements/daterange-picker.js index 348abd75..56a8cf84 100644 --- a/tools/rum/elements/daterange-picker.js +++ b/tools/rum/elements/daterange-picker.js @@ -313,7 +313,8 @@ export default class TimeRangePicker extends HTMLElement { })); } - updateTimeframe({ value, to = null }) { + updateTimeframe({ value }) { + // maintain the readonly state of the date fields and default value const { fromElement, toElement } = this; const now = new Date(); @@ -321,22 +322,35 @@ export default class TimeRangePicker extends HTMLElement { [fromElement, toElement].forEach((field) => { field.readOnly = true; }); - if (!to) { - toElement.value = toDateString(now); - } this.toggleCustomTimeframe(value === 'custom'); + if (value === 'week') { - const lastWeek = now; - lastWeek.setHours(7 * 24, 0, 0, 0); - fromElement.value = toDateString(lastWeek); + if (!fromElement.value) { + const lastWeek = now; + lastWeek.setHours(7 * 24, 0, 0, 0); + fromElement.value = toDateString(lastWeek); + } + if (!toElement.value) { + toElement.value = toDateString(now); + } } else if (value === 'month') { - const lastMonth = now; - lastMonth.setMonth(now.getMonth() - 1); - fromElement.value = toDateString(lastMonth); + if (!fromElement.value) { + const lastMonth = now; + lastMonth.setMonth(now.getMonth() - 1); + fromElement.value = toDateString(lastMonth); + } + if (!toElement.value) { + toElement.value = toDateString(now); + } } else if (value === 'year') { - const lastYear = now; - lastYear.setFullYear(now.getFullYear() - 1); - fromElement.value = toDateString(lastYear); + if (!fromElement.value) { + const lastYear = now; + lastYear.setFullYear(now.getFullYear() - 1); + fromElement.value = toDateString(lastYear); + } + if (!toElement.value) { + toElement.value = toDateString(now); + } } else if (value === 'custom') { [fromElement, toElement].forEach((field) => { field.removeAttribute('readonly'); diff --git a/tools/rum/slicer.js b/tools/rum/slicer.js index 2dae8d8f..3b59f1a6 100644 --- a/tools/rum/slicer.js +++ b/tools/rum/slicer.js @@ -351,22 +351,9 @@ const io = new IntersectionObserver((entries) => { window.history.replaceState({}, '', url); } - let startDate = params.get('startDate') ? `${params.get('startDate')}` : null; + const startDate = params.get('startDate') ? `${params.get('startDate')}` : null; const endDate = params.get('endDate') ? `${params.get('endDate')}` : null; - if (startDate || endDate) { - const start = new Date(startDate); - const end = new Date(endDate); - if (start > end) { - start.setTime(end.getTime() - 1000 * 60 * 60 * 24); - startDate = start.toISOString(); - params.set('startDate', startDate); - const url = new URL(window.location.href); - url.search = params.toString(); - window.history.replaceState({}, '', url); - } - } - elems.incognito.addEventListener('change', async () => { loader.domainKey = elems.incognito.getAttribute('domainkey');