Skip to content

Commit

Permalink
Revert "fix(Table): onChange sorter param types (ant-design#36710)"
Browse files Browse the repository at this point in the history
This reverts commit 9e7e32b.
  • Loading branch information
MadCcc authored and gp0119 committed Aug 17, 2022
1 parent b2853dd commit b7c9a6e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface ChangeEventInfo<RecordType> {
total?: number;
};
filters: Record<string, FilterValue | null>;
sorter: SorterResult<RecordType> | SorterResult<RecordType[]>;
sorter: SorterResult<RecordType> | SorterResult<RecordType>[];

filterStates: FilterState<RecordType>[];
sorterStates: SortState<RecordType>[];
Expand Down Expand Up @@ -92,7 +92,7 @@ export interface TableProps<RecordType>
onChange?: (
pagination: TablePaginationConfig,
filters: Record<string, FilterValue | null>,
sorter: SorterResult<RecordType> | SorterResult<RecordType[]>,
sorter: SorterResult<RecordType> | SorterResult<RecordType>[],
extra: TableCurrentDataSource<RecordType>,
) => void;
rowSelection?: TableRowSelection<RecordType>;
Expand Down Expand Up @@ -263,7 +263,7 @@ function InternalTable<RecordType extends object = any>(

// ============================ Sorter =============================
const onSorterChange = (
sorter: SorterResult<RecordType> | SorterResult<RecordType[]>,
sorter: SorterResult<RecordType> | SorterResult<RecordType>[],
sorterStates: SortState<RecordType>[],
) => {
triggerOnChange(
Expand Down
6 changes: 0 additions & 6 deletions components/table/__tests__/type.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ describe('Table.typescript', () => {
const table = <Table<RecordType> dataSource={[{ key: 'Bamboo' }]} />;
expect(table).toBeTruthy();
});

it('Sorter types', () => {
const table = <Table onChange={(_pagination, _filters, sorter) => sorter.field} />;

expect(table).toBeTruthy();
});
});

describe('Table.typescript types', () => {
Expand Down
12 changes: 8 additions & 4 deletions components/table/hooks/useSorter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function stateToInfo<RecordType>(sorterStates: SortState<RecordType>) {

function generateSorterInfo<RecordType>(
sorterStates: SortState<RecordType>[],
): SorterResult<RecordType> | SorterResult<RecordType[]> {
): SorterResult<RecordType> | SorterResult<RecordType>[] {
const list = sorterStates.filter(({ sortOrder }) => sortOrder).map(stateToInfo);

// =========== Legacy compatible support ===========
Expand All @@ -259,7 +259,11 @@ function generateSorterInfo<RecordType>(
};
}

return list[0] || {};
if (list.length <= 1) {
return list[0] || {};
}

return list;
}

export function getSortData<RecordType>(
Expand Down Expand Up @@ -320,7 +324,7 @@ interface SorterConfig<RecordType> {
prefixCls: string;
mergedColumns: ColumnsType<RecordType>;
onSorterChange: (
sorterResult: SorterResult<RecordType> | SorterResult<RecordType[]>,
sorterResult: SorterResult<RecordType> | SorterResult<RecordType>[],
sortStates: SortState<RecordType>[],
) => void;
sortDirections: SortOrder[];
Expand All @@ -339,7 +343,7 @@ export default function useFilterSorter<RecordType>({
TransformColumns<RecordType>,
SortState<RecordType>[],
ColumnTitleProps<RecordType>,
() => SorterResult<RecordType> | SorterResult<RecordType[]>,
() => SorterResult<RecordType> | SorterResult<RecordType>[],
] {
const [sortStates, setSortStates] = React.useState<SortState<RecordType>[]>(
collectSortStates(mergedColumns, true),
Expand Down

0 comments on commit b7c9a6e

Please sign in to comment.