From 2f02b69e636401108da8183c261783bb04df660b Mon Sep 17 00:00:00 2001 From: arefabouhamdan Date: Tue, 5 Aug 2025 00:11:13 +0300 Subject: [PATCH 01/12] Added today as a default value, added future and old dates based on data, added yesterday and today presets for date range, fixed presets start and end date --- .../atoms/inputs/date-input/DateInput.svelte | 2 + .../atoms/inputs/date-input/_DateInput.svelte | 129 ++++++++++++------ .../lib/atoms/shadcn/calendar/calendar.svelte | 48 +++++-- .../range-calendar/range-calendar.svelte | 48 +++++-- 4 files changed, 173 insertions(+), 54 deletions(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte index 3b1b9a8a97..8768100322 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte @@ -155,6 +155,8 @@ {currentDate} {title} {description} + {data} + {dates} /> {/if} diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte index 4c30d94a75..67e28dfa3e 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte @@ -6,7 +6,8 @@ startOfMonth, endOfMonth, startOfYear, - endOfYear + endOfYear, + today } from '@internationalized/date'; import { cn } from '$lib/utils.js'; import { Button } from '$lib/atoms/shadcn/button/index.js'; @@ -33,9 +34,15 @@ dateStyle: 'short' }); + const todayDate = today(getLocalTimeZone()); + /** @type {import('bits-ui').DateRange | undefined} */ let selectedDateInput = undefined; + $: referenceDate = selectedDateInput && !range ? selectedDateInput : selectedDateInput + && + selectedDateInput.end ? selectedDateInput.end : todayDate; + /** @type {(selectedDateInput: import('bits-ui').DateRange | undefined) => void} */ export let onSelectedDateInputChange; /** @type {string} */ @@ -55,111 +62,152 @@ export let extraDayEndString = undefined; /** @type {string | undefined} */ export let description = undefined; + /** @type {any} */ + export let data = undefined; + /** @type {string | undefined} */ + export let dates = undefined; + + // Extract available years from data if provided + $: extractedYears = (() => { + if (!data || !dates) { + return undefined; + } + + const years = new Set(); + data.rows.forEach(row => { + if (row[dates]) { + const year = new Date(row[dates]).getFullYear(); + years.add(year); + } + }); + + return Array.from(years).sort((a, b) => b - a); + })(); + + $: calendarStart = YYYYMMDDToCalendar(start); + // Use extraDayEndString for safety measures if available, otherwise use regular end + $: calendarEnd = YYYYMMDDToCalendar(extraDayEndString || end); /** @type { { label: string, group: string, range: import('bits-ui').DateRange }[] } */ $: presets = [ + { + label: 'Yesterday', + group: 'Days', + range: { + start: todayDate.subtract({ days: 1 }), + end: todayDate.subtract({ days: 1 }) + } + }, + { + label: 'Today', + group: 'Days', + range: { + start: todayDate, + end: todayDate + } + }, { label: 'Last 7 Days', group: 'Days', range: { - start: calendarEnd.subtract({ days: 6 }), - end: calendarEnd + start: referenceDate.subtract({ days: 6 }), + end: referenceDate } }, { label: 'Last 30 Days', group: 'Days', range: { - start: calendarEnd.subtract({ days: 29 }), - end: calendarEnd + start: referenceDate.subtract({ days: 29 }), + end: referenceDate } }, { label: 'Last 90 Days', group: 'Days', range: { - start: calendarEnd.subtract({ days: 89 }), - end: calendarEnd + start: referenceDate.subtract({ days: 89 }), + end: referenceDate } }, { label: 'Last 365 Days', group: 'Days', range: { - start: calendarEnd.subtract({ days: 364 }), - end: calendarEnd + start: referenceDate.subtract({ days: 364 }), + end: referenceDate } }, { label: 'Last 3 Months', group: 'Months', range: { - start: startOfMonth(calendarEnd.subtract({ months: 3 })), - end: endOfMonth(calendarEnd.subtract({ months: 1 })) + start: startOfMonth(referenceDate.subtract({ months: 3 })), + end: endOfMonth(referenceDate.subtract({ months: 1 })) } }, { label: 'Last 6 Months', group: 'Months', range: { - start: startOfMonth(calendarEnd.subtract({ months: 6 })), - end: endOfMonth(calendarEnd.subtract({ months: 1 })) + start: startOfMonth(referenceDate.subtract({ months: 6 })), + end: endOfMonth(referenceDate.subtract({ months: 1 })) } }, { label: 'Last 12 Months', group: 'Months', range: { - start: startOfMonth(calendarEnd.subtract({ months: 12 })), - end: endOfMonth(calendarEnd.subtract({ months: 1 })) + start: startOfMonth(referenceDate.subtract({ months: 12 })), + end: endOfMonth(referenceDate.subtract({ months: 1 })) } }, { label: 'Last Month', group: 'Last', range: { - start: startOfMonth(calendarEnd.subtract({ months: 1 })), - end: endOfMonth(calendarEnd.subtract({ months: 1 })) + start: startOfMonth(referenceDate.subtract({ months: 1 })), + end: endOfMonth(referenceDate.subtract({ months: 1 })) } }, { label: 'Last Year', group: 'Last', range: { - start: startOfYear(calendarEnd.subtract({ years: 1 })), - end: endOfYear(calendarEnd.subtract({ years: 1 })) + start: startOfYear(referenceDate.subtract({ years: 1 })), + end: endOfYear(referenceDate.subtract({ years: 1 })) } }, { label: 'Month to Date', group: 'To Date', range: { - start: startOfMonth(calendarEnd), - end: endOfMonth(calendarEnd) + start: startOfMonth(referenceDate), + end: endOfMonth(referenceDate) } }, { label: 'Month to Today', group: 'To Date', range: { - start: startOfMonth(calendarEnd), - end: calendarEnd + start: startOfMonth(referenceDate), + end: referenceDate } }, { label: 'Year to Date', group: 'To Date', range: { - start: startOfYear(calendarEnd), - end: endOfYear(calendarEnd) + start: startOfYear(referenceDate), + end: endOfYear(referenceDate) } }, { label: 'Year to Today', group: 'To Date', range: { - start: startOfYear(calendarEnd), - end: calendarEnd + start: startOfYear(referenceDate), + end: referenceDate } }, { @@ -198,7 +246,13 @@ let selectedPreset; let placeholder; - $: setPlaceholderDefault(calendarEnd); + // Set default placeholder to today's date instead of calendarEnd + $: setPlaceholderDefault(todayDate); + + // Initialize with today's date if no selection + $: if (!selectedDateInput) { + selectedDateInput = todayDate; + } // group exists check for nicely rendering group border for dropdown function groupExists(groupName) { @@ -219,7 +273,10 @@ selectedPreset = targetPreset; if (range) { selectedDateInput = targetPreset.range; + } else { + selectedDateInput = targetPreset.range.end; } + onSelectedDateInputChange(selectedDateInput); } $: if ( @@ -230,21 +287,13 @@ ) applyPreset(defaultValue); - $: calendarStart = YYYYMMDDToCalendar(start); - $: calendarEnd = YYYYMMDDToCalendar(end); - - let extraDayCalendarEnd = calendarEnd; - $: if (range) { - extraDayCalendarEnd = YYYYMMDDToCalendar(extraDayEndString); - } - function updateDateRange(start, end) { if (selectedPreset) return; if (range) { selectedDateInput = { start, end }; } else { - selectedDateInput = start; + selectedDateInput = selectedDateInput; } } $: updateDateRange(calendarStart, calendarEnd); @@ -326,7 +375,9 @@ selectedDateInput = value; }} minValue={calendarStart} - maxValue={extraDayCalendarEnd} + maxValue={calendarEnd} + defaultValue={todayDate} + availableYears={extractedYears} /> {:else} {/if} diff --git a/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte b/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte index 04c8e9090f..27105df650 100644 --- a/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte +++ b/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte @@ -34,6 +34,8 @@ let minValue = undefined; /** @type {CalendarDate | undefined} */ let maxValue = undefined; + /** @type {number[] | undefined} */ + let availableYears = undefined; /** @type {string | undefined | null} */ let className = undefined; @@ -57,10 +59,15 @@ month: 'long' }); - $: yearOptions = Array.from({ length: 100 }, (_, i) => ({ - label: String(new Date().getFullYear() - i), - value: new Date().getFullYear() - i - })).filter(({ value }) => !(minValue?.year > value || value > maxValue?.year)); + // Create year options based on available years from data + $: yearOptions = (() => { + if (availableYears?.length > 0) { + return availableYears + .sort((a, b) => b - a) + .map(year => ({ label: String(year), value: year })) + .filter(({ value }) => !(minValue?.year > value || value > maxValue?.year)); + } + })(); $: defaultYear = placeholder ? { value: placeholder.year, label: String(placeholder.year) } @@ -78,7 +85,8 @@ startValue, selectedDateInput, minValue, - maxValue + maxValue, + availableYears, }; @@ -126,9 +134,33 @@ selected={defaultYear} items={yearOptions} onSelectedChange={(v) => { - if (!v || !placeholder) return; - if (v.value === placeholder?.year) return; - placeholder = placeholder.set({ year: v.value }); + if (!v || !placeholder || v.value === placeholder?.year) return; + + const newYear = v.value; + const currentMonth = placeholder.month; + + // First, try to keep the same month in the new year + const sameMonthDate = placeholder.set({ year: newYear, month: currentMonth }); + if ((!minValue || sameMonthDate.compare(minValue) >= 0) && + (!maxValue || sameMonthDate.compare(maxValue) <= 0)) { + placeholder = sameMonthDate; + return; + } + + // If the same month is not available, find the closest valid month + const isBeyondRange = maxValue && sameMonthDate.compare(maxValue) > 0; + const startMonth = isBeyondRange ? 12 : 1; + const endMonth = isBeyondRange ? 0 : 13; + const step = isBeyondRange ? -1 : 1; + + for (let month = startMonth; month !== endMonth; month += step) { + const testDate = placeholder.set({ year: newYear, month }); + if ((!minValue || testDate.compare(minValue) >= 0) && + (!maxValue || testDate.compare(maxValue) <= 0)) { + placeholder = testDate; + break; + } + } }} > ({ - label: String(new Date().getFullYear() - i), - value: new Date().getFullYear() - i - })).filter(({ value }) => !(minValue?.year > value || value > maxValue?.year)); + // Create year options based on available years from data, with fallback to default range + $: yearOptions = (() => { + if (availableYears?.length > 0) { + return availableYears + .sort((a, b) => b - a) + .map(year => ({ label: String(year), value: year })) + .filter(({ value }) => !(minValue?.year > value || value > maxValue?.year)); + } + })(); $: defaultYear = placeholder ? { value: placeholder.year, label: String(placeholder.year) } @@ -68,7 +75,8 @@ startValue, selectedDateInput, minValue, - maxValue + maxValue, + availableYears, }; @@ -116,9 +124,33 @@ selected={defaultYear} items={yearOptions} onSelectedChange={(v) => { - if (!v || !placeholder) return; - if (v.value === placeholder?.year) return; - placeholder = placeholder.set({ year: v.value }); + if (!v || !placeholder || v.value === placeholder?.year) return; + + const newYear = v.value; + const currentMonth = placeholder.month; + + // First, try to keep the same month in the new year + const sameMonthDate = placeholder.set({ year: newYear, month: currentMonth }); + if ((!minValue || sameMonthDate.compare(minValue) >= 0) && + (!maxValue || sameMonthDate.compare(maxValue) <= 0)) { + placeholder = sameMonthDate; + return; + } + + // If the same month is not available, find the closest valid month + const isBeyondRange = maxValue && sameMonthDate.compare(maxValue) > 0; + const startMonth = isBeyondRange ? 12 : 1; + const endMonth = isBeyondRange ? 0 : 13; + const step = isBeyondRange ? -1 : 1; + + for (let month = startMonth; month !== endMonth; month += step) { + const testDate = placeholder.set({ year: newYear, month }); + if ((!minValue || testDate.compare(minValue) >= 0) && + (!maxValue || testDate.compare(maxValue) <= 0)) { + placeholder = testDate; + break; + } + } }} > Date: Wed, 6 Aug 2025 01:06:30 +0300 Subject: [PATCH 02/12] Fixed default value --- .../atoms/inputs/date-input/_DateInput.svelte | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte index 67e28dfa3e..dda939fb36 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte @@ -249,9 +249,26 @@ // Set default placeholder to today's date instead of calendarEnd $: setPlaceholderDefault(todayDate); - // Initialize with today's date if no selection - $: if (!selectedDateInput) { - selectedDateInput = todayDate; + $: if ( + typeof defaultValue === 'string' && + !selectedPreset && + presets.length + ) { + applyPreset(defaultValue); + } + + // Initialize with default value or today's date if no selection and no default value applied + $: if (!selectedDateInput && !selectedPreset) { + if (defaultValue && typeof defaultValue === 'string') { + try { + const defaultDate = YYYYMMDDToCalendar(defaultValue); + selectedDateInput = defaultDate; + } catch (error) { + selectedDateInput = todayDate; + } + } else { + selectedDateInput = todayDate; + } } // group exists check for nicely rendering group border for dropdown @@ -279,14 +296,6 @@ onSelectedDateInputChange(selectedDateInput); } - $: if ( - typeof defaultValue === 'string' && - !selectedDateInput && - !selectedPreset && - presets.length - ) - applyPreset(defaultValue); - function updateDateRange(start, end) { if (selectedPreset) return; From 8b14829db15fa1aede53cc3bbb9034331d056828 Mon Sep 17 00:00:00 2001 From: arefabouhamdan Date: Wed, 6 Aug 2025 17:25:37 +0300 Subject: [PATCH 03/12] Fixed month to today, year to today presets --- .../src/lib/atoms/inputs/date-input/_DateInput.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte index dda939fb36..136b78cc2b 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte @@ -191,7 +191,7 @@ group: 'To Date', range: { start: startOfMonth(referenceDate), - end: referenceDate + end: todayDate } }, { @@ -207,7 +207,7 @@ group: 'To Date', range: { start: startOfYear(referenceDate), - end: referenceDate + end: todayDate } }, { From 8befffdda9d2f3d13be781ebeaa05eec1ac80227 Mon Sep 17 00:00:00 2001 From: arefabouhamdan Date: Wed, 13 Aug 2025 22:18:01 +0300 Subject: [PATCH 04/12] Fixed saftey date --- .../src/lib/atoms/inputs/date-input/DateInput.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte index 8768100322..144f51f961 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte @@ -82,7 +82,7 @@ let extraDayEndString; - $: if (endString && range) { + $: if (endString) { extraDayEndString = new Date(endString); extraDayEndString.setDate(extraDayEndString.getDate() + 1); extraDayEndString = formatDateString(extraDayEndString); From 7870a48bb0e1c4baf1554cd186002f563c05018a Mon Sep 17 00:00:00 2001 From: arefabouhamdan Date: Thu, 25 Sep 2025 23:52:37 +0300 Subject: [PATCH 05/12] Fixed timezone issue --- .../src/lib/atoms/inputs/date-input/helpers.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/helpers.js b/packages/ui/core-components/src/lib/atoms/inputs/date-input/helpers.js index 302f3a74e1..d912f461e9 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/helpers.js +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/helpers.js @@ -1,7 +1,10 @@ const YYYYMMDD = /^\d{4}-\d{2}-\d{2}$/; function dateToYYYYMMDD(date) { - return date.toISOString().split('T')[0]; + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; } function formatDateString(date) { From 6a9afc2203d4347110ea0fc4dd88a673be72620c Mon Sep 17 00:00:00 2001 From: arefabouhamdan Date: Fri, 26 Sep 2025 00:00:35 +0300 Subject: [PATCH 06/12] Changes after format --- .../atoms/inputs/date-input/_DateInput.svelte | 25 +++++++++---------- .../lib/atoms/shadcn/calendar/calendar.svelte | 24 ++++++++++-------- .../range-calendar/range-calendar.svelte | 24 ++++++++++-------- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte index 136b78cc2b..ec3982deda 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte @@ -39,9 +39,12 @@ /** @type {import('bits-ui').DateRange | undefined} */ let selectedDateInput = undefined; - $: referenceDate = selectedDateInput && !range ? selectedDateInput : selectedDateInput - && - selectedDateInput.end ? selectedDateInput.end : todayDate; + $: referenceDate = + selectedDateInput && !range + ? selectedDateInput + : selectedDateInput && selectedDateInput.end + ? selectedDateInput.end + : todayDate; /** @type {(selectedDateInput: import('bits-ui').DateRange | undefined) => void} */ export let onSelectedDateInputChange; @@ -72,15 +75,15 @@ if (!data || !dates) { return undefined; } - + const years = new Set(); - data.rows.forEach(row => { + data.rows.forEach((row) => { if (row[dates]) { const year = new Date(row[dates]).getFullYear(); years.add(year); } }); - + return Array.from(years).sort((a, b) => b - a); })(); @@ -248,15 +251,11 @@ let placeholder; // Set default placeholder to today's date instead of calendarEnd $: setPlaceholderDefault(todayDate); - - $: if ( - typeof defaultValue === 'string' && - !selectedPreset && - presets.length - ) { + + $: if (typeof defaultValue === 'string' && !selectedPreset && presets.length) { applyPreset(defaultValue); } - + // Initialize with default value or today's date if no selection and no default value applied $: if (!selectedDateInput && !selectedPreset) { if (defaultValue && typeof defaultValue === 'string') { diff --git a/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte b/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte index 27105df650..93da292fb7 100644 --- a/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte +++ b/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte @@ -64,7 +64,7 @@ if (availableYears?.length > 0) { return availableYears .sort((a, b) => b - a) - .map(year => ({ label: String(year), value: year })) + .map((year) => ({ label: String(year), value: year })) .filter(({ value }) => !(minValue?.year > value || value > maxValue?.year)); } })(); @@ -86,7 +86,7 @@ selectedDateInput, minValue, maxValue, - availableYears, + availableYears }; @@ -135,28 +135,32 @@ items={yearOptions} onSelectedChange={(v) => { if (!v || !placeholder || v.value === placeholder?.year) return; - + const newYear = v.value; const currentMonth = placeholder.month; - + // First, try to keep the same month in the new year const sameMonthDate = placeholder.set({ year: newYear, month: currentMonth }); - if ((!minValue || sameMonthDate.compare(minValue) >= 0) && - (!maxValue || sameMonthDate.compare(maxValue) <= 0)) { + if ( + (!minValue || sameMonthDate.compare(minValue) >= 0) && + (!maxValue || sameMonthDate.compare(maxValue) <= 0) + ) { placeholder = sameMonthDate; return; } - + // If the same month is not available, find the closest valid month const isBeyondRange = maxValue && sameMonthDate.compare(maxValue) > 0; const startMonth = isBeyondRange ? 12 : 1; const endMonth = isBeyondRange ? 0 : 13; const step = isBeyondRange ? -1 : 1; - + for (let month = startMonth; month !== endMonth; month += step) { const testDate = placeholder.set({ year: newYear, month }); - if ((!minValue || testDate.compare(minValue) >= 0) && - (!maxValue || testDate.compare(maxValue) <= 0)) { + if ( + (!minValue || testDate.compare(minValue) >= 0) && + (!maxValue || testDate.compare(maxValue) <= 0) + ) { placeholder = testDate; break; } diff --git a/packages/ui/core-components/src/lib/atoms/shadcn/range-calendar/range-calendar.svelte b/packages/ui/core-components/src/lib/atoms/shadcn/range-calendar/range-calendar.svelte index 3744bd20d1..51cd0ef91b 100644 --- a/packages/ui/core-components/src/lib/atoms/shadcn/range-calendar/range-calendar.svelte +++ b/packages/ui/core-components/src/lib/atoms/shadcn/range-calendar/range-calendar.svelte @@ -54,7 +54,7 @@ if (availableYears?.length > 0) { return availableYears .sort((a, b) => b - a) - .map(year => ({ label: String(year), value: year })) + .map((year) => ({ label: String(year), value: year })) .filter(({ value }) => !(minValue?.year > value || value > maxValue?.year)); } })(); @@ -76,7 +76,7 @@ selectedDateInput, minValue, maxValue, - availableYears, + availableYears }; @@ -125,28 +125,32 @@ items={yearOptions} onSelectedChange={(v) => { if (!v || !placeholder || v.value === placeholder?.year) return; - + const newYear = v.value; const currentMonth = placeholder.month; - + // First, try to keep the same month in the new year const sameMonthDate = placeholder.set({ year: newYear, month: currentMonth }); - if ((!minValue || sameMonthDate.compare(minValue) >= 0) && - (!maxValue || sameMonthDate.compare(maxValue) <= 0)) { + if ( + (!minValue || sameMonthDate.compare(minValue) >= 0) && + (!maxValue || sameMonthDate.compare(maxValue) <= 0) + ) { placeholder = sameMonthDate; return; } - + // If the same month is not available, find the closest valid month const isBeyondRange = maxValue && sameMonthDate.compare(maxValue) > 0; const startMonth = isBeyondRange ? 12 : 1; const endMonth = isBeyondRange ? 0 : 13; const step = isBeyondRange ? -1 : 1; - + for (let month = startMonth; month !== endMonth; month += step) { const testDate = placeholder.set({ year: newYear, month }); - if ((!minValue || testDate.compare(minValue) >= 0) && - (!maxValue || testDate.compare(maxValue) <= 0)) { + if ( + (!minValue || testDate.compare(minValue) >= 0) && + (!maxValue || testDate.compare(maxValue) <= 0) + ) { placeholder = testDate; break; } From 6202ac763273738815c31457c9ae530b8cc28474 Mon Sep 17 00:00:00 2001 From: arefabouhamdan Date: Fri, 26 Sep 2025 00:34:23 +0300 Subject: [PATCH 07/12] Added changeset --- .changeset/funny-planes-smile.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changeset/funny-planes-smile.md diff --git a/.changeset/funny-planes-smile.md b/.changeset/funny-planes-smile.md new file mode 100644 index 0000000000..fc09dd2730 --- /dev/null +++ b/.changeset/funny-planes-smile.md @@ -0,0 +1,9 @@ +--- +'@evidence-dev/core-components': major +--- + +- Timezone Fixes +- Changed the default value to today +- Year select only shows the first and last date in the data +- Disabled dates that are before or after the first and last date +- Added Today and Yesterday range presets \ No newline at end of file From c53918bec92fae65be2f077f3009b3c965c02a0b Mon Sep 17 00:00:00 2001 From: Aref Abou Hamdan Date: Wed, 12 Nov 2025 13:37:04 +0200 Subject: [PATCH 08/12] Fixed start and end date issues and yearOptions issues --- .../atoms/inputs/date-input/DateInput.svelte | 3 --- .../atoms/inputs/date-input/_DateInput.svelte | 16 +++++++------- .../lib/atoms/shadcn/calendar/calendar.svelte | 20 +++++++++++++----- .../range-calendar/range-calendar.svelte | 21 ++++++++++++++----- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte index 144f51f961..f7c7928413 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte @@ -78,8 +78,6 @@ $: startString = formatDateString(start || $query?.[0].start || new Date(0)); $: endString = formatDateString(end || $query?.[0].end || new Date()); - let currentDate = dateToYYYYMMDD(new Date()); - let extraDayEndString; $: if (endString) { @@ -152,7 +150,6 @@ {presetRanges} {defaultValue} {range} - {currentDate} {title} {description} {data} diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte index ec3982deda..236d38ddc4 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte @@ -49,19 +49,19 @@ /** @type {(selectedDateInput: import('bits-ui').DateRange | undefined) => void} */ export let onSelectedDateInputChange; /** @type {string} */ - export let start; + export let start = undefined; /** @type {string} */ - export let end; + export let end = undefined; export let loaded = true; /** @type {[]string] | undefined} */ - export let presetRanges; + export let presetRanges = undefined; /** @type {string] | undefined} */ - export let defaultValue; + export let defaultValue = undefined; /** @type {boolean} */ export let range = false; $: range = toBoolean(range); /** @type {string} */ - export let title; + export let title = undefined; export let extraDayEndString = undefined; /** @type {string | undefined} */ export let description = undefined; @@ -72,7 +72,7 @@ // Extract available years from data if provided $: extractedYears = (() => { - if (!data || !dates) { + if (!data || !dates || !data.rows) { return undefined; } @@ -87,9 +87,9 @@ return Array.from(years).sort((a, b) => b - a); })(); - $: calendarStart = YYYYMMDDToCalendar(start); + $: calendarStart = start ? YYYYMMDDToCalendar(start) : todayDate.subtract({ years: 10 }); // Use extraDayEndString for safety measures if available, otherwise use regular end - $: calendarEnd = YYYYMMDDToCalendar(extraDayEndString || end); + $: calendarEnd = (extraDayEndString || end) ? YYYYMMDDToCalendar(extraDayEndString || end) : todayDate; /** @type { { label: string, group: string, range: import('bits-ui').DateRange }[] } */ $: presets = [ diff --git a/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte b/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte index 93da292fb7..ab120c5bc2 100644 --- a/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte +++ b/packages/ui/core-components/src/lib/atoms/shadcn/calendar/calendar.svelte @@ -67,6 +67,14 @@ .map((year) => ({ label: String(year), value: year })) .filter(({ value }) => !(minValue?.year > value || value > maxValue?.year)); } + if (minValue && maxValue) { + const years = []; + for (let year = maxValue.year; year >= minValue.year; year--) { + years.push({ label: String(year), value: year }); + } + return years; + } + return undefined; })(); $: defaultYear = placeholder @@ -174,11 +182,13 @@ - {#each yearOptions as { value, label }} - - {label} - - {/each} + {#if yearOptions && yearOptions.length > 0} + {#each yearOptions as { value, label }} + + {label} + + {/each} + {/if} diff --git a/packages/ui/core-components/src/lib/atoms/shadcn/range-calendar/range-calendar.svelte b/packages/ui/core-components/src/lib/atoms/shadcn/range-calendar/range-calendar.svelte index 51cd0ef91b..c0451c810b 100644 --- a/packages/ui/core-components/src/lib/atoms/shadcn/range-calendar/range-calendar.svelte +++ b/packages/ui/core-components/src/lib/atoms/shadcn/range-calendar/range-calendar.svelte @@ -57,6 +57,15 @@ .map((year) => ({ label: String(year), value: year })) .filter(({ value }) => !(minValue?.year > value || value > maxValue?.year)); } + + if (minValue && maxValue) { + const years = []; + for (let year = maxValue.year; year >= minValue.year; year--) { + years.push({ label: String(year), value: year }); + } + return years; + } + return undefined; })(); $: defaultYear = placeholder @@ -164,11 +173,13 @@ - {#each yearOptions as { value, label }} - - {label} - - {/each} + {#if yearOptions && yearOptions.length > 0} + {#each yearOptions as { value, label }} + + {label} + + {/each} + {/if} From d0a303f70f7de0458452577cde040a1dd2a6ebab Mon Sep 17 00:00:00 2001 From: Aref Abou Hamdan Date: Wed, 12 Nov 2025 14:36:28 +0200 Subject: [PATCH 09/12] Changed the reference date to be the end date or start date if today's date is not available --- .../atoms/inputs/date-input/_DateInput.svelte | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte index 236d38ddc4..8e5a0b9533 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte @@ -39,12 +39,22 @@ /** @type {import('bits-ui').DateRange | undefined} */ let selectedDateInput = undefined; - $: referenceDate = - selectedDateInput && !range - ? selectedDateInput - : selectedDateInput && selectedDateInput.end - ? selectedDateInput.end - : todayDate; + $: referenceDate = (() => { + if (selectedDateInput && !range) { + return selectedDateInput; + } + if (selectedDateInput && selectedDateInput.end) { + return selectedDateInput.end; + } + // If today is outside the data range, use calendarEnd as reference for presets + if (calendarEnd && todayDate.compare(calendarEnd) > 0) { + return calendarEnd; + } + if (calendarStart && todayDate.compare(calendarStart) < 0) { + return calendarStart; + } + return todayDate; + })(); /** @type {(selectedDateInput: import('bits-ui').DateRange | undefined) => void} */ export let onSelectedDateInputChange; @@ -249,24 +259,49 @@ let selectedPreset; let placeholder; - // Set default placeholder to today's date instead of calendarEnd - $: setPlaceholderDefault(todayDate); + // Set default placeholder: use calendarEnd if today is beyond the data range, otherwise use today + $: { + if (calendarEnd && todayDate.compare(calendarEnd) > 0) { + // If today is after the end of the data range, open to the end date + setPlaceholderDefault(calendarEnd); + } else if (calendarStart && todayDate.compare(calendarStart) < 0) { + // If today is before the start of the data range, open to the start date + setPlaceholderDefault(calendarStart); + } else { + // Otherwise, open to today + setPlaceholderDefault(todayDate); + } + } $: if (typeof defaultValue === 'string' && !selectedPreset && presets.length) { applyPreset(defaultValue); } - // Initialize with default value or today's date if no selection and no default value applied + // Initialize with default value or a sensible date if no selection and no default value applied $: if (!selectedDateInput && !selectedPreset) { if (defaultValue && typeof defaultValue === 'string') { try { const defaultDate = YYYYMMDDToCalendar(defaultValue); selectedDateInput = defaultDate; } catch (error) { - selectedDateInput = todayDate; + // If today is outside the data range, use calendarEnd, otherwise use today + if (calendarEnd && todayDate.compare(calendarEnd) > 0) { + selectedDateInput = calendarEnd; + } else if (calendarStart && todayDate.compare(calendarStart) < 0) { + selectedDateInput = calendarStart; + } else { + selectedDateInput = todayDate; + } } } else { - selectedDateInput = todayDate; + // If today is outside the data range, use calendarEnd, otherwise use today + if (calendarEnd && todayDate.compare(calendarEnd) > 0) { + selectedDateInput = calendarEnd; + } else if (calendarStart && todayDate.compare(calendarStart) < 0) { + selectedDateInput = calendarStart; + } else { + selectedDateInput = todayDate; + } } } From da9f9079d8aa336f4a49be63116681fea9041f20 Mon Sep 17 00:00:00 2001 From: Aref Abou Hamdan Date: Fri, 14 Nov 2025 20:14:40 +0200 Subject: [PATCH 10/12] Changes after second format --- .../src/lib/atoms/inputs/date-input/_DateInput.svelte | 3 ++- .../src/lib/atoms/inputs/dropdown/Dropdown.svelte | 2 +- .../src/lib/unsorted/viz/core/_Sparkline.svelte | 2 +- .../src/lib/unsorted/viz/heatmap/_Heatmap.svelte | 2 +- .../ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte | 2 +- .../src/lib/unsorted/viz/map/components/Areas.svelte | 4 ++-- .../viz/references/ReferenceArea/ReferenceArea.svelte | 4 ++-- .../viz/references/ReferenceLine/ReferenceLine.svelte | 4 ++-- .../viz/references/ReferencePoint/ReferencePoint.svelte | 4 ++-- .../core-components/src/lib/unsorted/viz/table/Column.svelte | 2 +- .../src/lib/unsorted/viz/venn/VennDiagram.svelte | 4 ++-- 11 files changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte index 8e5a0b9533..b76b1b91df 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte @@ -99,7 +99,8 @@ $: calendarStart = start ? YYYYMMDDToCalendar(start) : todayDate.subtract({ years: 10 }); // Use extraDayEndString for safety measures if available, otherwise use regular end - $: calendarEnd = (extraDayEndString || end) ? YYYYMMDDToCalendar(extraDayEndString || end) : todayDate; + $: calendarEnd = + extraDayEndString || end ? YYYYMMDDToCalendar(extraDayEndString || end) : todayDate; /** @type { { label: string, group: string, range: import('bits-ui').DateRange }[] } */ $: presets = [ diff --git a/packages/ui/core-components/src/lib/atoms/inputs/dropdown/Dropdown.svelte b/packages/ui/core-components/src/lib/atoms/inputs/dropdown/Dropdown.svelte index e98cca41f7..4f200df55d 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/dropdown/Dropdown.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/dropdown/Dropdown.svelte @@ -207,7 +207,7 @@ finalQuery = query ?? data; } }, 100); - $: (search, data, query, updateQuery()); + $: search, data, query, updateQuery(); $: open ? pauseSorting() : resumeSorting(); diff --git a/packages/ui/core-components/src/lib/unsorted/viz/core/_Sparkline.svelte b/packages/ui/core-components/src/lib/unsorted/viz/core/_Sparkline.svelte index 10db89655b..d59ba8b009 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/core/_Sparkline.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/core/_Sparkline.svelte @@ -145,7 +145,7 @@ } } - $: (data, config); + $: data, config; $: if (browser && chartInstance && config) { chartInstance.setOption(config, true); // true forces a complete replacement of the options diff --git a/packages/ui/core-components/src/lib/unsorted/viz/heatmap/_Heatmap.svelte b/packages/ui/core-components/src/lib/unsorted/viz/heatmap/_Heatmap.svelte index c0e04da410..295ec31d63 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/heatmap/_Heatmap.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/heatmap/_Heatmap.svelte @@ -352,7 +352,7 @@ } } - $: (data, height, config); + $: data, height, config; {#if error} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte b/packages/ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte index 2ab70385c8..f487d5c444 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte @@ -282,7 +282,7 @@ } } - $: (data, config); + $: data, config; {#if !error} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/map/components/Areas.svelte b/packages/ui/core-components/src/lib/unsorted/viz/map/components/Areas.svelte index 70c887532d..a8bf9b6348 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/map/components/Areas.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/map/components/Areas.svelte @@ -298,13 +298,13 @@ } // Re-load areas when related props change - $: (geoJsonUrl, + $: geoJsonUrl, data, areaCol, (async () => { await data.fetch(); await processAreas(); - })()); + })(); diff --git a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceArea/ReferenceArea.svelte b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceArea/ReferenceArea.svelte index ba5c9932ba..494583a9e2 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceArea/ReferenceArea.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceArea/ReferenceArea.svelte @@ -149,7 +149,7 @@ const store = new ReferenceAreaStore(props, config); // React to the props store to make sure the ReferencePoint is added after the chart is fully rendered - $: ($props, + $: $props, store.setConfig({ xMin, xMax, @@ -177,7 +177,7 @@ bold: toBoolean(bold), italic: toBoolean(italic), activeAppearance: $activeAppearance - })); + }); {#if $$slots.default} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceLine/ReferenceLine.svelte b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceLine/ReferenceLine.svelte index 21c91f3e37..fb850f2542 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceLine/ReferenceLine.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceLine/ReferenceLine.svelte @@ -184,7 +184,7 @@ const { theme } = getThemeStores(); // React to the props store to make sure the ReferencePoint is added after the chart is fully rendered - $: ($props, + $: $props, store.setConfig({ x, y, @@ -214,7 +214,7 @@ align, bold: toBoolean(bold), italic: toBoolean(italic) - })); + }); {#if $$slots.default} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferencePoint/ReferencePoint.svelte b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferencePoint/ReferencePoint.svelte index 05374a4978..89d4635916 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferencePoint/ReferencePoint.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferencePoint/ReferencePoint.svelte @@ -162,7 +162,7 @@ const { theme } = getThemeStores(); // React to the props store to make sure the ReferencePoint is added after the chart is fully rendered - $: ($props, + $: $props, store.setConfig({ data, x, @@ -189,7 +189,7 @@ align, bold, italic - })); + }); {#if $$slots.default} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/table/Column.svelte b/packages/ui/core-components/src/lib/unsorted/viz/table/Column.svelte index 683415f9ed..36c1dceaf6 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/table/Column.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/table/Column.svelte @@ -203,7 +203,7 @@ return d; }); }; - $: (options, updateProps()); + $: options, updateProps(); onDestroy(() => { props.update((d) => { diff --git a/packages/ui/core-components/src/lib/unsorted/viz/venn/VennDiagram.svelte b/packages/ui/core-components/src/lib/unsorted/viz/venn/VennDiagram.svelte index 5175730f3d..569a2ffd12 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/venn/VennDiagram.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/venn/VennDiagram.svelte @@ -33,7 +33,7 @@ let intercets; - $: (distanceToLabels, + $: distanceToLabels, (intercets = [ // A only { @@ -62,7 +62,7 @@ y: origin.y - apothem + distanceToLabels, value: overlaps[2]?.toLocaleString('en-GB', { style: 'percent' }) ?? '' } - ])); + ]);
From 9f9c99c743f6c20be88a03d68258925e6f3f1269 Mon Sep 17 00:00:00 2001 From: Aref Abou Hamdan Date: Mon, 1 Dec 2025 17:34:58 +0200 Subject: [PATCH 11/12] Cleaned the code with "npm run lint" --- packages/datasources/duckdb/CHANGELOG.md | 2 -- packages/lib/db-commons/CHANGELOG.md | 2 -- packages/lib/universal-sql/CHANGELOG.md | 2 -- packages/ui/core-components/CHANGELOG.md | 3 --- .../src/lib/atoms/inputs/dropdown/Dropdown.svelte | 2 +- .../src/lib/unsorted/viz/core/_Sparkline.svelte | 2 +- .../src/lib/unsorted/viz/heatmap/_Heatmap.svelte | 2 +- .../ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte | 2 +- .../src/lib/unsorted/viz/map/components/Areas.svelte | 4 ++-- .../viz/references/ReferenceArea/ReferenceArea.svelte | 4 ++-- .../viz/references/ReferenceLine/ReferenceLine.svelte | 4 ++-- .../viz/references/ReferencePoint/ReferencePoint.svelte | 4 ++-- .../core-components/src/lib/unsorted/viz/table/Column.svelte | 2 +- .../src/lib/unsorted/viz/venn/VennDiagram.svelte | 4 ++-- 14 files changed, 15 insertions(+), 24 deletions(-) diff --git a/packages/datasources/duckdb/CHANGELOG.md b/packages/datasources/duckdb/CHANGELOG.md index 248bfc9cb1..8705e96dc9 100644 --- a/packages/datasources/duckdb/CHANGELOG.md +++ b/packages/datasources/duckdb/CHANGELOG.md @@ -5,12 +5,10 @@ ### Major Changes - b28f63f23: Update DuckDB to latest packages: - - Switch to @duckdb/node-api from duckdb-async - Update duckdb-wasm to latest release This release also has small data fixes across several packages: - - Better handling of NULL values when discovering column types - Fix batch processing of parquet files - Fix error with temporary parquet files when reloading data in dev environment diff --git a/packages/lib/db-commons/CHANGELOG.md b/packages/lib/db-commons/CHANGELOG.md index 7fa87e8a85..8a8dbce3ea 100644 --- a/packages/lib/db-commons/CHANGELOG.md +++ b/packages/lib/db-commons/CHANGELOG.md @@ -5,12 +5,10 @@ ### Minor Changes - b28f63f23: Update DuckDB to latest packages: - - Switch to @duckdb/node-api from duckdb-async - Update duckdb-wasm to latest release This release also has small data fixes across several packages: - - Better handling of NULL values when discovering column types - Fix batch processing of parquet files - Fix error with temporary parquet files when reloading data in dev environment diff --git a/packages/lib/universal-sql/CHANGELOG.md b/packages/lib/universal-sql/CHANGELOG.md index 23f7ce5df6..7dbd86bfef 100644 --- a/packages/lib/universal-sql/CHANGELOG.md +++ b/packages/lib/universal-sql/CHANGELOG.md @@ -5,12 +5,10 @@ ### Major Changes - b28f63f23: Update DuckDB to latest packages: - - Switch to @duckdb/node-api from duckdb-async - Update duckdb-wasm to latest release This release also has small data fixes across several packages: - - Better handling of NULL values when discovering column types - Fix batch processing of parquet files - Fix error with temporary parquet files when reloading data in dev environment diff --git a/packages/ui/core-components/CHANGELOG.md b/packages/ui/core-components/CHANGELOG.md index eb71a60d4f..d0bea78e41 100644 --- a/packages/ui/core-components/CHANGELOG.md +++ b/packages/ui/core-components/CHANGELOG.md @@ -5,12 +5,10 @@ ### Minor Changes - b28f63f23: Update DuckDB to latest packages: - - Switch to @duckdb/node-api from duckdb-async - Update duckdb-wasm to latest release This release also has small data fixes across several packages: - - Better handling of NULL values when discovering column types - Fix batch processing of parquet files - Fix error with temporary parquet files when reloading data in dev environment @@ -27,7 +25,6 @@ - 6d2782e64: Fixed base path not being applied to data file (parquet) URLs. This resolves an issue where applications deployed with a base path would fail to load data files, resulting in 404 errors. The fix restores the dependency injection pattern for the `addBasePath` function in `setParquetURLs`, ensuring that base paths are correctly applied to all data requests in both monorepo and published package environments. - - @evidence-dev/component-utilities@4.0.10 - @evidence-dev/tailwind@3.1.1 diff --git a/packages/ui/core-components/src/lib/atoms/inputs/dropdown/Dropdown.svelte b/packages/ui/core-components/src/lib/atoms/inputs/dropdown/Dropdown.svelte index 4f200df55d..e98cca41f7 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/dropdown/Dropdown.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/dropdown/Dropdown.svelte @@ -207,7 +207,7 @@ finalQuery = query ?? data; } }, 100); - $: search, data, query, updateQuery(); + $: (search, data, query, updateQuery()); $: open ? pauseSorting() : resumeSorting(); diff --git a/packages/ui/core-components/src/lib/unsorted/viz/core/_Sparkline.svelte b/packages/ui/core-components/src/lib/unsorted/viz/core/_Sparkline.svelte index d59ba8b009..10db89655b 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/core/_Sparkline.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/core/_Sparkline.svelte @@ -145,7 +145,7 @@ } } - $: data, config; + $: (data, config); $: if (browser && chartInstance && config) { chartInstance.setOption(config, true); // true forces a complete replacement of the options diff --git a/packages/ui/core-components/src/lib/unsorted/viz/heatmap/_Heatmap.svelte b/packages/ui/core-components/src/lib/unsorted/viz/heatmap/_Heatmap.svelte index 295ec31d63..c0e04da410 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/heatmap/_Heatmap.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/heatmap/_Heatmap.svelte @@ -352,7 +352,7 @@ } } - $: data, height, config; + $: (data, height, config); {#if error} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte b/packages/ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte index f487d5c444..2ab70385c8 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/map/_USMap.svelte @@ -282,7 +282,7 @@ } } - $: data, config; + $: (data, config); {#if !error} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/map/components/Areas.svelte b/packages/ui/core-components/src/lib/unsorted/viz/map/components/Areas.svelte index a8bf9b6348..70c887532d 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/map/components/Areas.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/map/components/Areas.svelte @@ -298,13 +298,13 @@ } // Re-load areas when related props change - $: geoJsonUrl, + $: (geoJsonUrl, data, areaCol, (async () => { await data.fetch(); await processAreas(); - })(); + })()); diff --git a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceArea/ReferenceArea.svelte b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceArea/ReferenceArea.svelte index 494583a9e2..ba5c9932ba 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceArea/ReferenceArea.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceArea/ReferenceArea.svelte @@ -149,7 +149,7 @@ const store = new ReferenceAreaStore(props, config); // React to the props store to make sure the ReferencePoint is added after the chart is fully rendered - $: $props, + $: ($props, store.setConfig({ xMin, xMax, @@ -177,7 +177,7 @@ bold: toBoolean(bold), italic: toBoolean(italic), activeAppearance: $activeAppearance - }); + })); {#if $$slots.default} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceLine/ReferenceLine.svelte b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceLine/ReferenceLine.svelte index fb850f2542..21c91f3e37 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceLine/ReferenceLine.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferenceLine/ReferenceLine.svelte @@ -184,7 +184,7 @@ const { theme } = getThemeStores(); // React to the props store to make sure the ReferencePoint is added after the chart is fully rendered - $: $props, + $: ($props, store.setConfig({ x, y, @@ -214,7 +214,7 @@ align, bold: toBoolean(bold), italic: toBoolean(italic) - }); + })); {#if $$slots.default} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferencePoint/ReferencePoint.svelte b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferencePoint/ReferencePoint.svelte index 89d4635916..05374a4978 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/references/ReferencePoint/ReferencePoint.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/references/ReferencePoint/ReferencePoint.svelte @@ -162,7 +162,7 @@ const { theme } = getThemeStores(); // React to the props store to make sure the ReferencePoint is added after the chart is fully rendered - $: $props, + $: ($props, store.setConfig({ data, x, @@ -189,7 +189,7 @@ align, bold, italic - }); + })); {#if $$slots.default} diff --git a/packages/ui/core-components/src/lib/unsorted/viz/table/Column.svelte b/packages/ui/core-components/src/lib/unsorted/viz/table/Column.svelte index 36c1dceaf6..683415f9ed 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/table/Column.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/table/Column.svelte @@ -203,7 +203,7 @@ return d; }); }; - $: options, updateProps(); + $: (options, updateProps()); onDestroy(() => { props.update((d) => { diff --git a/packages/ui/core-components/src/lib/unsorted/viz/venn/VennDiagram.svelte b/packages/ui/core-components/src/lib/unsorted/viz/venn/VennDiagram.svelte index 569a2ffd12..5175730f3d 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/venn/VennDiagram.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/venn/VennDiagram.svelte @@ -33,7 +33,7 @@ let intercets; - $: distanceToLabels, + $: (distanceToLabels, (intercets = [ // A only { @@ -62,7 +62,7 @@ y: origin.y - apothem + distanceToLabels, value: overlaps[2]?.toLocaleString('en-GB', { style: 'percent' }) ?? '' } - ]); + ]));
From a0bf5fd39e73682ef57f872de14f6a1cdd5aaccb Mon Sep 17 00:00:00 2001 From: Aref Abou Hamdan Date: Thu, 26 Feb 2026 22:07:59 +0200 Subject: [PATCH 12/12] Added defaultToToday prop --- .../atoms/inputs/date-input/DateInput.svelte | 3 +++ .../atoms/inputs/date-input/_DateInput.svelte | 23 +++++++++++-------- .../components/inputs/date-input/index.md | 8 ++++++- .../components/inputs/date-range/index.md | 8 ++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte index 755ce60f74..17d39b40d9 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/DateInput.svelte @@ -45,6 +45,8 @@ /** @type {boolean| string} */ export let range = false; $: range = toBoolean(range); + /** @type {boolean | string} */ + export let defaultToToday = false; let query; let errors = []; @@ -149,6 +151,7 @@ loaded={loaded?.ready ?? true} {presetRanges} {defaultValue} + {defaultToToday} {range} {title} {description} diff --git a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte index b76b1b91df..030d13b5bd 100644 --- a/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte +++ b/packages/ui/core-components/src/lib/atoms/inputs/date-input/_DateInput.svelte @@ -70,6 +70,9 @@ /** @type {boolean} */ export let range = false; $: range = toBoolean(range); + /** @type {boolean} */ + export let defaultToToday = false; + $: defaultToToday = toBoolean(defaultToToday); /** @type {string} */ export let title = undefined; export let extraDayEndString = undefined; @@ -278,24 +281,24 @@ applyPreset(defaultValue); } - // Initialize with default value or a sensible date if no selection and no default value applied + // Initialize with default value or today's date (if defaultToToday is enabled) $: if (!selectedDateInput && !selectedPreset) { if (defaultValue && typeof defaultValue === 'string') { try { const defaultDate = YYYYMMDDToCalendar(defaultValue); selectedDateInput = defaultDate; } catch (error) { - // If today is outside the data range, use calendarEnd, otherwise use today - if (calendarEnd && todayDate.compare(calendarEnd) > 0) { - selectedDateInput = calendarEnd; - } else if (calendarStart && todayDate.compare(calendarStart) < 0) { - selectedDateInput = calendarStart; - } else { - selectedDateInput = todayDate; + if (defaultToToday) { + if (calendarEnd && todayDate.compare(calendarEnd) > 0) { + selectedDateInput = calendarEnd; + } else if (calendarStart && todayDate.compare(calendarStart) < 0) { + selectedDateInput = calendarStart; + } else { + selectedDateInput = todayDate; + } } } - } else { - // If today is outside the data range, use calendarEnd, otherwise use today + } else if (defaultToToday) { if (calendarEnd && todayDate.compare(calendarEnd) > 0) { selectedDateInput = calendarEnd; } else if (calendarStart && todayDate.compare(calendarStart) < 0) { diff --git a/sites/docs/pages/components/inputs/date-input/index.md b/sites/docs/pages/components/inputs/date-input/index.md index 8d097affc5..8559678649 100644 --- a/sites/docs/pages/components/inputs/date-input/index.md +++ b/sites/docs/pages/components/inputs/date-input/index.md @@ -293,7 +293,13 @@ Customize "Select a Range" drop down, by including present range options. **Rang Accepts preset in string format to apply default value in Date Input picker. **Range options**: `'Last 7 Days'` `'Last 30 Days'` `'Last 90 Days'` `'Last 3 Months'` `'Last 6 Months'` `'Last 12 Months'` `'Last Month'` `'Last Year'` `'Month to Date'` `'Year to Date'` `'All Time'` - + - +