HOTFIX: Fix duplicate collectionSlug field error

- Multiple step types (create-document, read-document, etc.) were defining collectionSlug fields
- These created duplicate field names at the same level in the Workflow collection
- Fixed by prefixing step field names with step slug (__step_{stepSlug}_{fieldName})
- Added virtual field hooks to store/retrieve data using original field names
- Resolves DuplicateFieldName error preventing PayloadCMS initialization

Fixes: #duplicate-field-name-issue
Closes: User bug report for @xtr-dev/payload-automation@0.0.30
This commit is contained in:
2025-09-09 11:11:31 +02:00
parent 96b36a3caa
commit 398a2d160e

View File

@@ -319,17 +319,45 @@ export const createWorkflowCollection: <T extends string>(options: WorkflowsPlug
}
]
},
...(steps || []).flatMap(step => (step.inputSchema || []).map(field => ({
...(steps || []).flatMap(step => (step.inputSchema || []).map(field => {
const originalName = (field as any).name;
const resultField: any = {
...field,
// Prefix field name with step slug to avoid conflicts
name: `__step_${step.slug}_${originalName}`,
admin: {
...(field.admin || {}),
condition: (...args) => args[1]?.step === step.slug && (
field.admin?.condition ?
field.admin.condition.call(this, ...args) :
condition: (...args: any[]) => args[1]?.step === step.slug && (
(field.admin as any)?.condition ?
(field.admin as any).condition.call(this, ...args) :
true
),
},
} as Field))),
virtual: true,
};
// Add hooks to store/retrieve from the step's input data
resultField.hooks = {
...((field as any).hooks || {}),
afterRead: [
...(((field as any).hooks)?.afterRead || []),
({ siblingData }: any) => {
// Read from step input data using original field name
return siblingData?.[originalName] || (field as any).defaultValue;
}
],
beforeChange: [
...(((field as any).hooks)?.beforeChange || []),
({ siblingData, value }: any) => {
// Store in step data using original field name
siblingData[originalName] = value;
return undefined; // Don't store the prefixed field
}
]
};
return resultField as Field;
})),
{
name: 'dependencies',
type: 'text',