From 61e6316736f22800af5f722a6ec2189546f79e17 Mon Sep 17 00:00:00 2001 From: Yunus M Date: Mon, 5 Aug 2024 16:57:24 +0530 Subject: [PATCH] feat: add 1 month option in time range (#5639) --- .../src/container/NewWidget/RightContainer/timeItems.ts | 8 +++++++- .../src/container/TopNav/DateTimeSelectionV2/config.ts | 4 ++++ frontend/src/lib/getMinMax.ts | 4 ++++ frontend/src/lib/getStartAndEndTime/index.ts | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/src/container/NewWidget/RightContainer/timeItems.ts b/frontend/src/container/NewWidget/RightContainer/timeItems.ts index dd6f8cd552..dc4008d898 100644 --- a/frontend/src/container/NewWidget/RightContainer/timeItems.ts +++ b/frontend/src/container/NewWidget/RightContainer/timeItems.ts @@ -36,6 +36,10 @@ export const timeItems: timePreferance[] = [ name: 'Last 1 week', enum: 'LAST_1_WEEK', }, + { + name: 'Last 1 month', + enum: 'LAST_1_MONTH', + }, ]; export interface timePreferance { @@ -52,7 +56,8 @@ export type timePreferenceType = | LAST_6_HR | LAST_1_DAY | LAST_3_DAYS - | LAST_1_WEEK; + | LAST_1_WEEK + | LAST_1_MONTH; type GLOBAL_TIME = 'GLOBAL_TIME'; type LAST_5_MIN = 'LAST_5_MIN'; @@ -63,5 +68,6 @@ type LAST_6_HR = 'LAST_6_HR'; type LAST_1_DAY = 'LAST_1_DAY'; type LAST_3_DAYS = 'LAST_3_DAYS'; type LAST_1_WEEK = 'LAST_1_WEEK'; +type LAST_1_MONTH = 'LAST_1_MONTH'; export default timeItems; diff --git a/frontend/src/container/TopNav/DateTimeSelectionV2/config.ts b/frontend/src/container/TopNav/DateTimeSelectionV2/config.ts index 19a3e8c431..473107265e 100644 --- a/frontend/src/container/TopNav/DateTimeSelectionV2/config.ts +++ b/frontend/src/container/TopNav/DateTimeSelectionV2/config.ts @@ -19,6 +19,7 @@ type TenDay = '10d'; type OneWeek = '1w'; type TwoWeek = '2w'; type SixWeek = '6w'; +type OneMonth = '1month'; type TwoMonths = '2months'; type Custom = 'custom'; @@ -42,6 +43,7 @@ export type Time = | TwelveHour | TenDay | TwoWeek + | OneMonth | TwoMonths; export type TimeUnit = 'm' | 'h' | 'd' | 'w'; @@ -57,6 +59,7 @@ export const Options: Option[] = [ { value: '1d', label: 'Last 1 day' }, { value: '3d', label: 'Last 3 days' }, { value: '1w', label: 'Last 1 week' }, + { value: '1month', label: 'Last 1 month' }, { value: 'custom', label: 'Custom' }, ]; @@ -95,6 +98,7 @@ export const RelativeDurationOptions: Option[] = [ { value: '1d', label: 'Last 1 day' }, { value: '3d', label: 'Last 3 days' }, { value: '1w', label: 'Last 1 week' }, + { value: '1month', label: 'Last 1 month' }, ]; export const RelativeDurationSuggestionOptions: Option[] = [ diff --git a/frontend/src/lib/getMinMax.ts b/frontend/src/lib/getMinMax.ts index 4a5076b066..d2062f5a4c 100644 --- a/frontend/src/lib/getMinMax.ts +++ b/frontend/src/lib/getMinMax.ts @@ -99,6 +99,10 @@ const GetMinMax = ( // six week = one day * 42 const minTimeAgo = getMinAgo({ minutes: 24 * 60 * 42 }).getTime(); minTime = minTimeAgo; + } else if (interval === '1month') { + // one month = one day * 30 + const minTimeAgo = getMinAgo({ minutes: 24 * 60 * 30 }).getTime(); + minTime = minTimeAgo; } else if (interval === '2months') { // two months = one day * 60 const minTimeAgo = getMinAgo({ minutes: 24 * 60 * 60 }).getTime(); diff --git a/frontend/src/lib/getStartAndEndTime/index.ts b/frontend/src/lib/getStartAndEndTime/index.ts index ee012858d7..43b7d2f6d6 100644 --- a/frontend/src/lib/getStartAndEndTime/index.ts +++ b/frontend/src/lib/getStartAndEndTime/index.ts @@ -56,6 +56,10 @@ const GetStartAndEndTime = ({ return calculateStartAndEndTime(24 * 60 * 7, endString); } + if (type === 'LAST_1_MONTH') { + return calculateStartAndEndTime(24 * 60 * 30, endString); + } + return { start: getMicroSeconds({ time: minTime / 1000000 }), end: getMicroSeconds({ time: maxTime / 1000000 }),