Skip to content

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

Joshen/debug 147 add horizontal scroll to unified logs UI (#47111)

Joshen Limdc5633aee259
diff --git a/apps/studio/components/ui/DataTable/DataTableInfinite.tsx b/apps/studio/components/ui/DataTable/DataTableInfinite.tsx
index 9ccdb0b0c08..c7a774c0e7c 100644
--- a/apps/studio/components/ui/DataTable/DataTableInfinite.tsx
+++ b/apps/studio/components/ui/DataTable/DataTableInfinite.tsx
@@ -4,16 +4,18 @@ import { flexRender } from '@tanstack/react-table'
import { LoaderCircle } from 'lucide-react'
import { useQueryState } from 'nuqs'
import { Fragment, UIEvent, useCallback, useRef } from 'react'
-import { Button, cn } from 'ui'
+import { Button, cn, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
import { ShimmeringLoader } from 'ui-patterns'
-import AlertError from '../AlertError'
+import { AlertError } from '../AlertError'
import { formatCompactNumber } from './DataTable.utils'
import { useDataTable } from './providers/DataTableProvider'
-import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from './Table'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
+const TableRowClassName = 'border-b group data-[state=selected]:bg-muted hover:bg-surface-200'
+const TableCellClassName = 'text-xs py-1! p-2 *:[[role=checkbox]]:translate-y-[2px] truncate'
+
// TODO: add a possible chartGroupBy
export interface DataTableInfiniteProps<TData, TValue, _TMeta> {
columns: ColumnDef<TData, TValue>[]
@@ -73,151 +75,187 @@ export function DataTableInfinite<TData, TValue, TMeta>({
)
return (
- <Table
- ref={tableRef}
- onScroll={onScroll}
- className={cn(
- !isLoading && rows.length === 0 && 'h-full',
- isLoading && '[mask-image:linear-gradient(to_bottom,black_70%,transparent_100%)]'
- )}
- >
- <TableHeader>
- <TableRow className="bg-surface-75">
- {headers.map((header) => {
- const sort = header.column.getIsSorted()
- const canResize = header.column.getCanResize()
- const onResize = header.getResizeHandler()
- const headerClassName = (header.column.columnDef.meta as any)?.headerClassName
+ <>
+ <Table
+ ref={tableRef}
+ containerProps={{
+ onScroll,
+ className: 'h-full w-full overflow-auto caption-bottom text-sm @container',
+ }}
+ className={cn(
+ !isLoading && rows.length === 0 && 'h-full',
+ isLoading && '[mask-image:linear-gradient(to_bottom,black_70%,transparent_100%)]'
+ )}
+ >
+ <TableHeader className="sticky top-0 z-1">
+ <TableRow className={cn(TableRowClassName, 'bg-surface-75')}>
+ {headers.map((header) => {
+ const sort = header.column.getIsSorted()
+ const canResize = header.column.getCanResize()
+ const onResize = header.getResizeHandler()
+ const headerClassName = (header.column.columnDef.meta as any)?.headerClassName
- return (
- <TableHead
- key={header.id}
- id={header.id}
- className={cn('w-full', headerClassName)}
- aria-sort={sort === 'asc' ? 'ascending' : sort === 'desc' ? 'descending' : 'none'}
- >
- {header.isPlaceholder
- ? null
- : flexRender(header.column.columnDef.header, header.getContext())}
- {canResize && (
- <div
- onDoubleClick={() => header.column.resetSize()}
- onMouseDown={onResize}
- onTouchStart={onResize}
- className={cn(
- 'user-select-none absolute -right-2 top-0 z-10 flex h-full w-4 cursor-col-resize touch-none justify-center',
- 'before:absolute before:inset-y-0 before:w-px before:translate-x-px before:bg-border'
- )}
- />
- )}
- </TableHead>
- )
- })}
- </TableRow>
- </TableHeader>
+ return (
+ <TableHead
+ key={header.id}
+ id={header.id}
+ className={cn(
+ 'w-full text-xs! font-normal! text-foreground-lighter font-mono',
+ 'relative select-none truncate [&>.cursor-col-resize]:last:opacity-0',
+ 'text-muted-foreground h-9 px-2 text-left align-middle',
+ '[&:has([role=checkbox])]:pr-0 *:[[role=checkbox]]:translate-y-[2px]',
+ headerClassName
+ )}
+ aria-sort={sort === 'asc' ? 'ascending' : sort === 'desc' ? 'descending' : 'none'}
+ >
+ {header.isPlaceholder
+ ? null
+ : flexRender(header.column.columnDef.header, header.getContext())}
+ {canResize && (
+ <div
+ onDoubleClick={() => header.column.resetSize()}
+ onMouseDown={onResize}
+ onTouchStart={onResize}
+ className={cn(
+ 'user-select-none absolute -right-2 top-0 z-10 flex h-full w-4 cursor-col-resize touch-none justify-center',
+ 'before:absolute before:inset-y-0 before:w-px before:translate-x-px before:bg-border'
+ )}
+ />
+ )}
+ </TableHead>
+ )
+ })}
+ </TableRow>
+ </TableHeader>
- <TableBody
- id="content"
- tabIndex={-1}
- // REMINDER: avoids scroll (skipping the table header) when using skip to content
- style={{ scrollMarginTop: 'calc(var(--top-bar-height))' }}
- >
- {rows.length ? (
- rows.map((row) => (
- // REMINDER: if we want to add arrow navigation https://github.com/TanStack/table/discussions/2752#discussioncomment-192558
- <DataTableRow
- key={row.id}
- row={row}
- table={table}
- searchParamsParser={searchParamsParser}
- selected={row.id === openRowId}
- onSelect={() => setOpenRowId(row.id === openRowId ? undefined : row.id)}
- />
- ))
- ) : isLoading ? (
- <Fragment>
- {new Array(15).fill(0).map((_, x) => (
- <TableRow
- key={x}
- className="h-[30px] hover:!bg-transparent [&>td]:group-hover:!bg-transparent"
- >
- {table.getAllLeafColumns().map((col, idx) => (
- <TableCell key={col.id}>
- <ShimmeringLoader className={cn('py-2', idx % 2 === 0 && 'opacity-50')} />
- </TableCell>
- ))}
+ <TableBody
+ id="content"
+ tabIndex={-1}
+ className={cn(
+ 'transition-colors outline-none focus-visible:outline-1 focus-visible:-outline-offset-1 focus-visible:outline-primary'
+ )}
+ // REMINDER: avoids scroll (skipping the table header) when using skip to content
+ style={{ scrollMarginTop: 'calc(var(--top-bar-height))' }}
+ >
+ {rows.length ? (
+ rows.map((row) => (
+ // REMINDER: if we want to add arrow navigation https://github.com/TanStack/table/discussions/2752#discussioncomment-192558
+ <DataTableRow
+ key={row.id}
+ row={row}
+ table={table}
+ searchParamsParser={searchParamsParser}
+ selected={row.id === openRowId}
+ onSelect={() => setOpenRowId(row.id === openRowId ? undefined : row.id)}
+ />
+ ))
+ ) : isLoading ? (
+ <Fragment>
+ {new Array(15).fill(0).map((_, x) => (
+ <TableRow
+ key={x}
+ className={cn(
+ TableRowClassName,
+ 'h-[30px] hover:bg-transparent [&>td]:group-hover:!bg-transparent'
+ )}
+ >
+ {table.getAllLeafColumns().map((col, idx) => (
+ <TableCell key={col.id} className={TableCellClassName}>
+ <ShimmeringLoader className={cn('py-2', idx % 2 === 0 && 'opacity-50')} />
+ </TableCell>
+ ))}
+ </TableRow>
+ ))}
+ </Fragment>
+ ) : isError ? (
+ <Fragment>
+ <TableRow className={cn(TableRowClassName, 'hover:bg-transparent h-full')}>
+ <TableCell
+ colSpan={columns.length}
+ className={cn(TableCellClassName, 'text-center')}
+ >
+ <div className="flex flex-col items-start justify-start h-full gap-3 px-4 pt-4">
+ <AlertError
+ error={error}
+ className="text-left"
+ subject="Failed to retrieve logs"
+ />
+ </div>
+ </TableCell>
</TableRow>
- ))}
- </Fragment>
- ) : isError ? (
- <Fragment>
- <TableRow className="hover:bg-transparent h-full">
- <TableCell colSpan={columns.length} className="text-center">
- <div className="flex flex-col items-start justify-start h-full gap-3 px-4 pt-4">
- <AlertError
- error={error}
- className="text-left"
- subject="Failed to retrieve logs"
- />
- </div>
- </TableCell>
- </TableRow>
- </Fragment>
- ) : (
- <Fragment>
- <TableRow className="hover:bg-transparent h-full">
- <TableCell colSpan={columns.length} className="text-center">
- <div className="flex flex-col items-center justify-center h-full gap-3">
- <p className="text-foreground-light text-sm">No results found</p>
+ </Fragment>
+ ) : (
+ <Fragment>
+ <TableRow className={cn(TableRowClassName, 'hover:bg-transparent h-full')}>
+ <TableCell
+ colSpan={columns.length}
+ className={cn(TableCellClassName, 'text-center')}
+ >
+ <div className="flex flex-col items-center justify-center h-full gap-3">
+ <p className="text-foreground-light text-sm">No results found</p>
+ </div>
+ </TableCell>
+ </TableRow>
+ </Fragment>
+ )}
+
+ {/* Only show load more section if we have rows OR if we're not in initial loading state */}
+ {(rows.length > 0 || (!isLoading && !rows.length)) && (
+ <TableRow
+ className={cn(
+ TableRowClassName,
+ 'hover:bg-transparent data-[state=selected]:bg-transparent'
+ )}
+ >
+ <TableCell colSpan={columns.length} className="text-xs p-0! overflow-visible">
+ <div className="sticky left-0 w-[100cqw] flex flex-col items-center gap-2 py-2 text-center">
+ {hasNextPage || isFetching ? (
+ <>
+ <Button
+ disabled={isFetching}
+ onClick={() => fetchNextPage()}
+ size="tiny"
+ variant="default"
+ icon={
+ isFetching ? <LoaderCircle className="mr-2 h-4 w-4 animate-spin" /> : null
+ }
+ >
+ Load more
+ </Button>
+ <p className="text-xs text-foreground-lighter">
+ Showing{' '}
+ <span className="font-mono font-medium">
+ {formatCompactNumber(totalRowsFetched)}
+ </span>{' '}
+ of{' '}
+ <span className="font-mono font-medium">
+ {formatCompactNumber(totalRows)}
+ </span>{' '}
+ rows
+ </p>
+ </>
+ ) : (
+ rows.length > 0 && (
+ <p className="text-xs text-foreground-lighter">
+ No more data to load (
+ <span className="font-mono font-medium">
+ {formatCompactNumber(filterRows)}
+ </span>{' '}
+ of{' '}
+ <span className="font-mono font-medium">
+ {formatCompactNumber(totalRows)}
+ </span>{' '}
+ rows)
+ </p>
+ )
+ )}
</div>
</TableCell>
</TableRow>
- </Fragment>
- )}
-
- {/* Only show load more section if we have rows OR if we're not in initial loading state */}
- {(rows.length > 0 || (!isLoading && !rows.length)) && (
- <TableRow className="hover:bg-transparent data-[state=selected]:bg-transparent">
- <TableCell colSpan={columns.length} className="text-center py-2!">
- {hasNextPage || isFetching ? (
- <div className="flex flex-col items-center gap-2">
- <Button
- disabled={isFetching}
- onClick={() => fetchNextPage()}
- size="small"
- variant="default"
- icon={
- isFetching ? <LoaderCircle className="mr-2 h-4 w-4 animate-spin" /> : null
- }
- >
- Load more
- </Button>
- <p className="text-xs text-foreground-lighter">
- Showing{' '}
- <span className="font-mono font-medium">
- {formatCompactNumber(totalRowsFetched)}
- </span>{' '}
- of{' '}
- <span className="font-mono font-medium">{formatCompactNumber(totalRows)}</span>{' '}
- rows
- </p>
- </div>
- ) : (
- rows.length > 0 && (
- <p className="text-xs text-foreground-lighter">
- No more data to load (
- <span className="font-mono font-medium">{formatCompactNumber(filterRows)}</span>{' '}
- of{' '}
- <span className="font-mono font-medium">{formatCompactNumber(totalRows)}</span>{' '}
- rows)
- </p>
- )
- )}
- </TableCell>
- </TableRow>
- )}
- </TableBody>
- </Table>
+ )}
+ </TableBody>
+ </Table>
+ </>
)
}
@@ -256,12 +294,12 @@ function DataTableRow<TData>({
onSelect()
}
}}
- className={cn(rowClassName)}
+ className={cn(TableRowClassName, rowClassName)}
>
{cells.map((cell) => {
const cellClassName = (cell.column.columnDef.meta as any)?.cellClassName
return (
- <TableCell key={cell.id} className={cn(cellClassName)}>
+ <TableCell key={cell.id} className={cn(TableCellClassName, cellClassName)}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
)
diff --git a/apps/studio/components/ui/DataTable/Table.tsx b/apps/studio/components/ui/DataTable/Table.tsx
deleted file mode 100644
index 9f81520bbfe..00000000000
--- a/apps/studio/components/ui/DataTable/Table.tsx
+++ /dev/null
@@ -1,108 +0,0 @@
-import { ComponentPropsWithRef, forwardRef } from 'react'
-import { cn } from 'ui'
-import {
- Table as ShadcnTable,
- TableBody as ShadcnTableBody,
- TableCaption as ShadcnTableCaption,
- TableCell as ShadcnTableCell,
- TableFooter as ShadcnTableFooter,
- TableHead as ShadcnTableHead,
- TableHeader as ShadcnTableHeader,
- TableRow as ShadcnTableRow,
-} from 'ui/src/components/shadcn/ui/table'
-
-// Only create a custom component for Table with the added props
-export const Table = forwardRef<HTMLTableElement, ComponentPropsWithRef<typeof ShadcnTable>>(
- ({ className, onScroll, ...props }, ref) => (
- <ShadcnTable
- ref={ref}
- {...props}
- className={cn(className)}
- containerProps={{
- onScroll,
- className: 'h-full w-full overflow-auto caption-bottom text-sm [&>table]:table-fixed',
- }}
- />
- )
-)
-Table.displayName = 'Table'
-
-export const TableHeader = forwardRef<
- HTMLTableSectionElement,
- ComponentPropsWithRef<typeof ShadcnTableHeader>
->(({ className, ...props }, ref) => (
- <ShadcnTableHeader ref={ref} className={cn('sticky top-0 z-1', className)} {...props} />
-))
-TableHeader.displayName = 'TableHeader'
-
-export const TableBody = forwardRef<
- HTMLTableSectionElement,
- ComponentPropsWithRef<typeof ShadcnTableBody>
->(({ className, ...props }, ref) => (
- <ShadcnTableBody
- ref={ref}
- {...props}
- className={cn(
- 'transition-colors outline-none focus-visible:outline-1 focus-visible:-outline-offset-1 focus-visible:outline-primary',
- className
- )}
- />
-))
-TableBody.displayName = 'TableBody'
-
-export const TableFooter = forwardRef<
- HTMLTableSectionElement,
- ComponentPropsWithRef<typeof ShadcnTableFooter>
->(({ className, ...props }, ref) => (
- <ShadcnTableFooter ref={ref} className={cn('text-primary-foreground', className)} {...props} />
-))
-TableFooter.displayName = 'TableFooter'
-
-export const TableRow = forwardRef<
- HTMLTableRowElement,
- ComponentPropsWithRef<typeof ShadcnTableRow>
->(({ className, ...props }, ref) => (
- <ShadcnTableRow
- ref={ref}
- className={cn('bg-background hover:bg-surface-100 border-b-0', className)}
- {...props}
- />
-))
-TableRow.displayName = 'TableRow'
-
-export const TableHead = forwardRef<
- HTMLTableCellElement,
- ComponentPropsWithRef<typeof ShadcnTableHead>
->(({ className, ...props }, ref) => (
- <ShadcnTableHead
- ref={ref}
- className={cn(
- 'text-xs! font-normal! text-foreground-lighter font-mono',
- 'relative select-none truncate [&>.cursor-col-resize]:last:opacity-0',
- 'text-muted-foreground h-9 px-2 text-left align-middle [&:has([role=checkbox])]:pr-0 *:[[role=checkbox]]:translate-y-[2px]',
- className
- )}
- {...props}
- />
-))
-TableHead.displayName = 'TableHead'
-
-export const TableCell = forwardRef<
- HTMLTableCellElement,
- ComponentPropsWithRef<typeof ShadcnTableCell>
->(({ className, ...props }, ref) => (
- <ShadcnTableCell
- ref={ref}
- className={cn('text-xs py-1! p-2 *:[[role=checkbox]]:translate-y-[2px] truncate', className)}
- {...props}
- />
-))
-TableCell.displayName = 'TableCell'
-
-export const TableCaption = forwardRef<
- HTMLTableCaptionElement,
- ComponentPropsWithRef<typeof ShadcnTableCaption>
->(({ className, ...props }, ref) => (
- <ShadcnTableCaption ref={ref} className={cn('text-sm', className)} {...props} />
-))
-TableCaption.displayName = 'TableCaption'