From b18822aaa9f5348734a890e09f1d3e342914a982 Mon Sep 17 00:00:00 2001 From: Junyi Date: Mon, 23 Oct 2023 00:05:15 +0800 Subject: [PATCH] fix(plugin-workflow): fix cycling association stackoverflow (#2892) --- .../plugin-workflow/src/client/nodes/aggregate.tsx | 1 + .../plugin-workflow/src/client/variable.tsx | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/aggregate.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/aggregate.tsx index e5af50f08..4868250b8 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/aggregate.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/aggregate.tsx @@ -29,6 +29,7 @@ function useAssociatedFields() { .useOptions({ types: [matchToManyField], appends: null, + depth: 4, }) ?.filter(Boolean); return { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx index 9cfd37ae6..b0d5c276c 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx @@ -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, };