Files
supabase/apps/studio/components/interfaces/AuditLogs/AuditLogsDateRangeOption.tsx
Joshen Lim 1ddb9ac787 Refactor organization audit logs to use filter bar (#51921)
## Context

Related to this PR
[here](https://github.com/supabase/supabase/pull/51790), gonna refactor
the Organization audit logs UI to also use the FilterBar component to
match a consistent UX across log surfaces, instead of the individual
filter popovers.

<img width="1450" height="684" alt="image"
src="https://github.com/user-attachments/assets/c1a4aab3-59d0-46a5-b7c7-1e7a5ad86b0d"
/>


### For design

Adding a small update to the `FilterBar` component here with a
`topLevelOnly` parameter if the component is being used with
`supportsOperators` (nested groups)
- In the case of AuditLogs as least, figured that the date range filter
option only makes sense as a top level filter
- Hence this prevents the date range filter from being selectable while
managing filters within a group

<img width="366" height="186" alt="image"
src="https://github.com/user-attachments/assets/e34ea0c8-5f03-4115-9fb1-554612f148dd"
/>
2026-10-20 14:52:40 +08:00

45 lines
1.4 KiB
TypeScript

import type { CustomOptionProps } from 'ui-patterns/FilterBar'
import { AUDIT_LOG_DATEPICKER_HELPERS } from './AuditLogs.utils'
import {
findMatchingDateHelper,
formatDateRange,
} from '@/components/interfaces/Settings/Logs/Logs.datePickerHelpers'
import {
LogsDatePicker,
type DatePickerValue,
} from '@/components/interfaces/Settings/Logs/Logs.DatePickers'
import {
parseTimeRange,
serializeTimeRange,
} from '@/components/interfaces/Settings/Logs/Logs.timeRange'
export const DateRangeOption = ({ onChange }: CustomOptionProps) => {
const defaultHelper =
AUDIT_LOG_DATEPICKER_HELPERS.find((helper) => helper.default) ?? AUDIT_LOG_DATEPICKER_HELPERS[0]
return (
<LogsDatePicker
hideWarnings
variant="inline"
value={{
from: defaultHelper.calcFrom(),
to: defaultHelper.calcTo(),
text: defaultHelper.text,
isHelper: true,
}}
helpers={AUDIT_LOG_DATEPICKER_HELPERS}
onSubmit={(value: DatePickerValue) =>
onChange(serializeTimeRange([new Date(value.from), new Date(value.to)]))
}
/>
)
}
export const formatDateRangeValue = (value: unknown): string => {
const range = parseTimeRange(value)
if (!range) return String(value ?? '')
const [from, to] = range
const helper = findMatchingDateHelper(from, to, AUDIT_LOG_DATEPICKER_HELPERS)
return helper?.text ?? formatDateRange(from.toISOString(), to.toISOString())
}