fix: date time value initialising to start of day in case of typing (#4585)

This commit is contained in:
Vikrant Gupta 2024-02-22 16:32:30 +05:30 committed by GitHub
parent 7bca847f11
commit f3bc1a8f8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 16 deletions

View File

@ -5,6 +5,7 @@ import cx from 'classnames';
import ROUTES from 'constants/routes'; import ROUTES from 'constants/routes';
import { DateTimeRangeType } from 'container/TopNav/CustomDateTimeModal'; import { DateTimeRangeType } from 'container/TopNav/CustomDateTimeModal';
import { import {
LexicalContext,
Option, Option,
RelativeDurationSuggestionOptions, RelativeDurationSuggestionOptions,
} from 'container/TopNav/DateTimeSelectionV2/config'; } from 'container/TopNav/DateTimeSelectionV2/config';
@ -20,7 +21,10 @@ interface CustomTimePickerPopoverContentProps {
setIsOpen: Dispatch<SetStateAction<boolean>>; setIsOpen: Dispatch<SetStateAction<boolean>>;
customDateTimeVisible: boolean; customDateTimeVisible: boolean;
setCustomDTPickerVisible: Dispatch<SetStateAction<boolean>>; setCustomDTPickerVisible: Dispatch<SetStateAction<boolean>>;
onCustomDateHandler: (dateTimeRange: DateTimeRangeType) => void; onCustomDateHandler: (
dateTimeRange: DateTimeRangeType,
lexicalContext?: LexicalContext,
) => void;
onSelectHandler: (label: string, value: string) => void; onSelectHandler: (label: string, value: string) => void;
handleGoLive: () => void; handleGoLive: () => void;
selectedTime: string; selectedTime: string;
@ -63,7 +67,7 @@ function CustomTimePickerPopoverContent({
if (date_time?.[1]) { if (date_time?.[1]) {
onPopoverClose(false); onPopoverClose(false);
} }
onCustomDateHandler(date_time); onCustomDateHandler(date_time, LexicalContext.CUSTOM_DATE_PICKER);
}; };
function getTimeChips(options: Option[]): JSX.Element { function getTimeChips(options: Option[]): JSX.Element {
return ( return (

View File

@ -148,3 +148,8 @@ export interface TimeRange {
startTime: string; startTime: string;
endTime: string; endTime: string;
} }
export enum LexicalContext {
CUSTOM_DATE_PICKER = 'customDatePicker',
CUSTOM_DATE_TIME_INPUT = 'customDateTimeInput',
}

View File

@ -44,6 +44,7 @@ import { DateTimeRangeType } from '../CustomDateTimeModal';
import { import {
getDefaultOption, getDefaultOption,
getOptions, getOptions,
LexicalContext,
LocalStorageTimeRange, LocalStorageTimeRange,
Time, Time,
TimeRange, TimeRange,
@ -318,31 +319,37 @@ function DateTimeSelection({
onLastRefreshHandler(); onLastRefreshHandler();
}; };
const onCustomDateHandler = (dateTimeRange: DateTimeRangeType): void => { const onCustomDateHandler = (
dateTimeRange: DateTimeRangeType,
lexicalContext?: LexicalContext,
): void => {
if (dateTimeRange !== null) { if (dateTimeRange !== null) {
const [startTimeMoment, endTimeMoment] = dateTimeRange; const [startTimeMoment, endTimeMoment] = dateTimeRange;
if (startTimeMoment && endTimeMoment) { if (startTimeMoment && endTimeMoment) {
let startTime = startTimeMoment;
let endTime = endTimeMoment;
if (
lexicalContext &&
lexicalContext === LexicalContext.CUSTOM_DATE_PICKER
) {
startTime = startTime.startOf('day');
endTime = endTime.endOf('day');
}
setCustomDTPickerVisible(false); setCustomDTPickerVisible(false);
startTimeMoment.startOf('day').toString();
updateTimeInterval('custom', [ updateTimeInterval('custom', [
startTimeMoment.startOf('day').toDate().getTime(), startTime.toDate().getTime(),
endTimeMoment.endOf('day').toDate().getTime(), endTime.toDate().getTime(),
]); ]);
setLocalStorageKey('startTime', startTimeMoment.toString()); setLocalStorageKey('startTime', startTime.toString());
setLocalStorageKey('endTime', endTimeMoment.toString()); setLocalStorageKey('endTime', endTime.toString());
updateLocalStorageForRoutes( updateLocalStorageForRoutes(JSON.stringify({ startTime, endTime }));
JSON.stringify({ startTime: startTimeMoment, endTime: endTimeMoment }),
);
if (!isLogsExplorerPage) { if (!isLogsExplorerPage) {
urlQuery.set( urlQuery.set(
QueryParams.startTime, QueryParams.startTime,
startTimeMoment?.toDate().getTime().toString(), startTime?.toDate().getTime().toString(),
);
urlQuery.set(
QueryParams.endTime,
endTimeMoment?.toDate().getTime().toString(),
); );
urlQuery.set(QueryParams.endTime, endTime?.toDate().getTime().toString());
const generatedUrl = `${location.pathname}?${urlQuery.toString()}`; const generatedUrl = `${location.pathname}?${urlQuery.toString()}`;
history.replace(generatedUrl); history.replace(generatedUrl);
} }