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,
]);
if (_.isEmpty(storedFilter[uid])) {
block.clearSelection?.();
}
if (doNothingWhenFilterIsEmpty && _.isEmpty(storedFilter[uid])) {
return;
}
@ -1349,6 +1353,7 @@ export const useAssociationFilterBlockProps = () => {
[filterKey]: value,
};
} else {
block.clearSelection?.();
if (block.dataLoadingMode === 'manual') {
return block.clearData();
}
@ -1442,6 +1447,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

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

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: [
{
@ -226,7 +226,11 @@ export const useFilterAPI = () => {
],
};
} else {
block.clearSelection?.();
delete storedFilter[uid];
if (block.dataLoadingMode === 'manual') {
return block.clearData();
}
}
const mergedFilter = mergeFilter([

View File

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