refactor: remove deprecated API

This commit is contained in:
Zeke Zhang 2024-11-01 16:55:09 +08:00
parent a5f93b95fb
commit fee1c2999c
3 changed files with 21 additions and 16 deletions

View File

@ -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 } = {}) => {

View File

@ -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],
);

View File

@ -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<InheritanceCollectionMixin>(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) => {