mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-10 00:43:23 +00:00
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:
@@ -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,
|
...field,
|
||||||
|
// Prefix field name with step slug to avoid conflicts
|
||||||
|
name: `__step_${step.slug}_${originalName}`,
|
||||||
admin: {
|
admin: {
|
||||||
...(field.admin || {}),
|
...(field.admin || {}),
|
||||||
condition: (...args) => args[1]?.step === step.slug && (
|
condition: (...args: any[]) => args[1]?.step === step.slug && (
|
||||||
field.admin?.condition ?
|
(field.admin as any)?.condition ?
|
||||||
field.admin.condition.call(this, ...args) :
|
(field.admin as any).condition.call(this, ...args) :
|
||||||
true
|
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',
|
name: 'dependencies',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
|||||||
Reference in New Issue
Block a user