@@ -10,11 +10,12 @@ import {
1010import { parseAsJson , parseAsString , useQueryState } from "nuqs" ;
1111import { useCallback , useMemo } from "react" ;
1212import { Table as TableType } from "@latticexyz/config" ;
13- import { getKeySchema , getKeyTuple } from "@latticexyz/protocol-parser/internal" ;
13+ import { getKeySchema } from "@latticexyz/protocol-parser/internal" ;
1414import {
1515 ColumnDef ,
1616 OnChangeFn ,
1717 PaginationState ,
18+ RowData ,
1819 SortingState ,
1920 flexRender ,
2021 getCoreRowModel ,
@@ -31,9 +32,9 @@ import { cn } from "../../../../../../utils";
3132import { useChain } from "../../../../hooks/useChain" ;
3233import { TData , TDataRow , useTableDataQuery } from "../../../../queries/useTableDataQuery" ;
3334import { indexerForChainId } from "../../../../utils/indexerForChainId" ;
34- import { EditableTableCell } from "./EditableTableCell" ;
3535import { ExportButton } from "./ExportButton" ;
3636import { PAGE_SIZE_OPTIONS } from "./consts" ;
37+ import { defaultColumn } from "./defaultColumn" ;
3738import { usePaginationState } from "./hooks/usePaginationState" ;
3839import { useSQLQueryState } from "./hooks/useSQLQueryState" ;
3940import { getLimitOffset } from "./utils/getLimitOffset" ;
@@ -42,6 +43,13 @@ import { typeSortingFn } from "./utils/typeSortingFn";
4243const initialSortingState : SortingState = [ ] ;
4344const initialRows : TData [ "rows" ] = [ ] ;
4445
46+ declare module "@tanstack/react-table" {
47+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
48+ interface TableMeta < TData extends RowData > {
49+ tableConfig ?: TableType ;
50+ }
51+ }
52+
4553type Props = {
4654 table ?: TableType ;
4755 query ?: string ;
@@ -83,7 +91,6 @@ export function TablesViewer({ table, isLiveQuery }: Props) {
8391 const schema = table ?. schema [ name ] ;
8492 const type = schema ?. type ;
8593 const keySchema = getKeySchema ( table ) ;
86-
8794 return {
8895 accessorKey : name ,
8996 header : ( { column } ) => {
@@ -101,27 +108,14 @@ export function TablesViewer({ table, isLiveQuery }: Props) {
101108 ) ;
102109 } ,
103110 sortingFn : ( rowA , rowB , columnId ) => typeSortingFn ( rowA , rowB , columnId , type ) ,
104- cell : ( { row } ) => {
105- const keySchema = getKeySchema ( table ) ;
106- const value = row . getValue ( name ) ;
107- if ( ! table || Object . keys ( keySchema ) . includes ( name ) ) {
108- return value ;
109- }
110-
111- try {
112- const keyTuple = getKeyTuple ( table , row . original as never ) ;
113- return < EditableTableCell name = { name } table = { table } value = { value } keyTuple = { keyTuple } /> ;
114- } catch ( e ) {
115- return value ;
116- }
117- } ,
118111 } ;
119112 } ) ;
120113 } , [ table , tableData ] ) ;
121114
122115 const reactTable = useReactTable ( {
123116 data : tableData ?. rows ?? initialRows ,
124117 columns : tableColumns ,
118+ defaultColumn,
125119 initialState : {
126120 pagination : {
127121 pageSize : pagination . pageSize ,
@@ -142,6 +136,9 @@ export function TablesViewer({ table, isLiveQuery }: Props) {
142136 globalFilter,
143137 pagination,
144138 } ,
139+ meta : {
140+ tableConfig : table ,
141+ } ,
145142 } ) ;
146143
147144 // Pagination is only enabled if the query has a LIMIT and OFFSET that are divisible by the page size
@@ -196,6 +193,7 @@ export function TablesViewer({ table, isLiveQuery }: Props) {
196193 </ TableRow >
197194 ) ) }
198195 </ TableHeader >
196+
199197 < TableBody className = "relative" >
200198 { isLoading && (
201199 < div className = "absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm" >
@@ -204,10 +202,12 @@ export function TablesViewer({ table, isLiveQuery }: Props) {
204202 ) }
205203 { ! isError && reactTable . getRowModel ( ) . rows ?. length ? (
206204 reactTable . getRowModel ( ) . rows . map ( ( row ) => (
207- < TableRow key = { row . id } data-state = { row . getIsSelected ( ) && "selected" } >
208- { row . getVisibleCells ( ) . map ( ( cell ) => (
209- < TableCell key = { cell . id } > { flexRender ( cell . column . columnDef . cell , cell . getContext ( ) ) } </ TableCell >
210- ) ) }
205+ < TableRow key = { row . id } >
206+ { row . getVisibleCells ( ) . map ( ( cell ) => {
207+ return (
208+ < TableCell key = { cell . id } > { flexRender ( cell . column . columnDef . cell , cell . getContext ( ) ) } </ TableCell >
209+ ) ;
210+ } ) }
211211 </ TableRow >
212212 ) )
213213 ) : (
0 commit comments