refactor: added 3 days global timestamp (#4290)

* refactor: added 3 days global timestamp

* refactor: updated 3 days data in right container

* refactor: common function for calculate start and end time
This commit is contained in:
Rajat Dabade 2023-12-29 12:54:02 +05:30 committed by GitHub
parent 3572baa5eb
commit cfc239e3c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 49 deletions

View File

@ -28,6 +28,10 @@ export const timeItems: timePreferance[] = [
name: 'Last 1 day', name: 'Last 1 day',
enum: 'LAST_1_DAY', enum: 'LAST_1_DAY',
}, },
{
name: 'Last 3 days',
enum: 'LAST_3_DAYS',
},
{ {
name: 'Last 1 week', name: 'Last 1 week',
enum: 'LAST_1_WEEK', enum: 'LAST_1_WEEK',
@ -47,6 +51,7 @@ export type timePreferenceType =
| LAST_1_HR | LAST_1_HR
| LAST_6_HR | LAST_6_HR
| LAST_1_DAY | LAST_1_DAY
| LAST_3_DAYS
| LAST_1_WEEK; | LAST_1_WEEK;
type GLOBAL_TIME = 'GLOBAL_TIME'; type GLOBAL_TIME = 'GLOBAL_TIME';
@ -56,6 +61,7 @@ type LAST_30_MIN = 'LAST_30_MIN';
type LAST_1_HR = 'LAST_1_HR'; type LAST_1_HR = 'LAST_1_HR';
type LAST_6_HR = 'LAST_6_HR'; type LAST_6_HR = 'LAST_6_HR';
type LAST_1_DAY = 'LAST_1_DAY'; type LAST_1_DAY = 'LAST_1_DAY';
type LAST_3_DAYS = 'LAST_3_DAYS';
type LAST_1_WEEK = 'LAST_1_WEEK'; type LAST_1_WEEK = 'LAST_1_WEEK';
export default timeItems; export default timeItems;

View File

@ -9,6 +9,7 @@ type SixHour = '6hr';
type OneHour = '1hr'; type OneHour = '1hr';
type FourHour = '4hr'; type FourHour = '4hr';
type OneDay = '1day'; type OneDay = '1day';
type ThreeDay = '3days';
type OneWeek = '1week'; type OneWeek = '1week';
type Custom = 'custom'; type Custom = 'custom';
@ -23,7 +24,8 @@ export type Time =
| OneHour | OneHour
| Custom | Custom
| OneWeek | OneWeek
| OneDay; | OneDay
| ThreeDay;
export const Options: Option[] = [ export const Options: Option[] = [
{ value: '5min', label: 'Last 5 min' }, { value: '5min', label: 'Last 5 min' },
@ -32,6 +34,7 @@ export const Options: Option[] = [
{ value: '1hr', label: 'Last 1 hour' }, { value: '1hr', label: 'Last 1 hour' },
{ value: '6hr', label: 'Last 6 hour' }, { value: '6hr', label: 'Last 6 hour' },
{ value: '1day', label: 'Last 1 day' }, { value: '1day', label: 'Last 1 day' },
{ value: '3days', label: 'Last 3 days' },
{ value: '1week', label: 'Last 1 week' }, { value: '1week', label: 'Last 1 week' },
{ value: 'custom', label: 'Custom' }, { value: 'custom', label: 'Custom' },
]; ];
@ -48,6 +51,7 @@ export const RelativeDurationOptions: Option[] = [
{ value: '1hr', label: 'Last 1 hour' }, { value: '1hr', label: 'Last 1 hour' },
{ value: '6hr', label: 'Last 6 hour' }, { value: '6hr', label: 'Last 6 hour' },
{ value: '1day', label: 'Last 1 day' }, { value: '1day', label: 'Last 1 day' },
{ value: '3days', label: 'Last 3 days' },
{ value: '1week', label: 'Last 1 week' }, { value: '1week', label: 'Last 1 week' },
]; ];

View File

@ -6,6 +6,7 @@ import getMinAgo from './getStartAndEndTime/getMinAgo';
const GetMinMax = ( const GetMinMax = (
interval: Time, interval: Time,
dateTimeRange?: [number, number], dateTimeRange?: [number, number],
// eslint-disable-next-line sonarjs/cognitive-complexity
): GetMinMaxPayload => { ): GetMinMaxPayload => {
let maxTime = new Date().getTime(); let maxTime = new Date().getTime();
let minTime = 0; let minTime = 0;
@ -32,6 +33,10 @@ const GetMinMax = (
// one day = 24*60(min) // one day = 24*60(min)
const minTimeAgo = getMinAgo({ minutes: 24 * 60 }).getTime(); const minTimeAgo = getMinAgo({ minutes: 24 * 60 }).getTime();
minTime = minTimeAgo; minTime = minTimeAgo;
} else if (interval === '3days') {
// three day = one day * 3
const minTimeAgo = getMinAgo({ minutes: 24 * 60 * 3 }).getTime();
minTime = minTimeAgo;
} else if (interval === '1week') { } else if (interval === '1week') {
// one week = one day * 7 // one week = one day * 7
const minTimeAgo = getMinAgo({ minutes: 24 * 60 * 7 }).getTime(); const minTimeAgo = getMinAgo({ minutes: 24 * 60 * 7 }).getTime();

View File

@ -3,6 +3,19 @@ import { timePreferenceType } from 'container/NewWidget/RightContainer/timeItems
import getMicroSeconds from './getMicroSeconds'; import getMicroSeconds from './getMicroSeconds';
import getMinAgo from './getMinAgo'; import getMinAgo from './getMinAgo';
const calculateStartAndEndTime = (
minutes: number,
endString: string,
): Payload => {
const agodate = getMinAgo({ minutes }).getTime();
const agoString = getMicroSeconds({ time: agodate });
return {
start: agoString,
end: endString,
};
};
const GetStartAndEndTime = ({ const GetStartAndEndTime = ({
type, type,
minTime, minTime,
@ -12,73 +25,35 @@ const GetStartAndEndTime = ({
const endString = getMicroSeconds({ time: end }); const endString = getMicroSeconds({ time: end });
if (type === 'LAST_5_MIN') { if (type === 'LAST_5_MIN') {
const agodate = getMinAgo({ minutes: 5 }).getTime(); return calculateStartAndEndTime(5, endString);
const agoString = getMicroSeconds({ time: agodate });
return {
start: agoString,
end: endString,
};
} }
if (type === 'LAST_30_MIN') { if (type === 'LAST_30_MIN') {
const agodate = getMinAgo({ minutes: 30 }).getTime(); return calculateStartAndEndTime(30, endString);
const agoString = getMicroSeconds({ time: agodate });
return {
start: agoString,
end: endString,
};
} }
if (type === 'LAST_1_HR') { if (type === 'LAST_1_HR') {
const agodate = getMinAgo({ minutes: 60 }).getTime(); return calculateStartAndEndTime(60, endString);
const agoString = getMicroSeconds({ time: agodate });
return {
start: agoString,
end: endString,
};
} }
if (type === 'LAST_15_MIN') { if (type === 'LAST_15_MIN') {
const agodate = getMinAgo({ minutes: 15 }).getTime(); return calculateStartAndEndTime(15, endString);
const agoString = getMicroSeconds({ time: agodate });
return {
start: agoString,
end: endString,
};
} }
if (type === 'LAST_6_HR') { if (type === 'LAST_6_HR') {
const agoDate = getMinAgo({ minutes: 6 * 60 }).getTime(); return calculateStartAndEndTime(6 * 60, endString);
const agoString = getMicroSeconds({ time: agoDate });
return {
start: agoString,
end: endString,
};
} }
if (type === 'LAST_1_DAY') { if (type === 'LAST_1_DAY') {
const agoDate = getMinAgo({ minutes: 24 * 60 }).getTime(); return calculateStartAndEndTime(24 * 60, endString);
const agoString = getMicroSeconds({ time: agoDate }); }
return { if (type === 'LAST_3_DAYS') {
start: agoString, return calculateStartAndEndTime(24 * 60 * 3, endString);
end: endString,
};
} }
if (type === 'LAST_1_WEEK') { if (type === 'LAST_1_WEEK') {
const agoDate = getMinAgo({ minutes: 24 * 60 * 7 }).getTime(); return calculateStartAndEndTime(24 * 60 * 7, endString);
const agoString = getMicroSeconds({ time: agoDate });
return {
start: agoString,
end: endString,
};
} }
return { return {