mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-10 17:03:22 +00:00
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:
56
src/triggers/global-trigger.ts
Normal file
56
src/triggers/global-trigger.ts
Normal 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,
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user