Skip to content

Commit

Permalink
chore: initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
kptdobe committed Sep 19, 2024
1 parent 5a4aaaf commit 1ef1067
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
40 changes: 27 additions & 13 deletions tools/rum/elements/daterange-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,30 +313,44 @@ 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();

[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');
Expand Down
15 changes: 1 addition & 14 deletions tools/rum/slicer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 1ef1067

Please sign in to comment.