fix(collection-manager): infinite recursion (#1608)

* fix(collection-manager): infinite recursion

* fix: ts error
This commit is contained in:
Dunqing 2023-03-29 17:06:33 +08:00 committed by GitHub
parent 92d0eab0cc
commit e6326460b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,17 +88,26 @@ export const useCollectionManager = () => {
type: string | string[] = 'string',
opts?: {
cached?: Record<string, any>;
collectionNames?: string[];
/**
* true
* Array<string>
*/
association?: boolean | string[];
/**
* Max depth of recursion
*/
maxDepth?: number;
},
) => {
const { association = false, cached = {} } = opts || {};
const { association = false, cached = {}, collectionNames = [collectionName], maxDepth = 1 } = opts || {};
if (collectionNames.length - 1 > maxDepth) {
return;
}
// 防止无限循环
if (cached[collectionName]) {
// avoid infinite recursion
return _.cloneDeep(cached[collectionName]);
}
@ -122,7 +131,13 @@ export const useCollectionManager = () => {
...field,
};
if (association && field.target) {
result.children = getCollectionFieldsOptions(field.target, type, { ...opts, cached });
result.children = collectionNames.includes(field.target)
? []
: getCollectionFieldsOptions(field.target, type, {
...opts,
cached,
collectionNames: [...collectionNames, field.target],
});
if (!result.children?.length) {
return null;
}