Files
supabase/apps/studio/components/interfaces/Settings/Logs/Logs.timeRange.ts
Joshen Lim 17f21bf6a8 Joshenlim/fe 4510 auditlogs filterbar for account logs (#51790)
## Context

Replaces the individual filters on the Account audit logs page with the
filter bar to match a consistent UX across log surfaces
<img width="1206" height="360" alt="image"
src="https://github.com/user-attachments/assets/c5bdfd7e-3277-4695-b9fc-1791df8720c7"
/>

Also uses the `supportOperators` param for the `FilterBar` to support
"OR" based operations when filtering for projects
<img width="1219" height="97" alt="image"
src="https://github.com/user-attachments/assets/d4748e6c-d1f3-4f23-b767-e0f4bb1c0a1c"
/>

The main changes for the `FilterBar` component made in this PR (which
would be more relevant for the design team) are:
- Added a divider between the options and "New group" 
  - Originally didn't have a divider
- So there's a clearer distinction that the "New group" isn't a option
to set as the value for
- Add a new `defaultGroupOperator` prop
  - Originally defaults to `AND`
- However, in the context of Audit Logs when filtering for projects,
you'd expect `OR` to be the default to filter across several projects
(`AND` wouldn't make sense here)
2026-10-16 13:30:19 +08:00

17 lines
598 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { z } from 'zod'
// Date ranges travel through filter bars as a single `from – to` string value.
const TIME_RANGE_SEPARATOR = ' – '
export const serializeTimeRange = (range: Date[]): string =>
range.map((date) => date.toISOString()).join(TIME_RANGE_SEPARATOR)
export const parseTimeRange = (value: unknown): [Date, Date] | undefined => {
if (typeof value !== 'string') return
const result = z
.tuple([z.coerce.date(), z.coerce.date()])
.safeParse(value.split(TIME_RANGE_SEPARATOR))
if (!result.success || result.data[0] > result.data[1]) return
return result.data
}