🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
feat: Enhance bucket selection and time handling in MainSection components
Bill Yangdca0841807d1
diff --git a/client/src/app/[site]/main/components/MainSection/BucketSelection.tsx b/client/src/app/[site]/main/components/MainSection/BucketSelection.tsxindex 4224d364a..6c3cd1945 100644--- a/client/src/app/[site]/main/components/MainSection/BucketSelection.tsx+++ b/client/src/app/[site]/main/components/MainSection/BucketSelection.tsx@@ -51,6 +51,9 @@ const getOptions = (time: Time) => {if (time.mode === "week") {return (<SelectContent>+ <SelectItem size="sm" value="fifteen_minutes">+ 15 Minutes+ </SelectItem><SelectItem size="sm" value="hour">Hour</SelectItem>@@ -63,6 +66,9 @@ const getOptions = (time: Time) => {if (time.mode === "month") {return (<SelectContent>+ <SelectItem size="sm" value="hour">+ Hour+ </SelectItem><SelectItem size="sm" value="day">Day</SelectItem>@@ -96,6 +102,21 @@ const getOptions = (time: Time) => {return (<SelectContent>+ {timeRangeLength <= 7 && (+ <SelectItem size="sm" value="five_minutes">+ 5 Minutes+ </SelectItem>+ )}+ {timeRangeLength <= 14 && (+ <>+ <SelectItem size="sm" value="ten_minutes">+ 10 Minutes+ </SelectItem>+ <SelectItem size="sm" value="fifteen_minutes">+ 15 Minutes+ </SelectItem>+ </>+ )}{timeRangeLength <= 30 && (<SelectItem size="sm" value="hour">Hourdiff --git a/client/src/app/[site]/main/components/MainSection/Chart.tsx b/client/src/app/[site]/main/components/MainSection/Chart.tsxindex be52e56ee..ea72b3abf 100644--- a/client/src/app/[site]/main/components/MainSection/Chart.tsx+++ b/client/src/app/[site]/main/components/MainSection/Chart.tsx@@ -19,48 +19,62 @@ export const formatter = Intl.NumberFormat("en", { notation: "compact" });const getMax = (time: Time, bucket: TimeBucket) => {const now = DateTime.now();++ // Helper function to get bucket-specific minute adjustment+ const getMinuteAdjustment = (bucket: TimeBucket) => {+ switch (bucket) {+ case "hour":+ return 59;+ case "fifteen_minutes":+ return 14;+ case "ten_minutes":+ return 9;+ case "five_minutes":+ return 4;+ default:+ return 0;+ }+ };++ // Helper to apply end of period with bucket adjustment+ const getAdjustedEndDate = (dateTime: DateTime) => {+ return dateTime+ .endOf(+ time.mode === "day" || time.mode === "range"+ ? "day"+ : time.mode === "week"+ ? "week"+ : time.mode === "month"+ ? "month"+ : time.mode === "year"+ ? "year"+ : "day"+ )+ .minus({ minutes: getMinuteAdjustment(bucket) });+ };+if (time.mode === "last-24-hours") {return DateTime.now().setZone("UTC").startOf("hour").toJSDate();- } else if (time.mode === "day") {- const dayDate = DateTime.fromISO(time.day)- .endOf("day")- .minus({- minutes:- bucket === "hour"- ? 59- : bucket === "fifteen_minutes"- ? 14- : bucket === "ten_minutes"- ? 9- : bucket === "five_minutes"- ? 4- : 0,- });- return now < dayDate ? dayDate.toJSDate() : undefined;+ }++ let endDate: DateTime | undefined;++ if (time.mode === "day") {+ endDate = getAdjustedEndDate(DateTime.fromISO(time.day));} else if (time.mode === "range") {- if (bucket === "hour") {- const endDate = DateTime.fromISO(time.endDate).endOf("day").minus({- minutes: 59,- });- return now < endDate ? endDate.toJSDate() : undefined;- }- return undefined;+ endDate = getAdjustedEndDate(DateTime.fromISO(time.endDate));} else if (time.mode === "week") {- if (bucket === "hour") {- const endDate = DateTime.fromISO(time.week).endOf("week").minus({- minutes: 59,- });- return now < endDate ? endDate.toJSDate() : undefined;+ // Only apply for hour and fifteen_minutes buckets+ if (bucket === "hour" || bucket === "fifteen_minutes") {+ endDate = getAdjustedEndDate(DateTime.fromISO(time.week));}- return undefined;} else if (time.mode === "month") {- const monthDate = DateTime.fromISO(time.month).endOf("month");- return now < monthDate ? monthDate.toJSDate() : undefined;+ endDate = getAdjustedEndDate(DateTime.fromISO(time.month));} else if (time.mode === "year") {- const yearDate = DateTime.fromISO(time.year).endOf("year");- return now < yearDate ? yearDate.toJSDate() : undefined;+ endDate = getAdjustedEndDate(DateTime.fromISO(time.year));}- return undefined;++ return endDate && now < endDate ? endDate.toJSDate() : undefined;};const getMin = (time: Time, bucket: TimeBucket) => {