Refactor: Move trigger field configs to separate modules

- Create dedicated triggers directory for trigger field configurations
- Extract collection, webhook, global, and cron trigger fields into separate modules
- Improve code organization and maintainability
- Update Workflow.ts to use the new modular trigger imports
This commit is contained in:
2025-09-10 09:29:33 +02:00
parent 25d42b4653
commit 449b80e162
6 changed files with 256 additions and 218 deletions

View File

@@ -0,0 +1,56 @@
import type { Field } from 'payload'
export function getGlobalTriggerFields(): Field[] {
return [
{
name: '__builtin_global',
type: 'select',
admin: {
condition: (_, siblingData) => siblingData?.type === 'global-trigger',
description: 'Global that triggers the workflow',
},
hooks: {
afterRead: [
({ siblingData }) => {
return siblingData?.parameters?.global || undefined
}
],
beforeChange: [
({ siblingData, value }) => {
if (!siblingData.parameters) {siblingData.parameters = {}}
siblingData.parameters.global = value
return undefined // Virtual field, don't store directly
}
]
},
options: [], // Will be populated dynamically based on available globals
virtual: true,
},
{
name: '__builtin_globalOperation',
type: 'select',
admin: {
condition: (_, siblingData) => siblingData?.type === 'global-trigger',
description: 'Global operation that triggers the workflow',
},
hooks: {
afterRead: [
({ siblingData }) => {
return siblingData?.parameters?.globalOperation || undefined
}
],
beforeChange: [
({ siblingData, value }) => {
if (!siblingData.parameters) {siblingData.parameters = {}}
siblingData.parameters.globalOperation = value
return undefined // Virtual field, don't store directly
}
]
},
options: [
'update'
],
virtual: true,
}
]
}