mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## 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" />
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import dayjs from 'dayjs'
|
|
|
|
import { DatePickerToFrom } from '@/components/interfaces/Settings/Logs/Logs.types'
|
|
|
|
// [Joshen] Mainly to handle if a single date is selected - currently just for Audit Logs as
|
|
// i'm on the fence if this logic should be within the DatePicker component itself
|
|
// e.g for Logs.DatePicker which uses this component, the component itself has its own time selection UI
|
|
// JFYI currentDate is just a parameter so that I can run tests for this
|
|
|
|
export const formatSelectedDateRange = (value: DatePickerToFrom) => {
|
|
const current = dayjs()
|
|
const from = dayjs(value.from)
|
|
.hour(current.hour())
|
|
.minute(current.minute())
|
|
.second(current.second())
|
|
const to = dayjs(value.to).hour(current.hour()).minute(current.minute()).second(current.second())
|
|
|
|
if (from.date() === to.date()) {
|
|
// [Joshen] If a single date is selected, we either set the "from" to start from 00:00
|
|
// or "to" to end at 23:59 depending on which date was selected
|
|
if (from.date() === current.date()) {
|
|
return {
|
|
from: from.set('hour', 0).set('minute', 0).set('second', 0).utc().toISOString(),
|
|
to: to.utc().toISOString(),
|
|
}
|
|
} else {
|
|
return {
|
|
from: from.utc().toISOString(),
|
|
to: to.set('hour', 23).set('minute', 59).set('second', 59).utc().toISOString(),
|
|
}
|
|
}
|
|
} else {
|
|
return { from: from.utc().toISOString(), to: to.utc().toISOString() }
|
|
}
|
|
}
|