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
This commit is contained in:
xzdry 2022-07-17 17:52:10 +08:00
parent 3f94a694e0
commit da6521324a

View File

@ -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={