fix(plugin-workflow): fix cycling association stackoverflow (#2892)

This commit is contained in:
Junyi 2023-10-23 00:05:15 +08:00 committed by GitHub
parent f51c06e7b8
commit b18822aaa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -29,6 +29,7 @@ function useAssociatedFields() {
.useOptions({
types: [matchToManyField],
appends: null,
depth: 4,
})
?.filter(Boolean);
return {

View File

@ -30,6 +30,7 @@ export type OptionsOfUseVariableOptions = {
children?: string;
};
appends?: string[] | null;
depth?: number;
};
export const defaultFieldNames = { label: 'label', value: 'value', children: 'children' } as const;
@ -167,17 +168,20 @@ function getNextAppends(field, appends: string[] | null): string[] | null {
return appends.filter((item) => item.startsWith(fieldPrefix)).map((item) => item.replace(fieldPrefix, ''));
}
function filterTypedFields({ fields, types, appends, compile, getCollectionFields }) {
function filterTypedFields({ fields, types, appends, depth = 1, compile, getCollectionFields }) {
return fields.filter((field) => {
const match = types?.length ? types.some((type) => matchFieldType(field, type)) : true;
if (isAssociationField(field)) {
if (appends === null) {
if (!depth) {
return false;
}
return (
match ||
filterTypedFields({
fields: getNormalizedFields(field.target, { compile, getCollectionFields }),
types,
// depth: depth - 1,
depth: depth - 1,
appends,
compile,
getCollectionFields,
@ -286,6 +290,7 @@ function loadChildren(option) {
collection: option.field.target,
types: option.types,
appends,
depth: option.depth - 1,
...this,
});
option.loadChildren = null;
@ -306,6 +311,7 @@ export function getCollectionFieldOptions(options): VariableOption[] {
collection,
types,
appends = [],
depth = 1,
compile,
getCollectionFields,
fieldNames = defaultFieldNames,
@ -317,7 +323,7 @@ export function getCollectionFieldOptions(options): VariableOption[] {
const result: VariableOption[] = filterTypedFields({
fields: computedFields,
types,
// depth,
depth,
appends,
compile,
getCollectionFields,
@ -335,7 +341,7 @@ export function getCollectionFieldOptions(options): VariableOption[] {
isLeaf,
loadChildren: isLeaf ? null : boundLoadChildren,
field,
// depth,
depth,
appends,
types,
};