From 5cb4fb50962707a5a06686bf59dd153971d83dd9 Mon Sep 17 00:00:00 2001 From: Junyi Date: Wed, 4 Sep 2024 10:35:18 +0800 Subject: [PATCH] fix(plugin-workflow): fix missed fields in variable (#5187) --- .../@nocobase/plugin-workflow/src/client/variable.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx index 07d855c1dd..30ed780432 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx @@ -383,7 +383,7 @@ function getNormalizedFields(collectionName, { compile, getCollectionFields }) { const fkFields: any[] = []; const result: any[] = []; fields.forEach((field) => { - if (field.isForeignKey) { + if (field.isForeignKey && !field.primaryKey) { fkFields.push(field); } else { const fkField = fields.find((f) => f.name === field.foreignKey); @@ -394,11 +394,13 @@ function getNormalizedFields(collectionName, { compile, getCollectionFields }) { } }); const foreignKeyFields = uniqBy(fkFields, 'name'); + // NOTE: for all foreignKey fields for (let i = result.length - 1; i >= 0; i--) { const field = result[i]; if (field.type === 'belongsTo') { - const foreignKeyField = foreignKeyFields.find((f) => f.name === field.foreignKey); - if (foreignKeyField) { + const foreignKeyFieldIndex = foreignKeyFields.findIndex((f) => f.name === field.foreignKey); + if (foreignKeyFieldIndex > -1) { + const foreignKeyField = foreignKeyFields[foreignKeyFieldIndex]; result.splice(i, 0, { ...field, ...foreignKeyField, @@ -407,6 +409,7 @@ function getNormalizedFields(collectionName, { compile, getCollectionFields }) { title: foreignKeyField.uiSchema?.title ? compile(foreignKeyField.uiSchema?.title) : foreignKeyField.name, }, }); + foreignKeyFields.splice(foreignKeyFieldIndex, 1); } else { result.splice(i, 0, { ...field, @@ -424,6 +427,7 @@ function getNormalizedFields(collectionName, { compile, getCollectionFields }) { result.splice(i, 1); } } + result.push(...foreignKeyFields); return uniqBy(result, 'name').filter((field) => field.interface && !field.hidden); }