Implement triggerField helper across all trigger modules

- Standardize virtual field creation using triggerField helper
- Simplify field definitions by removing repetitive virtual field boilerplate
- Use consistent naming pattern: '__trigger_' + fieldName instead of '__builtin_'
- Preserve existing field conditions while adding parameter storage logic
- Update all trigger field modules to use Field type consistently
This commit is contained in:
2025-09-10 13:35:48 +02:00
parent 8f0ee4bcef
commit 9a3b94ef60
6 changed files with 91 additions and 139 deletions

View File

@@ -1,56 +1,28 @@
import type { Field } from 'payload'
import type {Field} from 'payload'
import {triggerField} from "./helpers.js"
export function getGlobalTriggerFields(): Field[] {
return [
{
name: '__builtin_global',
triggerField({
name: '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',
}),
triggerField({
name: '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,
}
})
]
}