Skip to content

Commit ee9ac00

Browse files
feat: update deprecated type change (#5725)
* chore: pulling * feat: update deprecated type changes * feat: update deprecated type changes * fix _getInitialState bugs --------- Co-authored-by: Kevin Van Cott <kevinvandy656@gmail.com>
1 parent 7b53352 commit ee9ac00

File tree

35 files changed

+9380
-10604
lines changed

35 files changed

+9380
-10604
lines changed

examples/lit/column-sizing/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class LitTableExample extends LitElement {
132132
${JSON.stringify(
133133
{
134134
columnSizing: table.getState().columnSizing,
135-
columnSizingInfo: table.getState().columnSizingInfo,
135+
columnResizing: table.getState().columnResizing,
136136
},
137137
null,
138138
2,

examples/react/column-resizing-performant/src/main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function App() {
106106
colSizes[`--col-${header.column.id}-size`] = header.column.getSize()
107107
}
108108
return colSizes
109-
}, [table.getState().columnSizingInfo, table.getState().columnSizing])
109+
}, [table.getState().columnResizing, table.getState().columnSizing])
110110

111111
//demo purposes
112112
const [enableMemo, setEnableMemo] = React.useState(true)
@@ -191,7 +191,7 @@ function App() {
191191
))}
192192
</div>
193193
{/* When resizing any column we will render this special memoized version of our table body */}
194-
{table.getState().columnSizingInfo.isResizingColumn && enableMemo ? (
194+
{table.getState().columnResizing.isResizingColumn && enableMemo ? (
195195
<MemoizedTableBody table={table} />
196196
) : (
197197
<TableBody table={table} />

examples/react/column-sizing/src/main.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function App() {
201201
'rtl'
202202
? -1
203203
: 1) *
204-
(table.getState().columnSizingInfo
204+
(table.getState().columnResizing
205205
.deltaOffset ?? 0)
206206
}px)`
207207
: '',
@@ -290,7 +290,7 @@ function App() {
290290
'rtl'
291291
? -1
292292
: 1) *
293-
(table.getState().columnSizingInfo
293+
(table.getState().columnResizing
294294
.deltaOffset ?? 0)
295295
}px)`
296296
: '',
@@ -394,7 +394,7 @@ function App() {
394394
'rtl'
395395
? -1
396396
: 1) *
397-
(table.getState().columnSizingInfo
397+
(table.getState().columnResizing
398398
.deltaOffset ?? 0)
399399
}px)`
400400
: '',
@@ -453,7 +453,7 @@ function App() {
453453
{JSON.stringify(
454454
{
455455
columnSizing: table.getState().columnSizing,
456-
columnSizingInfo: table.getState().columnSizingInfo,
456+
columnResizing: table.getState().columnResizing,
457457
},
458458
null,
459459
2,

examples/react/row-pinning/src/main.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import React, { useEffect } from 'react'
1+
import React from 'react'
22
import ReactDOM from 'react-dom/client'
3-
4-
import './index.css'
5-
63
import {
74
ColumnFiltering,
85
RowExpanding,
@@ -13,11 +10,11 @@ import {
1310
createFilteredRowModel,
1411
createPaginatedRowModel,
1512
flexRender,
13+
tableFeatures,
1614
useTable,
1715
} from '@tanstack/react-table'
1816
import { makeData } from './makeData'
1917
import type { Person } from './makeData'
20-
2118
import type {
2219
Column,
2320
ColumnDef,
@@ -26,6 +23,14 @@ import type {
2623
RowPinningState,
2724
Table,
2825
} from '@tanstack/react-table'
26+
import './index.css'
27+
28+
const _features = tableFeatures({
29+
RowPinning,
30+
RowExpanding,
31+
ColumnFiltering,
32+
RowPagination,
33+
})
2934

3035
function App() {
3136
const rerender = React.useReducer(() => ({}), {})[1]
@@ -43,7 +48,7 @@ function App() {
4348
const [includeParentRows, setIncludeParentRows] = React.useState(false)
4449
const [copyPinnedRows, setCopyPinnedRows] = React.useState(false)
4550

46-
const columns = React.useMemo<Array<ColumnDef<any, Person>>>(
51+
const columns = React.useMemo<Array<ColumnDef<typeof _features, Person>>>(
4752
() => [
4853
{
4954
id: 'pin',
@@ -150,7 +155,7 @@ function App() {
150155
const refreshData = () => setData(() => makeData(1000, 2, 2))
151156

152157
const table = useTable({
153-
_features: { RowPinning, RowExpanding, ColumnFiltering, RowPagination },
158+
_features,
154159
_rowModels: {
155160
Core: createCoreRowModel(),
156161
Filtered: createFilteredRowModel(),
@@ -172,9 +177,9 @@ function App() {
172177
})
173178

174179
// console.log(table.getBottomRows)
175-
useEffect(() => {
176-
console.log(table.getBottomRows())
177-
}, [table.getBottomRows()])
180+
// React.useEffect(() => {
181+
// console.log(table.getBottomRows())
182+
// }, [table.getBottomRows()])
178183

179184
return (
180185
<div className="app">
@@ -216,7 +221,7 @@ function App() {
216221
).map((row) => {
217222
return (
218223
<tr key={row.id}>
219-
{row.getVisibleCells().map((cell) => {
224+
{row.getAllCells().map((cell) => {
220225
return (
221226
<td key={cell.id}>
222227
{flexRender(
@@ -363,8 +368,8 @@ function PinnedRow({
363368
row,
364369
table,
365370
}: {
366-
row: Row<any, any>
367-
table: Table<any, any>
371+
row: Row<typeof _features, Person>
372+
table: Table<typeof _features, Person>
368373
}) {
369374
return (
370375
<tr
@@ -383,7 +388,7 @@ function PinnedRow({
383388
: undefined,
384389
}}
385390
>
386-
{row.getVisibleCells().map((cell) => {
391+
{row.getAllCells().map((cell) => {
387392
return (
388393
<td key={cell.id}>
389394
{flexRender(cell.column.columnDef.cell, cell.getContext())}
@@ -398,8 +403,8 @@ function Filter({
398403
column,
399404
table,
400405
}: {
401-
column: Column<any, any>
402-
table: Table<any>
406+
column: Column<typeof _features, Person>
407+
table: Table<typeof _features, Person>
403408
}) {
404409
const firstValue = table
405410
.getPreFilteredRowModel()

packages/table-core/src/core/table/Tables.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export interface Table_CoreProperties<
106106
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#initialstate)
107107
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
108108
*/
109-
initialState: Partial<TableState<TFeatures>>
109+
initialState: TableState<TFeatures>
110110
/**
111111
* A read-only reference to the table's current options.
112112
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#options)

packages/table-core/src/features/column-filtering/ColumnFiltering.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
table_resetColumnFilters,
1313
table_setColumnFilters,
1414
} from './ColumnFiltering.utils'
15+
import type { TableState } from '../../types/TableState'
1516
import type { CellData, RowData, Updater } from '../../types/type-utils'
1617
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
1718
import type { Table } from '../../types/Table'
@@ -35,7 +36,9 @@ import type {
3536
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)
3637
*/
3738
export const ColumnFiltering: TableFeature = {
38-
_getInitialState: (state): TableState_ColumnFiltering => {
39+
_getInitialState: <TFeatures extends TableFeatures>(
40+
state: TableState<TFeatures>,
41+
): TableState<TFeatures> & TableState_ColumnFiltering => {
3942
return {
4043
columnFilters: [],
4144
...state,
@@ -72,8 +75,6 @@ export const ColumnFiltering: TableFeature = {
7275
table: Table<TFeatures, TData> &
7376
Partial<Table_ColumnFiltering<TFeatures, TData>>,
7477
): void => {
75-
76-
7778
assignAPIs(column, table, [
7879
{
7980
fn: () => column_getAutoFilterFn(column, table),
@@ -110,8 +111,6 @@ export const ColumnFiltering: TableFeature = {
110111
table: Table<TFeatures, TData> &
111112
Partial<Table_ColumnFiltering<TFeatures, TData>>,
112113
): void => {
113-
114-
115114
assignAPIs(table, table, [
116115
{
117116
fn: (updater: Updater<ColumnFiltersState>) =>

packages/table-core/src/features/column-filtering/ColumnFiltering.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ interface ColumnFiltersOptionsBase<
191191
manualFiltering?: boolean
192192
/**
193193
* By default, filtering is done for all rows (max depth of 100), no matter if they are root level parent rows or the child leaf rows of a parent row. Setting this option to `0` will cause filtering to only be applied to the root level parent rows, with all sub-rows remaining unfiltered. Similarly, setting this option to `1` will cause filtering to only be applied to child leaf rows 1 level deep, and so on.
194-
194+
195195
* This is useful for situations where you want a row's entire child hierarchy to be visible regardless of the applied filter.
196196
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-filtering#maxleafrowfilterdepth)
197197
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-filtering)

packages/table-core/src/features/column-grouping/ColumnGrouping.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
table_resetGrouping,
1818
table_setGrouping,
1919
} from './ColumnGrouping.utils'
20+
import type { TableState } from '../../types/TableState'
2021
import type { CellData, RowData } from '../../types/type-utils'
2122
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
2223
import type { Table } from '../../types/Table'
@@ -39,7 +40,9 @@ import type {
3940
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-grouping)
4041
*/
4142
export const ColumnGrouping: TableFeature = {
42-
_getInitialState: (state): TableState_ColumnGrouping => {
43+
_getInitialState: <TFeatures extends TableFeatures>(
44+
state: TableState<TFeatures>,
45+
): TableState<TFeatures> & TableState_ColumnGrouping => {
4346
return {
4447
grouping: [],
4548
...state,

packages/table-core/src/features/column-grouping/ColumnGrouping.types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export interface TableState_ColumnGrouping {
1717
grouping: GroupingState
1818
}
1919

20+
export interface TableState_ColumnGrouping_Unavailable {
21+
/**
22+
* @deprecated Import the `ColumnGrouping` feature to use the column grouping APIs.
23+
*/
24+
grouping: GroupingState
25+
}
26+
2027
export interface AggregationFns {}
2128

2229
export type AggregationFn<

packages/table-core/src/features/column-ordering/ColumnOrdering.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
table_resetColumnOrder,
88
table_setColumnOrder,
99
} from './ColumnOrdering.utils'
10+
import type { TableState } from '../../types/TableState'
1011
import type {
1112
ColumnOrderDefaultOptions,
1213
Column_ColumnOrdering,
@@ -24,7 +25,9 @@ import type { Column } from '../../types/Column'
2425
* @link [Guide](https://tanstack.com/table/v8/docs/guide/column-ordering)
2526
*/
2627
export const ColumnOrdering: TableFeature = {
27-
_getInitialState: (state): TableState_ColumnOrdering => {
28+
_getInitialState: <TFeatures extends TableFeatures>(
29+
state: TableState<TFeatures>,
30+
): TableState<TFeatures> & TableState_ColumnOrdering => {
2831
return {
2932
columnOrder: [],
3033
...state,
@@ -49,22 +52,7 @@ export const ColumnOrdering: TableFeature = {
4952
table: Table<TFeatures, TData> &
5053
Partial<Table_ColumnOrdering<TFeatures, TData>>,
5154
): void => {
52-
// column.getIndex = memo(
53-
// (position) => [
54-
// position,
55-
// _table_getState(table).columnOrder,
56-
// _table_getState(table).columnPinning,
57-
// _table_getState(table).grouping,
58-
// ],
59-
// (position) => column_getIndex(column, table, position),
60-
// getMemoOptions(table.options, 'debugColumns', 'getIndex'),
61-
// )
6255

63-
// column.getIsFirstColumn = (position) =>
64-
// column_getIsFirstColumn(column, table, position)
65-
66-
// column.getIsLastColumn = (position) =>
67-
// column_getIsLastColumn(column, table, position)
6856

6957
assignAPIs(column, table, [
7058
{
@@ -89,10 +77,7 @@ export const ColumnOrdering: TableFeature = {
8977
table: Table<TFeatures, TData> &
9078
Partial<Table_ColumnOrdering<TFeatures, TData>>,
9179
): void => {
92-
// table.setColumnOrder = (updater) => table_setColumnOrder(table, updater)
9380

94-
// table.resetColumnOrder = (defaultState) =>
95-
// table_resetColumnOrder(table, defaultState)
9681

9782
assignAPIs(table, table, [
9883
{

0 commit comments

Comments
 (0)