mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## What kind of change does this PR introduce? Component update. ## What is the current behaviour? TanStack tables in the repo are split between the shared `TableHeadSort` primitive and the older Studio-local `DataTableColumnHeader` helper, which makes the sorting UI and integration path inconsistent. If you were to just use `DataTableColumnHeader` in `ui-patterns/Table`, you’d get a very different visual result to the `TableHeadSort` UI you see in most other tables. ## What is the new behaviour? Adds a shared `TanStackTableHeadSort` adapter in `ui-patterns/Table`, backed by the existing `TableHeadSort` primitive, and switches the webhook table plus the design-system TanStack demo to that canonical path. `DataTableColumnHeader` stays as a deprecated wrapper for now, Studio gets a lint guard to block new imports of it, and the table docs now point TanStack tables at the shared adapter explicitly. ## To test Check out column sorting on the Platform Webhook endpoint deliveries table.
54 lines
1.1 KiB
TypeScript
54 lines
1.1 KiB
TypeScript
'use client'
|
|
|
|
import { type Column } from '@tanstack/react-table'
|
|
import type { ReactNode } from 'react'
|
|
import { cn, TableHeadSort } from 'ui'
|
|
|
|
interface TanStackTableHeadSortProps<TData, TValue> {
|
|
column: Column<TData, TValue>
|
|
children: ReactNode
|
|
className?: string
|
|
}
|
|
|
|
/**
|
|
* Shared TanStack adapter for the `TableHeadSort` primitive.
|
|
* Prefer this in TanStack tables instead of wiring `TableHeadSort` manually.
|
|
*/
|
|
export const TanStackTableHeadSort = <TData, TValue>({
|
|
column,
|
|
children,
|
|
className,
|
|
}: TanStackTableHeadSortProps<TData, TValue>) => {
|
|
if (!column.getCanSort()) {
|
|
return <div className={cn(className)}>{children}</div>
|
|
}
|
|
|
|
const sort = column.getIsSorted()
|
|
const currentSort = sort ? `${column.id}:${sort}` : ''
|
|
|
|
const handleSortChange = () => {
|
|
if (!sort) {
|
|
column.toggleSorting(false)
|
|
return
|
|
}
|
|
|
|
if (sort === 'asc') {
|
|
column.toggleSorting(true)
|
|
return
|
|
}
|
|
|
|
column.clearSorting()
|
|
}
|
|
|
|
return (
|
|
<TableHeadSort
|
|
column={column.id}
|
|
currentSort={currentSort}
|
|
onSortChange={handleSortChange}
|
|
className={className}
|
|
>
|
|
{children}
|
|
</TableHeadSort>
|
|
)
|
|
}
|