fix: handle null value check and clear data in manual loading mode (#6460)

* fix: handle null value check and clear data in manual loading mode

* fix: add clearSelection method and invoke it in relevant places
This commit is contained in:
Zeke Zhang 2025-03-14 13:19:23 +08:00 committed by GitHub
parent 3b1f016256
commit 4269ff7412
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 2 deletions

View File

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

View File

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

View File

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

View File

@ -141,6 +141,7 @@ export const useTableBlockProps = () => {
const storedFilter = block.service.params?.[1]?.filters || {}; const storedFilter = block.service.params?.[1]?.filters || {};
if (selectedRow.includes(record[tableBlockContextBasicValue.rowKey])) { if (selectedRow.includes(record[tableBlockContextBasicValue.rowKey])) {
block.clearSelection?.();
if (block.dataLoadingMode === 'manual') { if (block.dataLoadingMode === 'manual') {
return block.clearData(); return block.clearData();
} }