From 502ac380832c143686a5d1425fffd0592dba67ba Mon Sep 17 00:00:00 2001 From: SemenStruchev Date: Wed, 14 Aug 2024 00:54:59 +0300 Subject: [PATCH 01/10] added future date range for relative date range picker --- .../DatePicker/RelativeDateRange.jsx | 125 ++++++++++-------- 1 file changed, 69 insertions(+), 56 deletions(-) diff --git a/src/components/DatePicker/RelativeDateRange.jsx b/src/components/DatePicker/RelativeDateRange.jsx index 882fc7516..08ff062a8 100644 --- a/src/components/DatePicker/RelativeDateRange.jsx +++ b/src/components/DatePicker/RelativeDateRange.jsx @@ -4,110 +4,83 @@ import { Button, Select } from "../.."; import { now, toDate } from "../../helpers/date"; const options = { + // Day YESTERDAY: "P1D,yesterday", TODAY: "P1D,today", + NEXT_DAY: "P1D,next day", + // Week LAST_WEEK: "P1W,last week", TRAILING_WEEK: "P1W,-1 week", THIS_WEEK: "P1W,this week", + NEXT_WEEK: "P1W,next week", + // Month LAST_MONTH: "P1M,first day of last month", TRAILING_MONTH: "P1M,-1 month", THIS_MONTH: "P1M,first day of this month", + NEXT_MONTH: "P1M,next month", + // Quarter LAST_QUARTER: "P3M,first day of last quarter", TRAILING_QUARTER: "P3M,-3 months", THIS_QUARTER: "P3M,first day of this quarter", + NEXT_QUARTER: "P3M,next quarter", + // Year LAST_YEAR: "P1Y,first day of January last year", TRAILING_YEAR: "P1Y,-1 year", THIS_YEAR: "P1Y,first day of this year", + NEXT_YEAR: "P1Y,next year", }; export const dateRanges = { day: { label: "Day", options: [ - { - value: options.YESTERDAY, - label: "Yesterday", - }, - { - value: options.TODAY, - label: "Today", - }, + { value: options.YESTERDAY, label: "Yesterday" }, + { value: options.TODAY, label: "Today" }, + { value: options.NEXT_DAY, label: "Next Day" }, ], }, week: { label: "Week", options: [ - { - value: options.LAST_WEEK, - label: "Last Week", - }, - { - value: options.TRAILING_WEEK, - label: "Trailing Week", - }, - { - value: options.THIS_WEEK, - label: "This Week", - }, + { value: options.LAST_WEEK, label: "Last Week" }, + { value: options.TRAILING_WEEK, label: "Trailing Week" }, + { value: options.THIS_WEEK, label: "This Week" }, + { value: options.NEXT_WEEK, label: "Next Week" }, ], }, month: { label: "Month", options: [ - { - value: options.LAST_MONTH, - label: "Last Month", - }, - { - value: options.TRAILING_MONTH, - label: "Trailing Month", - }, - { - value: options.THIS_MONTH, - label: "This Month", - }, + { value: options.LAST_MONTH, label: "Last Month" }, + { value: options.TRAILING_MONTH, label: "Trailing Month" }, + { value: options.THIS_MONTH, label: "This Month" }, + { value: options.NEXT_MONTH, label: "Next Month" }, ], }, quarter: { label: "Quarter", options: [ - { - value: options.LAST_QUARTER, - label: "Last Quarter", - }, - { - value: options.TRAILING_QUARTER, - label: "Trailing Quarter", - }, - { - value: options.THIS_QUARTER, - label: "This Quarter", - }, + { value: options.LAST_QUARTER, label: "Last Quarter" }, + { value: options.TRAILING_QUARTER, label: "Trailing Quarter" }, + { value: options.THIS_QUARTER, label: "This Quarter" }, + { value: options.NEXT_QUARTER, label: "Next Quarter" }, ], }, year: { label: "Year", options: [ - { - value: options.LAST_YEAR, - label: "Last Year", - }, - { - value: options.TRAILING_YEAR, - label: "Trailing Year", - }, - { - value: options.THIS_YEAR, - label: "This Year", - }, + { value: options.LAST_YEAR, label: "Last Year" }, + { value: options.TRAILING_YEAR, label: "Trailing Year" }, + { value: options.THIS_YEAR, label: "This Year" }, + { value: options.NEXT_YEAR, label: "Next Year" }, ], }, }; @@ -128,6 +101,14 @@ const handlers = { }; }, + [options.NEXT_DAY]: (timezone) => { + const nextDay = now(null, timezone).add(1, "day"); // Added + return { + from: toDate(nextDay.startOf("day")), + to: toDate(nextDay.endOf("day"), false), + }; + }, + [options.LAST_WEEK]: (timezone) => { const lastWeek = now(null, timezone).subtract(7, "day"); return { @@ -150,6 +131,14 @@ const handlers = { }; }, + [options.NEXT_WEEK]: (timezone) => { + const nextWeek = now(null, timezone).add(7, "day"); + return { + from: toDate(nextWeek.startOf("week")), + to: toDate(nextWeek.endOf("week"), false), + }; + }, + [options.LAST_MONTH]: (timezone) => { const lastMonth = now(null, timezone).subtract(1, "month"); return { @@ -170,6 +159,14 @@ const handlers = { to: toDate(now(null, timezone).endOf("month"), false), }), + [options.NEXT_MONTH]: (timezone) => { + const nextMonth = now(null, timezone).add(1, "month"); + return { + from: toDate(nextMonth.startOf("month")), + to: toDate(nextMonth.endOf("month"), false), + }; + }, + [options.LAST_QUARTER]: (timezone) => { return { from: toDate(now(null, timezone).startOf("quarter").subtract(3, "month").startOf("month")), @@ -191,6 +188,14 @@ const handlers = { }; }, + [options.NEXT_QUARTER]: (timezone) => { + const nextQuarter = now(null, timezone).add(3, "month"); + return { + from: toDate(nextQuarter.startOf("quarter")), + to: toDate(nextQuarter.endOf("quarter"), false), + }; + }, + [options.LAST_YEAR]: (timezone) => { const lastYear = now(null, timezone).subtract(1, "year"); return { @@ -210,6 +215,14 @@ const handlers = { from: toDate(now(null, timezone).startOf("year")), to: toDate(now(null, timezone).endOf("year"), false), }), + + [options.NEXT_YEAR]: (timezone) => { + const nextYear = now(null, timezone).add(1, "year"); + return { + from: toDate(nextYear.startOf("year")), + to: toDate(nextYear.endOf("year"), false), + }; + }, }; export const RelativeDateRange = ({ From d2102d4fced10fbed3d5ae3344cbfaf656178a7f Mon Sep 17 00:00:00 2001 From: SemenStruchev Date: Tue, 27 Aug 2024 18:51:19 +0300 Subject: [PATCH 02/10] resolve feedback --- src/components/DatePicker/RelativeDateRange.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/DatePicker/RelativeDateRange.jsx b/src/components/DatePicker/RelativeDateRange.jsx index 08ff062a8..4e55e7459 100644 --- a/src/components/DatePicker/RelativeDateRange.jsx +++ b/src/components/DatePicker/RelativeDateRange.jsx @@ -102,7 +102,7 @@ const handlers = { }, [options.NEXT_DAY]: (timezone) => { - const nextDay = now(null, timezone).add(1, "day"); // Added + const nextDay = now(null, timezone).add(1, "day"); return { from: toDate(nextDay.startOf("day")), to: toDate(nextDay.endOf("day"), false), @@ -132,7 +132,7 @@ const handlers = { }, [options.NEXT_WEEK]: (timezone) => { - const nextWeek = now(null, timezone).add(7, "day"); + const nextWeek = now(null, timezone).add(1, "week"); return { from: toDate(nextWeek.startOf("week")), to: toDate(nextWeek.endOf("week"), false), @@ -189,7 +189,7 @@ const handlers = { }, [options.NEXT_QUARTER]: (timezone) => { - const nextQuarter = now(null, timezone).add(3, "month"); + const nextQuarter = now(null, timezone).add(1, "quarter"); return { from: toDate(nextQuarter.startOf("quarter")), to: toDate(nextQuarter.endOf("quarter"), false), From 67bcc2afc751e4ad405cdc94eccb7b4457d90861 Mon Sep 17 00:00:00 2001 From: SemenStruchev Date: Wed, 18 Sep 2024 12:14:22 +0300 Subject: [PATCH 03/10] resolve feedback --- src/components/DatePicker/RelativeDateRange.jsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/DatePicker/RelativeDateRange.jsx b/src/components/DatePicker/RelativeDateRange.jsx index 4e55e7459..f7c9af914 100644 --- a/src/components/DatePicker/RelativeDateRange.jsx +++ b/src/components/DatePicker/RelativeDateRange.jsx @@ -233,6 +233,7 @@ export const RelativeDateRange = ({ onChange, onSubmit, timezoneName, + isFutureDatesAllowed = false, // New prop }) => { const handleChange = (e) => { const rangeName = e.target.value; @@ -240,6 +241,14 @@ export const RelativeDateRange = ({ onChange(rangeName, range); }; + const filterFutureDates = (options) => { + if (!isFutureDatesAllowed) { + // Filter out future date options + return options.filter((option) => !option.value.includes("next")); + } + return options; + }; + return (
@@ -268,7 +267,7 @@ export const RelativeDateRange = ({ return ( - {filterFutureDates(range.options).map((option) => ( + {filterFutureDates(range.options, isFutureDatesAllowed, futureDates).map((option) => ( From 8857ccf122b375a7bad4aeb1ce06193ad8240e99 Mon Sep 17 00:00:00 2001 From: SemenStruchev Date: Tue, 1 Oct 2024 01:23:09 +0300 Subject: [PATCH 09/10] added leading options to relative date tange --- .../DatePicker/RelativeDateRange.jsx | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/components/DatePicker/RelativeDateRange.jsx b/src/components/DatePicker/RelativeDateRange.jsx index e57846a28..e8aef838d 100644 --- a/src/components/DatePicker/RelativeDateRange.jsx +++ b/src/components/DatePicker/RelativeDateRange.jsx @@ -14,24 +14,28 @@ const options = { TRAILING_WEEK: "P1W,-1 week", THIS_WEEK: "P1W,this week", NEXT_WEEK: "P1W,next week", + LEADING_WEEK: "P1W,+1 week", // Month LAST_MONTH: "P1M,first day of last month", TRAILING_MONTH: "P1M,-1 month", THIS_MONTH: "P1M,first day of this month", NEXT_MONTH: "P1M,next month", + LEADING_MONTH: "P1M,+1 month", // Quarter LAST_QUARTER: "P3M,first day of last quarter", TRAILING_QUARTER: "P3M,-3 months", THIS_QUARTER: "P3M,first day of this quarter", NEXT_QUARTER: "P3M,next quarter", + LEADING_QUARTER: "P3M,+3 months", // Year LAST_YEAR: "P1Y,first day of January last year", TRAILING_YEAR: "P1Y,-1 year", THIS_YEAR: "P1Y,first day of this year", NEXT_YEAR: "P1Y,next year", + LEADING_YEAR: "P1Y,+1 year", }; export const dateRanges = { @@ -40,7 +44,7 @@ export const dateRanges = { options: [ { value: options.YESTERDAY, label: "Yesterday" }, { value: options.TODAY, label: "Today" }, - { value: options.NEXT_DAY, label: "Next Day" }, + { value: options.NEXT_DAY, label: "Tomorrow" }, ], }, @@ -51,6 +55,7 @@ export const dateRanges = { { value: options.TRAILING_WEEK, label: "Trailing Week" }, { value: options.THIS_WEEK, label: "This Week" }, { value: options.NEXT_WEEK, label: "Next Week" }, + { value: options.LEADING_WEEK, label: "Leading Week" }, ], }, @@ -61,6 +66,7 @@ export const dateRanges = { { value: options.TRAILING_MONTH, label: "Trailing Month" }, { value: options.THIS_MONTH, label: "This Month" }, { value: options.NEXT_MONTH, label: "Next Month" }, + { value: options.LEADING_MONTH, label: "Leading Month" }, ], }, @@ -71,6 +77,7 @@ export const dateRanges = { { value: options.TRAILING_QUARTER, label: "Trailing Quarter" }, { value: options.THIS_QUARTER, label: "This Quarter" }, { value: options.NEXT_QUARTER, label: "Next Quarter" }, + { value: options.LEADING_QUARTER, label: "Leading Quarter" }, ], }, @@ -81,6 +88,7 @@ export const dateRanges = { { value: options.TRAILING_YEAR, label: "Trailing Year" }, { value: options.THIS_YEAR, label: "This Year" }, { value: options.NEXT_YEAR, label: "Next Year" }, + { value: options.LEADING_YEAR, label: "Leading Year" }, ], }, }; @@ -100,6 +108,10 @@ const futureDates = new Set([ options.NEXT_MONTH, options.NEXT_QUARTER, options.NEXT_YEAR, + options.LEADING_WEEK, + options.LEADING_MONTH, + options.LEADING_QUARTER, + options.LEADING_YEAR, ]); const handlers = { @@ -156,6 +168,13 @@ const handlers = { }; }, + [options.LEADING_WEEK]: (timezone) => { + return { + from: toDate(now(null, timezone).add(7, "day").startOf("day")), + to: toDate(now(null, timezone).add(14, "day").endOf("day"), false), + }; + }, + [options.LAST_MONTH]: (timezone) => { const lastMonth = now(null, timezone).subtract(1, "month"); return { @@ -184,6 +203,13 @@ const handlers = { }; }, + [options.LEADING_MONTH]: (timezone) => { + return { + from: toDate(now(null, timezone).add(1, "month").startOf("month")), + to: toDate(now(null, timezone).add(2, "month").endOf("month"), false), + }; + }, + [options.LAST_QUARTER]: (timezone) => { return { from: toDate(now(null, timezone).startOf("quarter").subtract(3, "month").startOf("month")), @@ -213,6 +239,13 @@ const handlers = { }; }, + [options.LEADING_QUARTER]: (timezone) => { + return { + from: toDate(now(null, timezone).add(3, "month").startOf("quarter")), + to: toDate(now(null, timezone).add(6, "month").endOf("quarter"), false), + }; + }, + [options.LAST_YEAR]: (timezone) => { const lastYear = now(null, timezone).subtract(1, "year"); return { @@ -240,6 +273,13 @@ const handlers = { to: toDate(nextYear.endOf("year"), false), }; }, + + [options.LEADING_YEAR]: (timezone) => { + return { + from: toDate(now(null, timezone).add(1, "year").startOf("year")), + to: toDate(now(null, timezone).add(2, "year").endOf("year"), false), + }; + }, }; export const RelativeDateRange = ({ From 0d1d2fb6e83e1d010b9aaf1732ac7db9d843cfbb Mon Sep 17 00:00:00 2001 From: SemenStruchev Date: Tue, 1 Oct 2024 13:52:25 +0300 Subject: [PATCH 10/10] resolve feedback --- .../DatePicker/RelativeDateRange.jsx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/DatePicker/RelativeDateRange.jsx b/src/components/DatePicker/RelativeDateRange.jsx index e8aef838d..8b1b19250 100644 --- a/src/components/DatePicker/RelativeDateRange.jsx +++ b/src/components/DatePicker/RelativeDateRange.jsx @@ -169,9 +169,10 @@ const handlers = { }, [options.LEADING_WEEK]: (timezone) => { + const today = now(null, timezone); return { - from: toDate(now(null, timezone).add(7, "day").startOf("day")), - to: toDate(now(null, timezone).add(14, "day").endOf("day"), false), + from: toDate(today.startOf("day")), + to: toDate(today.add(1, "week").subtract(1, "day").endOf("day"), false), }; }, @@ -204,9 +205,10 @@ const handlers = { }, [options.LEADING_MONTH]: (timezone) => { + const today = now(null, timezone); return { - from: toDate(now(null, timezone).add(1, "month").startOf("month")), - to: toDate(now(null, timezone).add(2, "month").endOf("month"), false), + from: toDate(today.startOf("day")), + to: toDate(today.add(1, "month").subtract(1, "day").endOf("day"), false), }; }, @@ -240,9 +242,10 @@ const handlers = { }, [options.LEADING_QUARTER]: (timezone) => { + const today = now(null, timezone); return { - from: toDate(now(null, timezone).add(3, "month").startOf("quarter")), - to: toDate(now(null, timezone).add(6, "month").endOf("quarter"), false), + from: toDate(today.startOf("day")), + to: toDate(today.add(3, "month").subtract(1, "day").endOf("day"), false), // Сегодня + 3 месяца }; }, @@ -275,9 +278,10 @@ const handlers = { }, [options.LEADING_YEAR]: (timezone) => { + const today = now(null, timezone); return { - from: toDate(now(null, timezone).add(1, "year").startOf("year")), - to: toDate(now(null, timezone).add(2, "year").endOf("year"), false), + from: toDate(today.startOf("day")), + to: toDate(today.add(1, "year").subtract(1, "day").endOf("day"), false), // Сегодня + 1 год }; }, };