feat: add clearSelection method and handle selection clearing in various hooks

This commit is contained in:
Zeke Zhang 2025-03-14 13:18:30 +08:00
parent f694522034
commit da9d2714a4
4 changed files with 20 additions and 12 deletions

View File

@ -459,6 +459,10 @@ const useDoFilter = () => {
block.defaultFilter,
]);
if (_.isEmpty(storedFilter[uid])) {
block.clearSelection?.();
}
if (doNothingWhenFilterIsEmpty && _.isEmpty(storedFilter[uid])) {
return;
}
@ -1352,6 +1356,7 @@ export const useAssociationFilterBlockProps = () => {
[filterKey]: value,
};
} else {
block.clearSelection?.();
if (block.dataLoadingMode === 'manual') {
return block.clearData();
}
@ -1402,6 +1407,8 @@ async function doReset({
const target = targets.find((target) => target.uid === block.uid);
if (!target) return;
block.clearSelection?.();
if (block.dataLoadingMode === 'manual') {
return block.clearData();
}

View File

@ -52,6 +52,8 @@ export interface DataBlock {
clearFilter: (uid: string) => void;
/** 将数据区块的数据置为空 */
clearData: () => void;
/** 清除表格的选中项 */
clearSelection?: () => void;
/** 数据区块表中所有的关系字段 */
associatedFields?: CollectionFieldOptions_deprecated[];
/** 数据区块表中所有的外键字段 */
@ -147,17 +149,13 @@ export const DataBlockCollector = ({
clearData() {
this.service.mutate(undefined);
},
clearSelection() {
if (field) {
field.data.clearSelectedRowKeys?.();
}
},
});
}, [
associatedFields,
collection,
dataLoadingMode,
field?.componentProps?.title,
fieldSchema,
params?.filter,
recordDataBlocks,
service,
]);
}, [associatedFields, collection, dataLoadingMode, fieldSchema, params?.filter, recordDataBlocks, service, field]);
useEffect(() => {
if (shouldApplyFilter) addBlockToDataBlocks();

View File

@ -215,7 +215,7 @@ export const useFilterAPI = () => {
// 保留原有的 filter
const storedFilter = block.service.params?.[1]?.filters || {};
if (value !== undefined) {
if (value != null) {
storedFilter[uid] = {
$and: [
{
@ -227,6 +227,9 @@ export const useFilterAPI = () => {
};
} else {
delete storedFilter[uid];
if (block.dataLoadingMode === 'manual') {
return block.clearData();
}
}
const mergedFilter = mergeFilter([

View File

@ -16,7 +16,6 @@ import { findFilterTargets } from '../../../../../block-provider/hooks';
import { DataBlock, useFilterBlock } from '../../../../../filter-provider/FilterProvider';
import { mergeFilter } from '../../../../../filter-provider/utils';
import { removeNullCondition } from '../../../../../schema-component';
import { useCollection } from '../../../../../data-source';
export const useTableBlockProps = () => {
const field = useField<ArrayField>();
@ -121,6 +120,7 @@ export const useTableBlockProps = () => {
const storedFilter = block.service.params?.[1]?.filters || {};
if (selectedRow.includes(record[ctx.rowKey])) {
block.clearSelection?.();
if (block.dataLoadingMode === 'manual') {
return block.clearData();
}