From a595e2df0649b493be598bfdb57bdca5a9c5575b Mon Sep 17 00:00:00 2001 From: yessenia Date: Wed, 15 Oct 2025 18:25:08 +0800 Subject: [PATCH] fix(trigger): skip validation when updating properties --- .../subscription-list/create/common-modal.tsx | 50 +++++++++++-------- .../workflow-panel/trigger-subscription.tsx | 4 +- web/service/use-triggers.ts | 13 +++-- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx index 7d749fd8bf..b8db23e22c 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/common-modal.tsx @@ -9,6 +9,7 @@ import Toast from '@/app/components/base/toast' import { SupportedCreationMethods } from '@/app/components/plugins/types' import type { TriggerSubscriptionBuilder } from '@/app/components/workflow/block-selector/types' import { TriggerCredentialTypeEnum } from '@/app/components/workflow/block-selector/types' +import type { BuildTriggerSubscriptionPayload } from '@/service/use-triggers' import { useBuildTriggerSubscription, useCreateTriggerSubscriptionBuilder, @@ -41,6 +42,8 @@ enum ApiKeyStep { Configuration = 'configuration', } +const defaultFormValues = { values: {}, isCheckValidated: false } + // Check if URL is a private/local network address const isPrivateOrLocalAddress = (url: string): boolean => { try { @@ -202,7 +205,7 @@ export const CommonCreateModal = ({ onClose, createType, builder }: Props) => { if (!subscriptionBuilder || !detail?.provider) return - const formValues = manualPropertiesFormRef.current?.getFormValues({}) || { values: {}, isCheckValidated: false } + const formValues = manualPropertiesFormRef.current?.getFormValues({ needCheckValidatedValues: false }) || { values: {}, isCheckValidated: true } debouncedUpdate(detail.provider, subscriptionBuilder.id, formValues.values) }, [subscriptionBuilder, detail?.provider, debouncedUpdate]) @@ -214,7 +217,7 @@ export const CommonCreateModal = ({ onClose, createType, builder }: Props) => { }, [debouncedUpdate]) const handleVerify = () => { - const apiKeyCredentialsFormValues = apiKeyCredentialsFormRef.current?.getFormValues({}) || { values: {}, isCheckValidated: false } + const apiKeyCredentialsFormValues = apiKeyCredentialsFormRef.current?.getFormValues({}) || defaultFormValues const credentials = apiKeyCredentialsFormValues.values if (!Object.keys(credentials).length) { @@ -256,18 +259,6 @@ export const CommonCreateModal = ({ onClose, createType, builder }: Props) => { } const handleCreate = () => { - const autoCommonParametersFormValues = autoCommonParametersFormRef.current?.getFormValues({}) || { values: {}, isCheckValidated: false } - const subscriptionFormValues = subscriptionFormRef.current?.getFormValues({}) || { values: {}, isCheckValidated: false } - // console.log('parameterForm', parameterForm) - - if (!subscriptionFormValues?.isCheckValidated || (createType !== SupportedCreationMethods.MANUAL && !autoCommonParametersFormValues?.isCheckValidated)) { - // Toast.notify({ - // type: 'error', - // message: 'Please fill in all required fields', - // }) - return - } - if (!subscriptionBuilder) { Toast.notify({ type: 'error', @@ -276,15 +267,32 @@ export const CommonCreateModal = ({ onClose, createType, builder }: Props) => { return } - const subscriptionNameValue = subscriptionFormValues?.values.subscription_name as string + const subscriptionFormValues = subscriptionFormRef.current?.getFormValues({}) + if (!subscriptionFormValues?.isCheckValidated) + return + + const subscriptionNameValue = subscriptionFormValues?.values?.subscription_name as string + + const params: BuildTriggerSubscriptionPayload = { + provider: detail?.provider || '', + subscriptionBuilderId: subscriptionBuilder.id, + name: subscriptionNameValue, + } + + if (createType !== SupportedCreationMethods.MANUAL) { + const autoCommonParametersFormValues = autoCommonParametersFormRef.current?.getFormValues({}) || defaultFormValues + if (!autoCommonParametersFormValues?.isCheckValidated) + return + params.parameters = autoCommonParametersFormValues.values + } + else { + const manualFormValues = manualPropertiesFormRef.current?.getFormValues({}) || defaultFormValues + if (!manualFormValues?.isCheckValidated) + return + } buildSubscription( - { - provider: detail?.provider || '', - subscriptionBuilderId: subscriptionBuilder.id, - name: subscriptionNameValue, - parameters: autoCommonParametersFormValues.values, - }, + params, { onSuccess: () => { Toast.notify({ diff --git a/web/app/components/workflow/nodes/_base/components/workflow-panel/trigger-subscription.tsx b/web/app/components/workflow/nodes/_base/components/workflow-panel/trigger-subscription.tsx index 7b8800d787..90b7aca0a7 100644 --- a/web/app/components/workflow/nodes/_base/components/workflow-panel/trigger-subscription.tsx +++ b/web/app/components/workflow/nodes/_base/components/workflow-panel/trigger-subscription.tsx @@ -10,13 +10,13 @@ import cn from '@/utils/classnames' import type { FC } from 'react' import { useEffect } from 'react' -type NodeAuthProps = { +type TriggerSubscriptionProps = { data: Node['data'] onSubscriptionChange: (v: SimpleSubscription, callback?: () => void) => void children: React.ReactNode } -export const TriggerSubscription: FC = ({ data, onSubscriptionChange, children }) => { +export const TriggerSubscription: FC = ({ data, onSubscriptionChange, children }) => { // @ts-expect-error TODO: fix this const { currentProvider } = useConfig(data.id as string, data) const { setDetail } = usePluginStore() diff --git a/web/service/use-triggers.ts b/web/service/use-triggers.ts index 09de09eb91..651280442d 100644 --- a/web/service/use-triggers.ts +++ b/web/service/use-triggers.ts @@ -173,14 +173,17 @@ export const useVerifyTriggerSubscriptionBuilder = () => { }) } +export type BuildTriggerSubscriptionPayload = { + provider: string + subscriptionBuilderId: string + name: string + parameters?: Record +} + export const useBuildTriggerSubscription = () => { return useMutation({ mutationKey: [NAME_SPACE, 'build-subscription'], - mutationFn: (payload: { - provider: string - subscriptionBuilderId: string - [key: string]: any - }) => { + mutationFn: (payload: BuildTriggerSubscriptionPayload) => { const { provider, subscriptionBuilderId, ...body } = payload return post( `/workspaces/current/trigger-provider/${provider}/subscriptions/builder/build/${subscriptionBuilderId}`,