fix log explorer date state on first load

This commit is contained in:
Jordi Enric committed 2025-06-12 10:51:08 +02:00
1 parent 46337689db
commit f6d8f52e96
2 files changed
+23 -3

No files matched your search

+6 -2
View File
@@ -52,8 +52,12 @@ const useLogsQuery = (
...initialParams,
project: projectRef,
sql: initialParams?.sql ?? prev.sql,
iso_timestamp_start: initialParams.iso_timestamp_start ?? prev.iso_timestamp_start,
iso_timestamp_end: initialParams.iso_timestamp_end ?? prev.iso_timestamp_end,
iso_timestamp_start: initialParams.iso_timestamp_start
? initialParams.iso_timestamp_start
: defaultHelper.calcFrom(),
iso_timestamp_end: initialParams.iso_timestamp_end
? initialParams.iso_timestamp_end
: defaultHelper.calcTo(),
}))
}, [
projectRef,
@@ -12,6 +12,8 @@ import {
LOGS_LARGE_DATE_RANGE_DAYS_THRESHOLD,
LOGS_TABLES,
TEMPLATES,
EXPLORER_DATEPICKER_HELPERS,
getDefaultHelper,
} from 'components/interfaces/Settings/Logs/Logs.constants'
import {
DatePickerToFrom,
@@ -106,6 +108,7 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
isLoading: logsLoading,
changeQuery,
runQuery,
setParams,
} = useLogsQuery(
projectRef,
{
@@ -221,7 +224,12 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
})
}
changeQuery(query)
setParams((prev: typeof params) => ({
...prev,
sql: query,
iso_timestamp_start: timestampStart,
iso_timestamp_end: timestampEnd,
}))
runQuery()
router.push({
pathname: router.pathname,
@@ -354,6 +362,14 @@ export const LogsExplorerPage: NextPageWithLayout = () => {
}
}, [timestampStart, organization])
// Ensure default date range is set in URL state on first load
useEffect(() => {
const defaultHelper = getDefaultHelper(EXPLORER_DATEPICKER_HELPERS)
if (!timestampStart && !timestampEnd) {
setTimeRange(defaultHelper.calcFrom(), defaultHelper.calcTo())
}
}, [timestampStart, timestampEnd, setTimeRange])
return (
<div className="w-full h-full mx-auto">
<ResizablePanelGroup