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

View File

@ -148,3 +148,8 @@ export interface TimeRange {
startTime: 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 {
getDefaultOption,
getOptions,
LexicalContext,
LocalStorageTimeRange,
Time,
TimeRange,
@ -318,31 +319,37 @@ function DateTimeSelection({
onLastRefreshHandler();
};
const onCustomDateHandler = (dateTimeRange: DateTimeRangeType): void => {
const onCustomDateHandler = (
dateTimeRange: DateTimeRangeType,
lexicalContext?: LexicalContext,
): void => {
if (dateTimeRange !== null) {
const [startTimeMoment, endTimeMoment] = dateTimeRange;
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);
startTimeMoment.startOf('day').toString();
updateTimeInterval('custom', [
startTimeMoment.startOf('day').toDate().getTime(),
endTimeMoment.endOf('day').toDate().getTime(),
startTime.toDate().getTime(),
endTime.toDate().getTime(),
]);
setLocalStorageKey('startTime', startTimeMoment.toString());
setLocalStorageKey('endTime', endTimeMoment.toString());
updateLocalStorageForRoutes(
JSON.stringify({ startTime: startTimeMoment, endTime: endTimeMoment }),
);
setLocalStorageKey('startTime', startTime.toString());
setLocalStorageKey('endTime', endTime.toString());
updateLocalStorageForRoutes(JSON.stringify({ startTime, endTime }));
if (!isLogsExplorerPage) {
urlQuery.set(
QueryParams.startTime,
startTimeMoment?.toDate().getTime().toString(),
);
urlQuery.set(
QueryParams.endTime,
endTimeMoment?.toDate().getTime().toString(),
startTime?.toDate().getTime().toString(),
);
urlQuery.set(QueryParams.endTime, endTime?.toDate().getTime().toString());
const generatedUrl = `${location.pathname}?${urlQuery.toString()}`;
history.replace(generatedUrl);
}