From da6521324aac7a38c0f33e86a7f2f4afd9c7176b Mon Sep 17 00:00:00 2001 From: xzdry Date: Sun, 17 Jul 2022 17:52:10 +0800 Subject: [PATCH] refactor(arco/Table): remove selectedRow state and add rowSelectChange events seletedRow is a confusing property. It actually represents the row you are currently working on. In the case of multiple selections, the selectedRow is the current row regardless of whether the current row is selected or unselected. Although arco provides `selected` to determine if the current row is selected, there is a lot of extra logic required to determine if the selectedRow has a value. And in single selection, `selectedRow` and `selectedRows` can be confusing --- .../arco-lib/src/components/Table/Table.tsx | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/arco-lib/src/components/Table/Table.tsx b/packages/arco-lib/src/components/Table/Table.tsx index 2c4f3ed2..f0e842c4 100644 --- a/packages/arco-lib/src/components/Table/Table.tsx +++ b/packages/arco-lib/src/components/Table/Table.tsx @@ -30,7 +30,6 @@ import { useStateValue } from '../../hooks/useStateValue'; const TableStateSpec = Type.Object({ clickedRow: Type.Optional(Type.Any()), selectedRows: Type.Array(Type.Any()), - selectedRow: Type.Optional(Type.Any()), selectedRowKeys: Type.Array(Type.String()), filterRule: Type.Any(), sortRule: Type.Object({ @@ -157,7 +156,15 @@ export const Table = implementRuntimeComponent({ }, }, styleSlots: ['content'], - events: ['onRowClick', 'onSearch', 'onPageChange', 'onFilter', 'onSort', 'onChange'], + events: [ + 'onRowClick', + 'onSearch', + 'onPageChange', + 'onFilter', + 'onSort', + 'onChange', + 'rowSelectChange', + ], }, })(props => { const { @@ -492,21 +499,12 @@ export const Table = implementRuntimeComponent({ checkCrossPage: checkCrossPage, // This option is required to achieve multi-selection across pages when customizing paging preserveSelectedRowKeys: useCustomPagination ? checkCrossPage : undefined, - onSelect: (selected, record) => { - mergeState({ - selectedRow: selected ? record : undefined, - }); - }, - onSelectAll: () => { - mergeState({ - selectedRow: undefined, - }); - }, onChange(selectedRowKeys, selectedRows) { mergeState({ selectedRowKeys: selectedRowKeys as string[], selectedRows, }); + callbackMap?.rowSelectChange?.(); }, }} onRow={