feat(trigger): add event_parameters to PluginTriggerNode configuration

This commit is contained in:
zhsama 2025-10-15 18:14:10 +08:00
parent 112b5f63dd
commit c03b790888
2 changed files with 30 additions and 5 deletions

View File

@ -218,6 +218,7 @@ const nodeDefault: NodeDefault<PluginTriggerNodeType> = {
defaultValue: {
plugin_id: '',
event_name: '',
event_parameters: {},
// event_type: '',
config: {},
},

View File

@ -1,6 +1,7 @@
import { useCallback, useMemo } from 'react'
import produce from 'immer'
import type { PluginTriggerNodeType } from './types'
import type { PluginTriggerVarInputs } from './types'
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import { useNodesReadOnly } from '@/app/components/workflow/hooks'
import {
@ -14,6 +15,7 @@ import {
import type { InputVar } from '@/app/components/workflow/types'
import type { TriggerWithProvider } from '@/app/components/workflow/block-selector/types'
import type { Event } from '@/app/components/tools/types'
import { VarKindType } from '../_base/types'
const useConfig = (id: string, payload: PluginTriggerNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly()
@ -24,7 +26,13 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
payload,
)
const { provider_id, provider_name, event_name: event_name, config } = inputs
const {
provider_id,
provider_name,
event_name: event_name,
config = {},
event_parameters = {},
} = inputs
// Construct provider for authentication check
const authProvider = useMemo(() => {
@ -69,13 +77,19 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
}, [triggerSpecificParameterSchema])
const triggerParameterValue = useMemo(() => {
if (!triggerParameterSchema.length) return {}
return addDefaultValue(config || {}, triggerParameterSchema)
}, [triggerParameterSchema, config])
if (!triggerParameterSchema.length)
return {}
const hasNewParameters = event_parameters && Object.keys(event_parameters).length > 0
const baseValue = hasNewParameters ? event_parameters : (config || {})
return addDefaultValue(baseValue, triggerParameterSchema)
}, [triggerParameterSchema, event_parameters, config])
const setTriggerParameterValue = useCallback(
(value: Record<string, any>) => {
const newInputs = produce(inputs, (draft) => {
draft.event_parameters = value
draft.config = value
})
doSetInputs(newInputs)
@ -86,8 +100,18 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
const setInputVar = useCallback(
(variable: InputVar, varDetail: InputVar) => {
const newInputs = produce(inputs, (draft) => {
const nextEventParameters = {
...(draft.event_parameters || {}),
} as PluginTriggerVarInputs
nextEventParameters[variable.variable] = {
type: VarKindType.variable,
value: varDetail.variable,
}
draft.event_parameters = nextEventParameters
draft.config = {
...draft.config,
...nextEventParameters,
[variable.variable]: varDetail.variable,
}
})