mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
Use common shift click helper for audit logs (#50894)
## Context This [PR](https://github.com/supabase/supabase/pull/50462) introduced a shared helper to handle shift click selections for tables. Changes here just updates the account audit logs to use that shared helper <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Updates** * Audit log row selection now toggles individual rows on click and uses the last-clicked row as the anchor for Shift-click range selection. When no rows remain selected, the range anchor is cleared. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
1 parent
54c2a2788f
commit
dd02e96a17
1 file changed
+18
-24
@@ -1,7 +1,7 @@
|
||||
import type { ColumnDef } from '@tanstack/react-table'
|
||||
import dayjs from 'dayjs'
|
||||
import { Box, Boxes } from 'lucide-react'
|
||||
import type { MutableRefObject } from 'react'
|
||||
import type { RefObject } from 'react'
|
||||
import { Checkbox, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
||||
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
||||
import { TanStackTableHeadSort } from 'ui-patterns/Table'
|
||||
@@ -13,11 +13,12 @@ import {
|
||||
TIMESTAMP_MICROS_PER_MS,
|
||||
type AuditLog,
|
||||
} from '@/data/organizations/organization-audit-logs-query'
|
||||
import { getShiftClickRowSelection } from '@/lib/shift-click-selection'
|
||||
|
||||
interface AuditLogColumnsOptions {
|
||||
projects: { ref?: string; name: string }[]
|
||||
organizations: { slug?: string; name: string }[]
|
||||
lastSelectedRowId: MutableRefObject<string | null>
|
||||
lastSelectedRowId: RefObject<string | null>
|
||||
isLoadingProjects: boolean
|
||||
isLoadingOrganizations: boolean
|
||||
}
|
||||
@@ -48,33 +49,26 @@ export function getAuditLogColumns({
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
|
||||
const nextSelected = !row.getIsSelected()
|
||||
const rows = table.getRowModel().rows
|
||||
const lastIndex = lastSelectedRowId.current
|
||||
? rows.findIndex((r) => r.id === lastSelectedRowId.current)
|
||||
: -1
|
||||
const currentIndex = rows.findIndex((r) => r.id === row.id)
|
||||
const canSelectRange = e.shiftKey && lastIndex !== -1 && currentIndex !== -1
|
||||
const currentSelection = table.getState().rowSelection
|
||||
const hasSelection = Object.values(currentSelection).some(Boolean)
|
||||
const anchorRowId = hasSelection ? lastSelectedRowId.current : null
|
||||
|
||||
if (canSelectRange) {
|
||||
const [start, end] =
|
||||
lastIndex < currentIndex ? [lastIndex, currentIndex] : [currentIndex, lastIndex]
|
||||
table.setRowSelection((prev) => {
|
||||
const next = { ...prev }
|
||||
for (let i = start; i <= end; i++) {
|
||||
if (nextSelected) {
|
||||
next[rows[i].id] = true
|
||||
} else {
|
||||
delete next[rows[i].id]
|
||||
}
|
||||
}
|
||||
return next
|
||||
let next: typeof currentSelection
|
||||
if (e.shiftKey) {
|
||||
next = getShiftClickRowSelection({
|
||||
orderedRowIds: table.getRowModel().rows.map((r) => r.id),
|
||||
rowSelection: currentSelection,
|
||||
anchorRowId,
|
||||
targetRowId: row.id,
|
||||
})
|
||||
} else {
|
||||
row.toggleSelected(nextSelected)
|
||||
next = { ...currentSelection }
|
||||
if (next[row.id]) delete next[row.id]
|
||||
else next[row.id] = true
|
||||
}
|
||||
|
||||
lastSelectedRowId.current = row.id
|
||||
table.setRowSelection(next)
|
||||
lastSelectedRowId.current = Object.values(next).some(Boolean) ? row.id : null
|
||||
}}
|
||||
/>
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user