fix: collectionFieldsOptions cannot get all fields (#1588)

This commit is contained in:
Dunqing 2023-03-21 16:56:05 +08:00 committed by GitHub
parent 50183b065d
commit 0d36caf1c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,12 +83,11 @@ export const useCollectionManager = () => {
};
// 缓存下面已经获取的 options防止无限循环
const cachedOptions = {};
const getCollectionFieldsOptions = (
collectionName: string,
type: string | string[] = 'string',
opts?: {
cached?: Record<string, any>;
/**
* true
* Array<string>
@ -96,12 +95,13 @@ export const useCollectionManager = () => {
association?: boolean | string[];
},
) => {
const { association = false, cached = {} } = opts || {};
// 防止无限循环
if (cachedOptions[collectionName]) {
return _.cloneDeep(cachedOptions[collectionName]);
if (cached[collectionName]) {
return _.cloneDeep(cached[collectionName]);
}
const { association = false } = opts || {};
if (typeof type === 'string') {
type = [type];
}
@ -122,7 +122,7 @@ export const useCollectionManager = () => {
...field,
};
if (association && field.target) {
result.children = getCollectionFieldsOptions(field.target, type, opts);
result.children = getCollectionFieldsOptions(field.target, type, { ...opts, cached });
if (!result.children?.length) {
return null;
}
@ -132,7 +132,7 @@ export const useCollectionManager = () => {
// 过滤 map 产生为 null 的数据
.filter(Boolean);
cachedOptions[collectionName] = options;
cached[collectionName] = options;
return options;
};