diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index 06ce540cc9..3a59c261cf 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -439,15 +439,15 @@ export const updateFilterTargets = (fieldSchema, targets: FilterTarget['targets' const useDoFilter = () => { const form = useForm(); const { getDataBlocks } = useFilterBlock(); - const { getCollectionJoinField } = useCollectionManager_deprecated(); + const cm = useCollectionManager(); const { getOperators } = useOperators(); const fieldSchema = useFieldSchema(); const { name } = useCollection(); const { targets = [], uid } = useMemo(() => findFilterTargets(fieldSchema), [fieldSchema]); const getFilterFromCurrentForm = useCallback(() => { - return removeNullCondition(transformToFilter(form.values, getOperators(), getCollectionJoinField, name)); - }, [form.values, getCollectionJoinField, getOperators, name]); + return removeNullCondition(transformToFilter(form.values, getOperators(), cm.getCollectionField.bind(cm), name)); + }, [form.values, cm, getOperators, name]); const doFilter = useCallback( async ({ doNothingWhenFilterIsEmpty = false } = {}) => { diff --git a/packages/core/client/src/filter-provider/FilterProvider.tsx b/packages/core/client/src/filter-provider/FilterProvider.tsx index d103260af6..955e6ee99d 100644 --- a/packages/core/client/src/filter-provider/FilterProvider.tsx +++ b/packages/core/client/src/filter-provider/FilterProvider.tsx @@ -8,7 +8,7 @@ */ import { useField, useFieldSchema } from '@formily/react'; -import _, { uniqBy } from 'lodash'; +import _ from 'lodash'; import { CollectionFieldOptions_deprecated } from '../collection-manager'; import { Collection } from '../data-source/collection/Collection'; import { useCollection } from '../data-source/collection/CollectionProvider'; @@ -203,8 +203,8 @@ export const useFilterBlock = () => { Object.assign(existingBlock, block); return; } - // 由于 setDataBlocks 是异步操作,所以上面的 existingBlock 在判断时有可能用的是旧的 dataBlocks,所以下面还需要根据 uid 进行去重操作 - ctx?.setDataBlocks((prev) => uniqBy([...prev, block], 'uid')); + + ctx?.setDataBlocks((prev) => [...prev, block]); }, [ctx], ); diff --git a/packages/core/client/src/filter-provider/utils.ts b/packages/core/client/src/filter-provider/utils.ts index e59fbf16af..9af9c7dead 100644 --- a/packages/core/client/src/filter-provider/utils.ts +++ b/packages/core/client/src/filter-provider/utils.ts @@ -12,14 +12,10 @@ import { flatten, getValuesByPath } from '@nocobase/utils/client'; import _ from 'lodash'; import { useCallback, useEffect, useState } from 'react'; import { FilterTarget, findFilterTargets } from '../block-provider/hooks'; -import { - CollectionFieldOptions_deprecated, - FieldOptions, - useCollectionManager_deprecated, - useCollection_deprecated, -} from '../collection-manager'; +import { CollectionFieldOptions_deprecated, FieldOptions, InheritanceCollectionMixin } from '../collection-manager'; import { Collection } from '../data-source/collection/Collection'; import { useCollection } from '../data-source/collection/CollectionProvider'; +import { useDataSourceManager } from '../data-source/data-source/DataSourceManagerProvider'; import { removeNullCondition } from '../schema-component'; import { DataBlock, useFilterBlock } from './FilterProvider'; @@ -65,10 +61,21 @@ export const getSupportFieldsByForeignKey = (filterBlockCollection: Collection, * @returns */ export const useSupportedBlocks = (filterBlockType: FilterBlockType) => { + const dm = useDataSourceManager(); const { getDataBlocks } = useFilterBlock(); const fieldSchema = useFieldSchema(); const collection = useCollection(); - const { getAllCollectionsInheritChain } = useCollectionManager_deprecated(); + + // 获取当前 collection 继承链路上的所有 collection + const getAllCollectionsInheritChain = useCallback( + (collectionName: string, customDataSource?: string) => { + return dm + ?.getDataSource(customDataSource) + ?.collectionManager?.getCollection(collectionName) + ?.getAllCollectionsInheritChain(); + }, + [dm], + ); // Form 和 Collapse 仅支持同表的数据区块 if (filterBlockType === FilterBlockType.FORM || filterBlockType === FilterBlockType.COLLAPSE) { @@ -168,9 +175,7 @@ export const transformToFilter = ( }; export const useAssociatedFields = () => { - const { fields } = useCollection_deprecated(); - - return fields.filter((field) => isAssocField(field)) || []; + return useCollection()?.fields.filter((field) => isAssocField(field)) || []; }; export const isAssocField = (field?: FieldOptions) => {