mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 19:27:23 +08:00
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 { SupportedCreationMethods } from '@/app/components/plugins/types'
|
||||||
import type { TriggerSubscriptionBuilder } from '@/app/components/workflow/block-selector/types'
|
import type { TriggerSubscriptionBuilder } from '@/app/components/workflow/block-selector/types'
|
||||||
import { TriggerCredentialTypeEnum } from '@/app/components/workflow/block-selector/types'
|
import { TriggerCredentialTypeEnum } from '@/app/components/workflow/block-selector/types'
|
||||||
|
import type { BuildTriggerSubscriptionPayload } from '@/service/use-triggers'
|
||||||
import {
|
import {
|
||||||
useBuildTriggerSubscription,
|
useBuildTriggerSubscription,
|
||||||
useCreateTriggerSubscriptionBuilder,
|
useCreateTriggerSubscriptionBuilder,
|
||||||
@ -41,6 +42,8 @@ enum ApiKeyStep {
|
|||||||
Configuration = 'configuration',
|
Configuration = 'configuration',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultFormValues = { values: {}, isCheckValidated: false }
|
||||||
|
|
||||||
// Check if URL is a private/local network address
|
// Check if URL is a private/local network address
|
||||||
const isPrivateOrLocalAddress = (url: string): boolean => {
|
const isPrivateOrLocalAddress = (url: string): boolean => {
|
||||||
try {
|
try {
|
||||||
@ -202,7 +205,7 @@ export const CommonCreateModal = ({ onClose, createType, builder }: Props) => {
|
|||||||
if (!subscriptionBuilder || !detail?.provider)
|
if (!subscriptionBuilder || !detail?.provider)
|
||||||
return
|
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)
|
debouncedUpdate(detail.provider, subscriptionBuilder.id, formValues.values)
|
||||||
}, [subscriptionBuilder, detail?.provider, debouncedUpdate])
|
}, [subscriptionBuilder, detail?.provider, debouncedUpdate])
|
||||||
@ -214,7 +217,7 @@ export const CommonCreateModal = ({ onClose, createType, builder }: Props) => {
|
|||||||
}, [debouncedUpdate])
|
}, [debouncedUpdate])
|
||||||
|
|
||||||
const handleVerify = () => {
|
const handleVerify = () => {
|
||||||
const apiKeyCredentialsFormValues = apiKeyCredentialsFormRef.current?.getFormValues({}) || { values: {}, isCheckValidated: false }
|
const apiKeyCredentialsFormValues = apiKeyCredentialsFormRef.current?.getFormValues({}) || defaultFormValues
|
||||||
const credentials = apiKeyCredentialsFormValues.values
|
const credentials = apiKeyCredentialsFormValues.values
|
||||||
|
|
||||||
if (!Object.keys(credentials).length) {
|
if (!Object.keys(credentials).length) {
|
||||||
@ -256,18 +259,6 @@ export const CommonCreateModal = ({ onClose, createType, builder }: Props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleCreate = () => {
|
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) {
|
if (!subscriptionBuilder) {
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
@ -276,15 +267,32 @@ export const CommonCreateModal = ({ onClose, createType, builder }: Props) => {
|
|||||||
return
|
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(
|
buildSubscription(
|
||||||
{
|
params,
|
||||||
provider: detail?.provider || '',
|
|
||||||
subscriptionBuilderId: subscriptionBuilder.id,
|
|
||||||
name: subscriptionNameValue,
|
|
||||||
parameters: autoCommonParametersFormValues.values,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
|
|||||||
@ -10,13 +10,13 @@ import cn from '@/utils/classnames'
|
|||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
type NodeAuthProps = {
|
type TriggerSubscriptionProps = {
|
||||||
data: Node['data']
|
data: Node['data']
|
||||||
onSubscriptionChange: (v: SimpleSubscription, callback?: () => void) => void
|
onSubscriptionChange: (v: SimpleSubscription, callback?: () => void) => void
|
||||||
children: React.ReactNode
|
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
|
// @ts-expect-error TODO: fix this
|
||||||
const { currentProvider } = useConfig(data.id as string, data)
|
const { currentProvider } = useConfig(data.id as string, data)
|
||||||
const { setDetail } = usePluginStore()
|
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 = () => {
|
export const useBuildTriggerSubscription = () => {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: [NAME_SPACE, 'build-subscription'],
|
mutationKey: [NAME_SPACE, 'build-subscription'],
|
||||||
mutationFn: (payload: {
|
mutationFn: (payload: BuildTriggerSubscriptionPayload) => {
|
||||||
provider: string
|
|
||||||
subscriptionBuilderId: string
|
|
||||||
[key: string]: any
|
|
||||||
}) => {
|
|
||||||
const { provider, subscriptionBuilderId, ...body } = payload
|
const { provider, subscriptionBuilderId, ...body } = payload
|
||||||
return post(
|
return post(
|
||||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/build/${subscriptionBuilderId}`,
|
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/build/${subscriptionBuilderId}`,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user