Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Virtualize AuditLogsTable component (#51748)

Joshen Limdccad31a398c
diff --git a/apps/studio/components/interfaces/AuditLogs/AuditLogsTable.tsx b/apps/studio/components/interfaces/AuditLogs/AuditLogsTable.tsx
index 72f391f7da8..b4e224cdc6b 100644
--- a/apps/studio/components/interfaces/AuditLogs/AuditLogsTable.tsx
+++ b/apps/studio/components/interfaces/AuditLogs/AuditLogsTable.tsx
@@ -1,9 +1,14 @@
import { flexRender, type Table as TanStackTable } from '@tanstack/react-table'
-import { cn, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
+import { useRef } from 'react'
+import { cn, TableCell, TableHead, TableHeader, TableRow } from 'ui'
import { formatCompactNumber } from '@/components/ui/DataTable/DataTable.utils'
+import { VirtualizedTable, VirtualizedTableBody } from '@/components/ui/VirtualizedTable'
import type { AuditLog } from '@/data/organizations/organization-audit-logs-query'
+// py-2 padding + text-xs line height; rows are re-measured after mount
+const ESTIMATED_ROW_HEIGHT = 41
+
interface AuditLogColumnMeta {
cellClassName?: string
headerClassName?: string
@@ -16,15 +21,17 @@ interface AuditLogsTableProps {
}
export const AuditLogsTable = ({ table, selectedLog, onSelectLog }: AuditLogsTableProps) => {
+ const scrollContainerRef = useRef<HTMLDivElement>(null)
const rows = table.getRowModel().rows
return (
- <Table
+ <VirtualizedTable
+ data={rows}
className="table-fixed"
- containerProps={{
- containerClassName: 'h-full',
- className: 'h-full w-full overflow-auto @container',
- }}
+ estimateSize={() => ESTIMATED_ROW_HEIGHT}
+ getItemKey={(row) => row.id}
+ scrollContainerRef={scrollContainerRef}
+ scrollContainerProps={{ className: '@container' }}
>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
@@ -47,8 +54,30 @@ export const AuditLogsTable = ({ table, selectedLog, onSelectLog }: AuditLogsTab
</TableRow>
))}
</TableHeader>
- <TableBody>
- {rows.map((row) => (
+ <VirtualizedTableBody<(typeof rows)[number]>
+ paddingColSpan={table.getAllLeafColumns().length}
+ trailingContent={
+ rows.length > 0 ? (
+ <TableRow className="hover:bg-transparent">
+ <TableCell
+ colSpan={table.getAllLeafColumns().length}
+ className="p-0! overflow-visible"
+ >
+ <div className="sticky left-0 w-[100cqw] py-2 text-center">
+ <p className="text-xs text-foreground-lighter">
+ Viewing{' '}
+ <span className="font-mono font-medium">
+ {formatCompactNumber(rows.length)}
+ </span>{' '}
+ logs
+ </p>
+ </div>
+ </TableCell>
+ </TableRow>
+ ) : undefined
+ }
+ >
+ {(row) => (
<TableRow
key={row.id}
tabIndex={0}
@@ -80,21 +109,8 @@ export const AuditLogsTable = ({ table, selectedLog, onSelectLog }: AuditLogsTab
</TableCell>
))}
</TableRow>
- ))}
- {rows.length > 0 && (
- <TableRow className="hover:bg-transparent">
- <TableCell colSpan={table.getAllLeafColumns().length} className="p-0! overflow-visible">
- <div className="sticky left-0 w-[100cqw] py-2 text-center">
- <p className="text-xs text-foreground-lighter">
- Viewing{' '}
- <span className="font-mono font-medium">{formatCompactNumber(rows.length)}</span>{' '}
- logs
- </p>
- </div>
- </TableCell>
- </TableRow>
)}
- </TableBody>
- </Table>
+ </VirtualizedTableBody>
+ </VirtualizedTable>
)
}
diff --git a/apps/studio/pages/org/[slug]/audit.tsx b/apps/studio/pages/org/[slug]/audit.tsx
index 228c00a2408..c50717376ad 100644
--- a/apps/studio/pages/org/[slug]/audit.tsx
+++ b/apps/studio/pages/org/[slug]/audit.tsx
@@ -20,7 +20,7 @@ const OrgAuditLogs: NextPageWithLayout = () => {
const { data: selectedOrganization } = useSelectedOrganizationQuery()
return (
- <>
+ <div className="flex flex-col h-full">
<PageHeader size="full">
<PageHeaderMeta>
<PageHeaderSummary>
@@ -31,8 +31,14 @@ const OrgAuditLogs: NextPageWithLayout = () => {
</PageHeaderSummary>
</PageHeaderMeta>
</PageHeader>
- {selectedOrganization === undefined && isLoadingPermissions ? <LogoLoader /> : <AuditLogs />}
- </>
+ <div className="flex-1 min-h-0">
+ {selectedOrganization === undefined && isLoadingPermissions ? (
+ <LogoLoader />
+ ) : (
+ <AuditLogs />
+ )}
+ </div>
+ </div>
)
}