Skip to content

Commit 60a3d79

Browse files
committed
fix(url-state): honor a custom time range only when both bounds are present
A partial ?time-range=custom deep link (missing start/end) now falls back to the default preset window instead of displaying 'Custom range' while querying an unbounded result set.
1 parent 7142861 commit 60a3d79

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

apps/sim/ee/audit-logs/components/audit-logs.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ import { SettingsPanel } from '@/app/workspace/[workspaceId]/settings/components
3434
import { useSettingsSearch } from '@/app/workspace/[workspaceId]/settings/components/use-settings-search'
3535
import { RESOURCE_TYPE_OPTIONS } from '@/ee/audit-logs/constants'
3636
import { type AuditLogFilters, useAuditLogs } from '@/ee/audit-logs/hooks/audit-logs'
37-
import { auditLogFilterParsers, auditLogFilterUrlKeys } from '@/ee/audit-logs/search-params'
37+
import {
38+
auditLogFilterParsers,
39+
auditLogFilterUrlKeys,
40+
DEFAULT_AUDIT_TIME_RANGE,
41+
} from '@/ee/audit-logs/search-params'
3842
import { useDebounce } from '@/hooks/use-debounce'
3943
import type { TimeRange } from '@/stores/logs/filters/types'
4044

@@ -234,13 +238,22 @@ interface AuditLogsProps {
234238

235239
export function AuditLogs({ organizationId }: AuditLogsProps) {
236240
const [urlFilters, setUrlFilters] = useQueryStates(auditLogFilterParsers, auditLogFilterUrlKeys)
237-
const { types: selectedTypes, timeRange } = urlFilters
241+
const { types: selectedTypes } = urlFilters
238242
const customStartDate = urlFilters.startDate ?? ''
239243
const customEndDate = urlFilters.endDate ?? ''
244+
/**
245+
* 'Custom range' is only honored with both bounds present — a partial deep
246+
* link (`?time-range=custom` with a missing date) falls back to the default
247+
* preset window instead of silently querying unbounded.
248+
*/
249+
const timeRange: TimeRange =
250+
urlFilters.timeRange === 'Custom range' && (!customStartDate || !customEndDate)
251+
? DEFAULT_AUDIT_TIME_RANGE
252+
: urlFilters.timeRange
240253
const [datePickerOpen, setDatePickerOpen] = useState(false)
241254
/** Cancel target for the date picker — never 'Custom range' itself, so a deep link straight to an empty custom range still cancels back to a preset. */
242255
const previousTimeRangeRef = useRef<TimeRange>(
243-
timeRange === 'Custom range' ? 'Past 30 days' : timeRange
256+
timeRange === 'Custom range' ? DEFAULT_AUDIT_TIME_RANGE : timeRange
244257
)
245258
const dateRangeAppliedRef = useRef(false)
246259
const [searchTerm, setSearchTerm] = useSettingsSearch()

apps/sim/ee/audit-logs/search-params.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parseAsArrayOf, parseAsString } from 'nuqs/server'
22
import { parseAsTimeRange } from '@/app/workspace/[workspaceId]/logs/search-params'
33
import type { TimeRange } from '@/stores/logs/filters/types'
44

5-
const DEFAULT_AUDIT_TIME_RANGE: TimeRange = 'Past 30 days'
5+
export const DEFAULT_AUDIT_TIME_RANGE: TimeRange = 'Past 30 days'
66

77
/**
88
* Co-located, typed URL query-param definitions for the enterprise audit-logs

0 commit comments

Comments
 (0)