mirror of https://github.com/langgenius/dify.git
fix(trigger): skip validation when updating properties
This commit is contained in:
parent
729e0e9b1e
commit
a595e2df06
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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<NodeAuthProps> = ({ data, onSubscriptionChange, children }) => {
|
||||
export const TriggerSubscription: FC<TriggerSubscriptionProps> = ({ data, onSubscriptionChange, children }) => {
|
||||
// @ts-expect-error TODO: fix this
|
||||
const { currentProvider } = useConfig(data.id as string, data)
|
||||
const { setDetail } = usePluginStore()
|
||||
|
|
|
|||
|
|
@ -173,14 +173,17 @@ export const useVerifyTriggerSubscriptionBuilder = () => {
|
|||
})
|
||||
}
|
||||
|
||||
export type BuildTriggerSubscriptionPayload = {
|
||||
provider: string
|
||||
subscriptionBuilderId: string
|
||||
name: string
|
||||
parameters?: Record<string, any>
|
||||
}
|
||||
|
||||
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}`,
|
||||
|
|
|
|||
Loading…
Reference in New Issue