mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-10 08:53:23 +00:00
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:
@@ -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,
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user