fix(plugin-workflow): fix missed fields in variable (#5187)

This commit is contained in:
Junyi 2024-09-04 10:35:18 +08:00 committed by GitHub
parent b8acdc1477
commit 5cb4fb5096
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}