mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 14:39:25 +08:00
feat: add clearSelection method and handle selection clearing in various hooks
This commit is contained in:
parent
f694522034
commit
da9d2714a4
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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([
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user