fix: drop repeated "Connect data blocks" (#1763)

This commit is contained in:
black 2023-05-02 17:05:12 +08:00 committed by GitHub
parent 03f845246e
commit cba7de55d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ import { SharedFilter, mergeFilter } from '../block-provider/SharedFilterProvide
import { CollectionFieldOptions, useCollection } from '../collection-manager'; import { CollectionFieldOptions, useCollection } from '../collection-manager';
import { removeNullCondition } from '../schema-component'; import { removeNullCondition } from '../schema-component';
import { useAssociatedFields } from './utils'; import { useAssociatedFields } from './utils';
import { uniqBy } from 'lodash';
type Collection = ReturnType<typeof useCollection>; type Collection = ReturnType<typeof useCollection>;
@ -133,8 +134,8 @@ export const useFilterBlock = () => {
existingBlock.defaultFilter = block.defaultFilter; existingBlock.defaultFilter = block.defaultFilter;
return; return;
} }
// 由于 setDataBlocks 是异步操作,所以上面的 existingBlock 在判断时有可能用的是旧的 dataBlocks,所以下面还需要根据 uid 进行去重操作
setDataBlocks((prev) => [...prev, block]); setDataBlocks((prev) => uniqBy([...prev, block], 'uid'));
}; };
const getDataBlocks = () => dataBlocks; const getDataBlocks = () => dataBlocks;
const removeDataBlock = (uid: string) => { const removeDataBlock = (uid: string) => {