Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

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

Vikrant Guptaf3bc1a8f8a0a
diff --git a/frontend/src/components/CustomTimePicker/CustomTimePickerPopoverContent.tsx b/frontend/src/components/CustomTimePicker/CustomTimePickerPopoverContent.tsx
index e7bd571f35..3141158f7f 100644
--- a/frontend/src/components/CustomTimePicker/CustomTimePickerPopoverContent.tsx
+++ b/frontend/src/components/CustomTimePicker/CustomTimePickerPopoverContent.tsx
@@ -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 (
diff --git a/frontend/src/container/TopNav/DateTimeSelectionV2/config.ts b/frontend/src/container/TopNav/DateTimeSelectionV2/config.ts
index a1562e5a4c..becd3fed7b 100644
--- a/frontend/src/container/TopNav/DateTimeSelectionV2/config.ts
+++ b/frontend/src/container/TopNav/DateTimeSelectionV2/config.ts
@@ -148,3 +148,8 @@ export interface TimeRange {
startTime: string;
endTime: string;
}
+
+export enum LexicalContext {
+ CUSTOM_DATE_PICKER = 'customDatePicker',
+ CUSTOM_DATE_TIME_INPUT = 'customDateTimeInput',
+}
diff --git a/frontend/src/container/TopNav/DateTimeSelectionV2/index.tsx b/frontend/src/container/TopNav/DateTimeSelectionV2/index.tsx
index 157397f026..6e5c0c5b48 100644
--- a/frontend/src/container/TopNav/DateTimeSelectionV2/index.tsx
+++ b/frontend/src/container/TopNav/DateTimeSelectionV2/index.tsx
@@ -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);
}