1
+ import * as React from 'react' ;
1
2
import CaretDownOutlined from '@ant-design/icons/CaretDownOutlined' ;
2
3
import CaretUpOutlined from '@ant-design/icons/CaretUpOutlined' ;
3
4
import classNames from 'classnames' ;
4
5
import KeyCode from 'rc-util/lib/KeyCode' ;
5
- import * as React from 'react' ;
6
+
6
7
import type { TooltipProps } from '../../tooltip' ;
7
8
import Tooltip from '../../tooltip' ;
8
9
import type {
@@ -257,21 +258,26 @@ function injectSorter<RecordType>(
257
258
} ) ;
258
259
}
259
260
260
- function stateToInfo < RecordType > ( sorterStates : SortState < RecordType > ) {
261
+ const stateToInfo = < RecordType extends any > (
262
+ sorterStates : SortState < RecordType > ,
263
+ ) : SorterResult < RecordType > => {
261
264
const { column, sortOrder } = sorterStates ;
262
265
return { column, order : sortOrder , field : column . dataIndex , columnKey : column . key } ;
263
- }
266
+ } ;
264
267
265
268
function generateSorterInfo < RecordType > (
266
269
sorterStates : SortState < RecordType > [ ] ,
267
270
) : SorterResult < RecordType > | SorterResult < RecordType > [ ] {
268
- const list = sorterStates . filter ( ( { sortOrder } ) => sortOrder ) . map ( stateToInfo ) ;
271
+ const list = sorterStates
272
+ . filter ( ( { sortOrder } ) => sortOrder )
273
+ . map < SorterResult < RecordType > > ( stateToInfo ) ;
269
274
270
275
// =========== Legacy compatible support ===========
271
276
// https://github.com/ant-design/ant-design/pull/19226
272
277
if ( list . length === 0 && sorterStates . length ) {
278
+ const lastIndex = sorterStates . length - 1 ;
273
279
return {
274
- ...stateToInfo ( sorterStates [ sorterStates . length - 1 ] ) ,
280
+ ...stateToInfo ( sorterStates [ lastIndex ] ) ,
275
281
column : undefined ,
276
282
} ;
277
283
}
@@ -366,7 +372,7 @@ export default function useFilterSorter<RecordType>({
366
372
collectSortStates ( mergedColumns , true ) ,
367
373
) ;
368
374
369
- const mergedSorterStates = React . useMemo ( ( ) => {
375
+ const mergedSorterStates = React . useMemo < SortState < RecordType > [ ] > ( ( ) => {
370
376
let validate = true ;
371
377
const collectedStates = collectSortStates ( mergedColumns , false ) ;
372
378
@@ -426,9 +432,8 @@ export default function useFilterSorter<RecordType>({
426
432
} ;
427
433
} , [ mergedSorterStates ] ) ;
428
434
429
- function triggerSorter ( sortState : SortState < RecordType > ) {
430
- let newSorterStates ;
431
-
435
+ const triggerSorter = ( sortState : SortState < RecordType > ) => {
436
+ let newSorterStates : SortState < RecordType > [ ] ;
432
437
if (
433
438
sortState . multiplePriority === false ||
434
439
! mergedSorterStates . length ||
@@ -441,10 +446,9 @@ export default function useFilterSorter<RecordType>({
441
446
sortState ,
442
447
] ;
443
448
}
444
-
445
449
setSortStates ( newSorterStates ) ;
446
450
onSorterChange ( generateSorterInfo ( newSorterStates ) , newSorterStates ) ;
447
- }
451
+ } ;
448
452
449
453
const transformColumns = ( innerColumns : ColumnsType < RecordType > ) =>
450
454
injectSorter (
0 commit comments